As I discussed in my earlier blog post Analytics sets a number of cookies to track visitor interaction with your website. In this post I will show you how you can extract (and insert) useful data from one particular cookie: __utmz. Although I will just be focussing on this cookie, this principal is still the same for the other cookies.

As you may remember __utmz was the cookie that stores data about how a visitor arrived at your site. Here how you cna find your own example of the cookie data:

I generally use Firefox to check the cookie data as it makes it a whole lot easier than IE. To get to the cookie data just select: Tools>Options>Privacy>Show Cookies, then enter the name of your site e.g willmartinez.com.

Firefox cookie data

The important data to focus on from the image above is:

utmccn=(organic)|utmcsr=google|utmctr=motorcaravan+insurance|utmcmd=organic

As you can see all the variables I mentioned earlier are visible in a string of data, each variable separated by the pipe character |.

So what does this data tell us?

It tells us that I arrived at this site when I searched for ‘Motorcaravan Insurance’ on Google and then clicked on an organic search listing. Had I have arrived from a Yahoo organic search listing the data would have remained much the same and providing I searched using the same keywords only the utmcsr variable would have changed from Google to Yahoo.

What If I had arrived through a paid search ad?

Well, I will tell you but I would suggest trying this out for yourself and getting used to seeing the data first hand. Here’s an example:

utmcsr=Google|utmccn=(not%20set)|utmcmd=cpc|utmctr=motorcaravan+insurance

This shows I searched for Motorcaravan Insurance on Google then clicked the paid search ad and landed on the site. cpc refers to paid search or cost-per-click advertising. The utmccn variable is not set because this is not set automatically, you will have to append some variables to the end of your URL to set this, which I will now show you how to do.

Inserting data into the cookie variables

Inserting data is very simple. You just need to add the variable names and the values or data you want added to them at the end of the url.

e.g.

www.willmartinez.com/index.php?utmcsr=Affilliate&utmccn=aff_campaign&utmcmd=thewebsite.com&utmctr=none

To add variable data to be passed to a page you simple add the data after a ‘?’ in the sites URL. Then you write the variable_name=value any additional variable data is added by inserting an ‘&’ between them.

Accessing cookie data using Javascript

The two functions below work together to extract the data from your Analytics tracking cookies:


function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function getVariable(l,n,s) {
 if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
 var i,i2,i3,c="-";
 i=l.indexOf(n);
 i3=n.indexOf("=")+1;
 if (i > -1) {
  i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
  c=l.substring((i+i3),i2);
 }
 return c;
} 

buy Pest Hail the black metal wolves of belial LP mp3