SOLVED

Capturing Full URL from Referring Web Page to Form Submit

Go to solution
Highlighted

Capturing Full URL from Referring Web Page to Form Submit

Hello all. I am having a similar issue that others have had regarding capturing referral URL on form submit. We've read a bunch of other threads about this topic and we can't figure out exactly how to apply those instructions to our special circumstance. 

 

We have a custom Wordpress site and we are moving from ContactForm7 to Marketo Forms. Current ContactForm7 captures full referrer URL and includes it in the email alert to sales, which is super helpful information.

 

The behavior I want:

1) User clicks on a product page, then clicks the "request info" button.

2) We want to pass that product page URL to the WordPress landing page with the new Marketo form embedded on it.

3) User submits the form and the URL from the product page gets passed to our unique custom field (Form URL) we created to capture the URL. 

4) Email alert uses the custom field (Form URL). 

 

Questions: 

1) What type of field should the URL field be? String or URL? 

2) Other posts said to create an HTML block and put in the java script. Where does the HTML block go? On the Marketo form (rich text) or the WordPress product page, or the WordPress form landing page? 

3) What is the javascript I would use? 

 

Thanks in advance!! 

Brenda

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Level 10 - Community Moderator

Re: Capturing Full URL from Referring Web Page to Form Submit

OK, that code has exactly the same effect as the code posted above. In fact it's more fragile because the hidden field needs to be added to the form in Form Editor if you use setValues() or vals(). Using addHiddenFields() doesn't require the field to be on the form to begin with.

 

whenReady() adds the value to all forms, while the final argument to loadForm() adds the value to only that form.

 

Other than that, these 2 pieces of code are are not substantively different. They both set the value of a hidden field when a form is ready:

 

#1

MktoForms2.whenReady(function(mktoForm){
  mktoForm.addHiddenFields({
    lastFormReferrerURL : document.referrer
  });
});

 

#2

MktoForms2.loadForm("//app-ab37.marketo.com", "525-EAQ-286", 1056, function (form) {
  form.vals({
    "lastFormReferralURL" : document.referrer
  });
});

 

View solution in original post

7 REPLIES 7
Highlighted
Level 10 - Community Moderator

Re: Capturing Full URL from Referring Web Page to Form Submit


1) What type of field should the URL field be? String or URL? 

String.

 


2) Other posts said to create an HTML block and put in the java script. Where does the HTML block go? On the Marketo form (rich text) or the WordPress product page, or the WordPress form landing page? 


I wouldn't recommend putting it in the form, because Marketo recently introduced a bug that makes that much more difficult. it should be a separate <script> on the WP page hosting the form, placed anywhere after the form embed code.

 


3) What is the javascript I would use? 


MktoForms2.whenReady(function(mktoForm){
  mktoForm.addHiddenFields({
    lastFormReferrerURL : document.referrer
  });
});

 

replacing lastFormReferrerURL with the SOAP API name of your new String field. 

Highlighted

Re: Capturing Full URL from Referring Web Page to Form Submit

Ok, I tested the script and it didn't work. I put the script directly under the form script. I put the lastFormReferrerURL hidden field in the form but didn't specify a Referrer Parameter or a URL Parameter. Any advice? 

Highlighted
Level 10 - Community Moderator

Re: Capturing Full URL from Referring Web Page to Form Submit

The field doesn't even need to be on the form for this (addHiddenFields takes care of it).

 

What page is this on?

Highlighted

Re: Capturing Full URL from Referring Web Page to Form Submit

Had to get our external developer to help on this as I'm not good with JS. Here is the script that they ended up using from the Marketo doc: 

 

/*MktoForms2.whenReady(function(mktoForm){
mktoForm.addHiddenFields({
lastFormReferrerURL : document.referrer
});
});*/

This worked. Thanks for your help!! 

Brenda

Highlighted
Level 10 - Community Moderator

Re: Capturing Full URL from Referring Web Page to Form Submit

That code isn't doing anything, as it's completely commented out.

Highlighted

Re: Capturing Full URL from Referring Web Page to Form Submit

Opps, here is the code (I must have copied the wrong one). 

 

<script>
MktoForms2.loadForm("//app-ab37.marketo.com", "525-EAQ-286", 1056, function (form) {
  form.vals({
    "lastFormReferralURL":document.referrer
  });
});
</script>
Highlighted
Level 10 - Community Moderator

Re: Capturing Full URL from Referring Web Page to Form Submit

OK, that code has exactly the same effect as the code posted above. In fact it's more fragile because the hidden field needs to be added to the form in Form Editor if you use setValues() or vals(). Using addHiddenFields() doesn't require the field to be on the form to begin with.

 

whenReady() adds the value to all forms, while the final argument to loadForm() adds the value to only that form.

 

Other than that, these 2 pieces of code are are not substantively different. They both set the value of a hidden field when a form is ready:

 

#1

MktoForms2.whenReady(function(mktoForm){
  mktoForm.addHiddenFields({
    lastFormReferrerURL : document.referrer
  });
});

 

#2

MktoForms2.loadForm("//app-ab37.marketo.com", "525-EAQ-286", 1056, function (form) {
  form.vals({
    "lastFormReferralURL" : document.referrer
  });
});

 

View solution in original post