Associating URL Slug with Product

Liz_Smith
Level 2

Associating URL Slug with Product

I have forms setup on each product page on my website. When someone fills out the form, I receive an email. I want the email to include what product they were looking at. How do I translate the product ID in the URL slug to the associated product ID in my CRM system?

For example, if I fill out a form on the page www.test.com/123, and 123 is known as product 1 in my CRM, I want to receive an email trigger from Marketo that says "New Form filled out for "Product 1."

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Associating URL Slug with Product

What you're calling the URL slug is the pathname (or part of the pathname), a standard value available in the browser.

You'd have to use JavaScript to parse that value out of the URL, then write it to a hidden field on the form using addHiddenFields.

A greatly simplified example:

MktoForms2.whenReady(function(form){

form.addHiddenFields({

LastProductPage : document.location.pathname.replace(/^\//,"")

});

});

Also pretty sure this has been asked (and answered by me!) before, if you search.

Liz_Smith
Level 2

Re: Associating URL Slug with Product

Hi Stanford,

Thank you for the quick response. The issue is not getting that value, but rather translating it from a code to the product name in our CRM system. Is this something we can do without getting into the website code? We only have access to the forms form the Marketo side.

Thank you!

SanfordWhiteman
Level 10 - Community Moderator

Re: Associating URL Slug with Product

Actually you do need JS like the above to get the code, or you'll have nothing to look up on the server side!

The translation from the code to the friendlier name can be done in one of 2 ways:

  1. Use a webhook to call a lookup service (API) offered by your website, if one exists.
  2. Maintain a list of the code-to-name mappings in a Velocity token. Look up in that mapping table to output only the friendly name in your alert.

Obviously if you have no way of looking up the product names, whether via API or a periodic export/paste, there wouldn't be any way to accomplish this... Marketo can't read from the private db used on your site.