How to Use Cookies to Capture URL Parameters

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.

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

utm_source

utm_medium

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.

Questions?

Related Posts

Looking for some creative ways to spice up your Pardot forms? In this post, I will show you how to implement the popular floating label technique in three easy steps. I will also show you how to turn your long drop down menus into user-friendly, searchable dropdowns.

Learn how to build a net promoter score (NPS) survey directly in Pardot. I will show you how to create an NPS survey that asks the recipient to give you a score from 1 – 10 using an in-email rating that directs them to a Pardot landing page to collect more information.

You might already be tracking MQLs in Salesforce or in Pardot, but are you tracking all the information you need for enhanced reporting? I’ll walk you through the 3 steps you need to take for complete MQL tracking that can be used within reports and dashboard in Salesforce.

N

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