Unbounce Answers/Next Steps/Tips & Tricks

How to capture referrer data in your lead-gen form

Carter Gilchrist
posted this on April 11, 2011 11:21 am

A quick and easy way to capture basic referral information (the URL that referred the visitor) is to use a bit of javascript and look for the 'document.referrer' value. There's no 100% guarantee with this, but it's a good way to capture most referrers and see where they're coming from and what they may have searched for to get there. Here's how to set this up:

  1. Add a new "hidden form field" in your form called "referrer" (the name doesn't really matter as long as it matches the next part)
  2. Add the following script into your "Javascripts" section in the bottom left of the editor and set the Placement to "Head":

    <script type="text/javascript">
    jQuery(function(){
      jQuery('input#referrer').val(decodeURI(document.referrer));
    }); 
    </script>

That's it! You should start to see "referrer" showing up in your leads data and your email notifications.

How do I interpret the referrer data?

If I search google for "landing pages" and hit the Unbounce.com link that shows up, my referrer information looks like this (I've broken it up into multiple lines):

http://www.google.ca/url?sa=t&source=web&cd=2&
ved=0CEEQFjAB&url=http%3A%2F%2Funbounce.com
%2F&rct=j&q=landing%20pages&ei=VEKjTdLrN8ffiALDuKyGAw
&usg=AFQjCNEdp5atllJolLmui3JnJ-LeqkqI7g
&sig2=WWeqREq70WX5qNiwMh3oIw

You'll notice the data is a bit unreadable at first (it's encoded, the script you're copying above will help decode it) but you can still see that the domain is google.ca and that the search query (represented by 'q' in this case) was landing pages (the %20 is just a space). Hope this helps you learn more about your leads!

 

Comments

User photo
Andres Martin

This shall work with natural traffic (not being HTTPS blocked) but will it work with paid traffic (AdWords)? In case it won't, any idea on how to do it? 

Thanks, 

June 25, 2012 08:18 am
User photo
Gil S.

Is there anyway to modify the script to support/read links created by google's url builder?
http://support.google.com/analytics/bin/answer.py?hl=en-GB&answ...

Thanks.

October 03, 2012 02:02 pm
User photo
Brian Meert

I agree with Gil. It would be extremely valuable if there was a way to pass through the Google URL variables to the form.

Campaign Source, Campaign Medium, Campaign Term, Campaign Content and Campaign Name. Is it also possible to just display the Keyword as text and not as the entire URL? 

November 14, 2012 07:48 am
User photo
Ryan Engley
Unbounce

Hey Gil, Brian - the above script doesn't actually need to be modified to capture Google's form data.  In fact, any URL parameter will automatically populate the field on your Unbounce form with the same name.

Let's say for example, you've set up tracking through Google's URL builder and the URL looks like this:

http://listings.gastown-realty.com/?utm_source=google&utm_mediu...

If you add hidden fields to your Unbounce form for:

  • utm_source
  • utm_medium and
  • utm_campaign
those values will be populated nd saved with your lead data when your visitor submits the form.

Our article Can I Pre-populate a Form with URL Parameters covers this in more detail.
November 15, 2012 03:44 pm