Original External Referrer URL Javascript | Community
Skip to main content
George_Hoffman
Level 3
November 28, 2016
Solved

Original External Referrer URL Javascript

  • November 28, 2016
  • 1 reply
  • 6060 views

I'm trying to add Javascript that pulls Original External Referrer Url into a hidden form field. This is the Javascript that I will be using (from this discussion):

  1. <script> 
  2. MktoForms2.whenReady(function(form){ 
  3.   form.setValues({ 
  4.     OriginalExternalReferrer : document.referrer 
  5.   }); 
  6. }); 
  7. </script> 

Do I need to place this script on the landing page or in the form somewhere? If on the form, where do I place this?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Ok, I tested and it looks like it is working (see below),

However, it is not populating the field in Marketo,

The field is the following,

  

Original_External_Referrer__cOriginal External Referrer

Do I need to change something in the script to push the field into Marketo?


Yes, if that's the real field name, then the field name in addHiddenFields() needs to be Original_External_Referrer__c. 

1 reply

SanfordWhiteman
Level 10
November 28, 2016

form.setValues() is for when the field has been added to the form in Form Editor (there's no reason for it to be on the form if it will only be hidden and populated via JS).

So you want form.addHiddenFields(), not form.setValues().

The <script> with special form behaviors code can be placed in a Rich Text area on the form, but you may find that difficult to manage. You will probably find it easier to put it on the LP directly. Make sure it comes after the <script> that loads forms2.min.js.

George_Hoffman
Level 3
November 28, 2016

Hey Sanford,

Thanks for the reply! I am adding the script to the LP template in the script in the header. However, It is not filling the hidden field upon form fill out. This is what the script looks like:

<script src="info.healthyvending.com/rs/018-NMA-932/images/snacknation_jquery_min.js">

MktoForms2.whenReady(function(form){

form.addHiddenFields({

OriginalExternalReferrer : document.referrer

   });

});

  </script>

Any suggestions? Am I placing the code in the wrong place?

SanfordWhiteman
Level 10
November 28, 2016

Any suggestions? Am I placing the code in the wrong place?

Hmm, yes...

You can't put code inside a <script> block that has a remote src= (well, you can put text in there, but that is for obscure use cases that are irrelevant here).

You want a separate <script></script> block. No src. You will likely find this easiest to place right before the closing </body> tag (not in the <head>.