SOLVED

Re: Original External Referrer URL Javascript

Go to solution
George_Hoffman
Level 3

Original External Referrer URL Javascript

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?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Original External Referrer URL Javascript

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

View solution in original post

11 REPLIES 11
SanfordWhiteman
Level 10 - Community Moderator

Re: Original External Referrer URL Javascript

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

Re: Original External Referrer URL Javascript

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="http://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 - Community Moderator

Re: Original External Referrer URL Javascript

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>.

George_Hoffman
Level 3

Re: Original External Referrer URL Javascript

Placed it in the code with still no luck. This is what I added to the preexisting script right before the </body> tag

<!--scripts starts here-->

<script>

MktoForms2.whenReady(function(form){

form.setValues({

OriginalExternalReferrer : document.referrer

   });

});

  </script>

<script type="text/javascript" src="http://info.healthyvending.com/rs/018-NMA-932/images/snacknation_general.js"></script>

<!--scripts ends here-->

Any suggestions regarding the above?

As an alternative, where would I add the code in an individual form?

SanfordWhiteman
Level 10 - Community Moderator

Re: Original External Referrer URL Javascript

Please post a link to the URL where you've deployed this.

George_Hoffman
Level 3

Re: Original External Referrer URL Javascript

SanfordWhiteman
Level 10 - Community Moderator

Re: Original External Referrer URL Javascript

But it is working.  How are you testing?

2016-11-28 19_53_42-Healthy Snack Delivery Service for Offices _ SnackNation - Slimjet.png

George_Hoffman
Level 3

Re: Original External Referrer URL Javascript

Click the first link on this page .  The link is "The Millennial generation".

After clicking that link and being driven to the landing page, the "Original External URL" hidden field should be filled with the referring URL, which is From Healthy Food Subscription to Snack Products: 10 Brands that Give Back | SnackNation, correct?

George_Hoffman
Level 3

Re: Original External Referrer URL Javascript

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

Screen Shot 2016-11-28 at 5.43.42 PM.png

However, it is not populating the field in Marketo,

Screen Shot 2016-11-28 at 5.45.08 PM.png

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?