Marketo's documentation on this isn't very clear for me so I'm hoping someone can help.
We have one Marketo form that is embedded on multiple pages on our website. The internal stakeholders would like form fills to include the url of the page the person filled out the form on, so they can tell which pages are getting more form fills.
The pages do not have querystrings in their url's so I'm not sure parameters will work for this.
Is there a way to get the url into a hidden form field?
Otherwise I guess my other option would be to create smartlists and use the referrer constraint to split out each page the form is on.
Solved! Go to Solution.
1. Add the custom String field LastFormURL to your instance.
2. Use this simple JavaScript to pass that hidden field for every form fill:
MktoForms2.whenReady(function (form) {
form.addHiddenFields({ LastFormURL : document.location.href });
});
1. Add the custom String field LastFormURL to your instance.
2. Use this simple JavaScript to pass that hidden field for every form fill:
MktoForms2.whenReady(function (form) {
form.addHiddenFields({ LastFormURL : document.location.href });
});
Thanks, Sanford. Where would I put that script? On the page on our website the form is on or can I put it in a rich text area on the form?
You can add it directly after the embed code or if absolutely necessary, you can add it within a Rich Text but only if you do it like this: https://nation.marketo.com/t5/Product-Blogs/HOWTO-Add-Forms-2-0-JS-behaviors-inside-a-Rich-Text-Area...
So we tried adding this, but it's not working
what are we doing wrong?
Nothing wrong with the code, what's not working exactly?
When I do a test form fill and then create a smartlist to see the lastformurl field nothing is populated
Nevermind, our developers figured it out. It was in the script as LastFormURL, but the l should have been lowercase. They changed it to lastFormURL and now it's working. Thank you again!
To expand on this, quick word of advise on this solution.
Text strings are capped at 255 char.
the value of document.location.href
will contain URL parameters which could put you over the character limit.
The submission will be rejected if that happens.
This will help remove the URL parameters
document.location.href.split('?')[0]
MktoForms2.whenReady(function (form) {
form.addHiddenFields({ LastFormURL : document.location.href.split('?')[0] });
});