SOLVED

Capturing the URL itself, not URL parameters

Go to solution
Anonymous
Not applicable

Capturing the URL itself, not URL parameters

Is there a way to capture the URL itself in hidden field on a Marketo form? 

We already capture URL parameters, which is great. But I'd like to also be able to just capture the URL itself (the main part of the URL before the question mark). Then we would know which page the user was on when he/she filled out a given form.

The use case is kind of a long story, but it's related to the fact that we use a single Marketo form for all our webinars. Each webinar needs a different Unbounce landing page, and a mobile version of that page too.

I'd like to be able to specify in the form that if [URL where the person filled out the form] contains ABC, then go to thank you page XYZ.

Thanks in advance folks!
Matt 
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Edward_Masson
Level 10

Re: Capturing the URL itself, not URL parameters

A couple of options i know of.

You could be specific to your forms and label them so that certain forms are used for certain marketing activities. So your smart campaigns can be set up to listen to certain forms being filled out and all will be directed to the approprate landing page for follow up. i.e. all webinars submissions are sent to a webinar follow up page, offline events sent to Event follow up page.

The cutom field and JQuery route is another option.

Create a custom field to capture the URL with the help of JQuery, stamp the field with the URL. In the form 2.0, you can listen for that value to push to follow up landing pages on form submission.

View solution in original post

7 REPLIES 7
Edward_Masson
Level 10

Re: Capturing the URL itself, not URL parameters

A couple of options i know of.

You could be specific to your forms and label them so that certain forms are used for certain marketing activities. So your smart campaigns can be set up to listen to certain forms being filled out and all will be directed to the approprate landing page for follow up. i.e. all webinars submissions are sent to a webinar follow up page, offline events sent to Event follow up page.

The cutom field and JQuery route is another option.

Create a custom field to capture the URL with the help of JQuery, stamp the field with the URL. In the form 2.0, you can listen for that value to push to follow up landing pages on form submission.
Anonymous
Not applicable

Re: Capturing the URL itself, not URL parameters

Relevant thread if you go down the Javascript route: http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-javascript
Anonymous
Not applicable

Re: Capturing the URL itself, not URL parameters

Thanks everyone! With the help of our developer, I did this:
  • Created a field in Marketo (overwritable) called URL of Most Recent Form Fill
  • Added an extra line or two to the Marketo Embed Code on my Unbounce page
  • The purpose of the extra script is to capture "location.pathname" from the page (which is everything after the domain and before the question mark) and pass it to Marketo
  • Then I can use Marketo to divert users to different thank you pages depending on which URL they filled out the form on

 .


The script is this one. The added code beyond Marketo's usual Embed Code is in yellow. Note that 1429 is the form ID (you have to change this every time) and 300-GEQ-584 is specific to our instance of Marketo, so change that too if you're using this. 

<script src="//app-sj05.marketo.com/js/forms2/js/forms2.js"></script> <form id="mktoForm_1429"></form> <script>MktoForms2.loadForm("//app-sj05.marketo.com", "300-GEQ-584", 1429, function() {
  $("#mktoForm_1429 [name='uRLofMostRecentFormFill']").val( location.pathname );
});</script>

Anonymous
Not applicable

Re: Capturing the URL itself, not URL parameters

Hi Matt,

I'm also trying to capture the full URL and am wondering how and where you added the code above? When building landing pages, I am unable to edit the Embed Code. I also cannot edit the Embed Code in Design Studio for the particular form that needs to capture the URL from a hidden field.

SanfordWhiteman
Level 10 - Community Moderator

Re: Capturing the URL itself, not URL parameters

You don't need to edit the embed code. Use the MktoForms2.whenReady event. This works on both Marketo and non-Marketo LPs.

MktoForms2.whenReady(function(form){

  form.addHiddenFields({ last_form_fill_url : document.location.href });

});

Obviously substitute the actual name of the field in your instance for last_form_fill_url.

Note the code in the earlier post has a bug and should not be used. Forms 2.0 provides the setValues and addHiddenFields methods to set field values accurately on the form object (not just inputs in the <FORM> element). You should not set values on the input element directly: it will not work for all field types and form configs.

Danya_Al_Attar
Level 1

Re: Capturing the URL itself, not URL parameters

Hi,

Still not sure where to add this:

"MktoForms2.whenReady(function(form){

  form.addHiddenFields({ last_form_fill_url : document.location.href });

});"

SanfordWhiteman
Level 10 - Community Moderator

Re: Capturing the URL itself, not URL parameters

Also, this exact question was answered on another zombie thread today: Want to populate a field that has the actual URL a web form is filled out on.