How to Use Cookies to Capture URL Parameters

In:

A couple months ago I wrote a tutorial on how to use UTM parameters to capture lead source. The tutorial is an in-depth overview of how to capture URL parameters when a lead visits a landing page directly but if a lead visits a different page then fills out the form, those URL parameters won’t be captured. To fix this issue, you can store cookies in the lead’s browser and configure the form fields to pull from the cookie values instead of the URL parameter.

hidden-fields-in-forms-2

In this example, we will be setting 3 different cookies.

  1. utm_source
  2. utm_medium
  3. utm_campaign

Parse the URL

The URL parameters need to be parsed so the cookie values can be set. This can be done using javascript.

Setting the Cookie Values

In order to set the cookie values, jQuery and the jQuery Cookie Plugin must be on the page.

The syntax for creating a cookie using the jQuery plugin is very simple.

Using the variables defined in the first step, the cookie values can be set.

Testing

To ensure the cookie values are being stored in the browser correctly, open up Chrome -> Developer Tools and click on the Resources tab.

utm-cookies

The cookies utm_source, utm_medium and utm_campaign should be visible in the console.

Setting the Form Field Values

Now that all the UTM parameters are being stored in the lead’s browser, the forms need to be configured to grab the cookie value.

Putting it All Together

The Code on your page should look similar to this.

Questions?

Email me, or send me a tweet @jennamolby.

Related Posts

  • 21/09/2017
    3 Free Pardot Landing Page Templates for Asset Downloads

    Create beautiful, responsive landing pages in Pardot by using one of these 3 free Pardot layout templates. These landing page templates are designed specifically for gated assets such as white papers and eBooks, but they will work well with any landing page that contains a form.

  • 13/04/2017
    How to Use Salesforce Campaigns in Pardot to Track Campaign Influence

    Identifying which campaigns and channels have influenced an opportunity is a key piece of information to see which marketing campaigns are the most effective. In this tutorial, I’ll walk you through how I use Salesforce campaigns in Pardot to track campaign influence.

  • 17/10/2016
    9 Things You Should Know About The Marketo Account Based Marketing Platform

    Earlier this year at Summit, Marketo announced that they would be launching an Account Based Marketing Platform. As of September 2016, Marketo has officially launched their Account Based Marketing Platform as part of their Summer ’16 launch. There’s been a lot of buzz about Marketo ABM and its benefits, so I thought I would break everything down into the top 9 things you should know about the Marketo Account Based Marketing Platform.

5 comment(s)
  • Nick

    10/10/2017 at 12:20 pm
    Reply

    You should place this in github - it's really useful code!

  • N

    14/08/2017 at 2:57 pm
    Reply

    How do you pass the value? Im able to see cookie name but it doesn't submit the value. Great tutorial BTW!!

  • Whitney

    12/05/2017 at 10:28 am
    Reply

    Thank you for this well-written tutorial. It was much easier to follow than the other examples I found. I was easily able to also incorporate the referring url. For your information though: the jQuery Cookie Plugin is no longer supported and the new plugin is at https://github.com/js-cookie. The code has to be updated to Cookies.set instead of $.cookie Also, I was unable to get the following code to work: function getParameterByName(name) { name = name.replace(/[[]/, "\[").replace(/[]]/, "\]"); var regex = new RegExp("[\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/+/g, " ")); } So I replaced it with code I found from a similar tutorial: function getParameterByName(name) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i

  • Jessie

    24/02/2017 at 9:04 am
    Reply

    You are a lifesaver! Thank you!!

  • […] to get value from cookie value, but it doesn’t store the cookie for you. You will need some javascript code embeded on your website to store the […]

Leave A Comment

Your email address will not be published. Required fields are marked *

About Me

I am a results focused marketing automation expert, with a strong background in design and development. With a high level computer science background, I have the unique ability to design, code and understand data, while utilizing this skillset to further enhance my value and ROI in the digital marketing space.
LEARN MORE

Categories
Most Commented
Popular Posts