You are on page 1of 12

Attribution Tracking

This spec explains how to use the Google Analytics cookie to track and attribute users to their referral source (keyword, banner ad, etc)

Contents
Problem / Solution Solution Overview Solution Specs

The Problem
When we drive a new user to somesite.com we cannot track the users action beyond the form submit (sign up) using standard Google Analytics tracking. The prevents us from identifying where the user came from. Ie, the keyword, or ad unit that referred them to somesite.com. We call this attribution tracking.

The Solution
A custom tracking system that utilizes the Google Analytics cookie to pass campaign variables into the somesite.com database. Once we correlate a transaction with a referring ad ID we can attribute the user to a specific ad source (keyword, banner ad, email, etc). Once we have attribution tracking in place, we can measure ROI for our media

campaigns (paid search, email, SEO, social media, etc).

Solution Overview
1 Prospective customer clicks an ad or organic listing 3 Customer completes sign up form at somesite.com 4 Tracker reads Google cookie, extracts specific campaign variables, and passes them through the registration form as hidden fields

On ad click Google writes a cookie to users browser

Registration Data

ExecSight database Form data , including Analytics variables, posted to database

Solution Specs
Write a custom script that extracts the following campaign variables from the Google Analytics cookie and passes it through the lead form as a hidden field: Utmcsr Utmccn Utmcmd utmctr

Where: utmcsr = campaign source Utmccn = campaign name utmcmd = campaign medium utmctr = campaign terms

Step 1 : Read Cookie


To read out a cookie, call this function and pass the name of the cookie. Put the name in a variable. First check if this variable has a value (if the cookie does not exist the variable becomes null, which might upset the rest of your function), then do whatever is necessary.

var x = readCookie('ppkcookie1') if (x) { [do something with x] }


The function receives the argument and starts.

function readCookie(name) {
We're going to search for the name of the cookie, followed by an =. So create this new string and put it in nameEQ:

var nameEQ = name + "=";

Read Cookie Cont


Then split document.cookie on semicolons. ca becomes an array containing all cookies that are set for this domain and path.

var ca = document.cookie.split(';');
Then we go through the array (so through all cookies):

for(var i=0;i < ca.length;i++) {

Set c to the cookie to be checked

while (c.charAt(0)==' ') c = c.substring(1,c.length);

Read Cookie Cont


Now string c begins with the name of the current cookie. If this is the name of the desired cookie

if (c.indexOf(nameEQ) == 0)
We've found what we were looking for. We now only need to return the value of the cookie, which is the part of c that comes after nameEQ. By returning this value we also end the function: mission accomplished.

if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); }


If, after having gone through all cookies, we haven't found the name we're

looking for, the cookie is not present. We return null.

return null; }

Step 2: Extract Variables


Next we need to extract the variables from the Google Analytics cookie var utmz = readCookie('__utmz'); //using a cookie reading function var vals = (function() { var pairs = utmz.split('.').slice(4).join('.').split('|'); var ga = {}; for (var i = 0; i < pairs.length; i++) { var temp = pairs[i].split('='); ga[temp[0]] = temp[1]; } return ga; })(); //vals.utmcmd: medium (organic, referral, direct, etc) //vals.utmcsr: source (google, facebook.com, etc) //vals.utmcct: content (index.html, etc) //vals.utmccn: campaign //vals.utmctr: term (search term)

Step 3 : Pass Variables to Database


Modify the lead form located on the product pages to include 4 hidden fields: Utmcsr Utmccn Utmcmd Utmctr

These fields should be alphanumeric and should not require validation. The above fields are not required. Insert the extracted variables into their respective fields and

submit the form as normal. The hidden fields will ne captured in the registration form
and passed through to the ExecSight database.

Your Contact
Dylan Touhey

CMO / Principal
dylan@onenetmarketing.com 250.483.7411 x 101

You might also like