December 17th 2016

A delicious attribution recipe

Image Deanna Ladret

Adapted By: Charles Neigum, The Betty Crocker of Code + Lead Developer at One Net

First, who should bake these cookies?

This cookie recipe is for companies operating on a *free trial or **freemium***pricing model — where there is a lapse in time between the signup and the paid conversion. For other models (like e-commerce) where the purchase is the immediate call to action, the GA conversion script will work just fine as is.

So, for those of you who have been starving to find out where your paid customers come from, here's everything you need to know! Nothing half-baked.

Prep Time: 15 minutes

Yield: Unlimited!

You're hungry for answers...

When you drive a new user to somesite.com, you cannot track the user's action beyond the 'form submit' (CTA) when using standard Google Analytics tracking.

This prevents you from identifying where the user came from. You don't know which keyword or advertisement referred them to somesite.com. Some might say it's just the way the cookie crumbles.

Not us! There's an answer to this unsavoury dilemma, and that answer is called attribution tracking.

Use a custom tracking system that allows the Google Analytics cookie to pass campaign variables into the somesite.com database and create a specific ID for the referral source.

Once you correlate a transaction with a referral source ID, you can attribute the user to a specific ad source e.g. keyword, banner ad, email, etc.

Once attribution tracking is in place, you can accurately measure ROI for your media campaigns via paid search, email, SEO, social media, etc. (So many cooks in the kitchen!)

You still following? You're one smart cookie.

Write a custom script that extracts the following campaign variables from the Google Analytics cookie and then 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

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 may upset the rest of your function, not to mention your stomach.

Next, insert what you want to happen with the variable.

The function receives the argument and starts.

Search for the name of the cookie, followed by an =. Create this new string and put it in nameEQ:

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

function readCookie(name) {

var nameEQ = name + "=";

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

Go through the array (all cookies):

Set c to the cookie to be checked

var ca = document.cookie.split(';');

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

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

Now, eat a handful of chocolate chips. There's still more work to be done and you need energy.

Now string c begins with the name of the current cookie.

You've found what you are looking for. Now you only need to return the value of the cookie, which is the part of c that comes after nameEQ. By returning this value you also end the function. Oh, the sweet smell of success! Or is that coming from the oven?

If, after having gone through all cookies, you haven't found the name we're looking for, the cookie is not present. You return null. Don't be sad though, we'll still satisfy your sweet tooth soon! Just keep reading...

if (c.indexOf(nameEQ) == 0)

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

return null; }

Next, you need to extract the variables from the Google Analytics cookie. (Go ahead, take out those raisins. It's a cookie. It's not supposed to be healthy.)

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)

Modify your lead form to include 4 hidden fields:

utmcsr

utmccn

utmcmd

utmctr

These fields should be alphanumeric and should not require validation. Insert the extracted variables into their respective fields and submit the form as normal. The hidden fields will be captured in the form and passed through to your database.

Voila. Now you can have your cookies and eat them too!

"I hope you enjoyed your treat...just in time for the holidays!" — Charles

Happy Holidays from the One Net team!

Categories: ALL, Marketing

RELATED POSTS

April 23rd 2018

Why the Customer Journey Matters

By designing and positioning useful content with compelling ad campaigns across the entire customer journey, brands can increase revenue by 15%, decrease acquisition costs by 20% and increase repeat purchases by as much as 50%.

Image Dylan Touhey
January 3rd 2018

Email, work that ROI!

We all use email. Your audience on social media can be a flighty ROI sinkhole, and who knows what’s happening in the shiny, emerging world of VR—but email will always remain a comfortable medium we keep coming back to. And places we consistently come back to, we spend money on.

Image Brianne Dromey
December 7th 2017

One Net Guide: The River of Branded Content

Branded content is a type of creative asset that focuses on building relationships with your audience, rather than driving a ‘hard sell’.

Image Deanna Ladret