Super Cookie – How to guide and source code (a guide for techies)
This is a how to guide (+ source code) for the new Google Analytics Super Cookie developed by ConversionWorks. What’s the Super Cookie?
Wouldn’t it be great if we could track all the website touch-points before a website visitor converts? Well…we can, with a Super Cookie!
What we set out to do and what it does (an abstract)
Tracking where a visitor comes from is not a big deal. It can be done a number of ways, usually involving the referrer part of HTTP headers which can be accessed by any web scripting language, from PHP to JavaScript.
Understanding a list of referral paths however allows us to identify the effectiveness of our marketing budget and how they accessed our site on their way to a conversion.
We have produced a Javascript solution which gives us all the data we want in an easy to read format:
organic (google) (search term) | referral (referral) (referrer) | cpc (google) (search term)
This tells us that the visitor originally came to the site through an organic Google search, then came via a referring site and finally converted after clicking a CPC ad on Google.
Using a standard Google Analytics (GA) install, the credit for the conversion will go to the CPC ad (the last click) but why should the organic search not get any credit, or even the referrer?
How it’s done – the __utmz cookie & Javascript
So how do we create a record of multiple referrers? We use cookies. We can make use of the fact that a cookie will typically stay on a user’s machine for several weeks or months, to keep track of their visits to our site from first click, all the way through to conversion and beyond.
To make the referral data as accurate as possible we make use of the __utmz cookie which is set by GA.js to gather referral data. By combining this with a set of custom Javascript functions which are executed after trackPageview(), we build a referral path string and store it in a cookie on the user’s machine. The cookie is given a lifetime of 6 months to match the default lifetime of the __utmz cookie.
Every time a user visits our site the cookie string is updated and then passed to setVar() – a user defined value function from the GATC so we can access it via the Google Analytics interface. We can then combine this with a converting traffic segment to find our top converting referral paths.
Side-note: If you need to configure __utmz to have a greater lifespan, you can configure the campaign tracking cookie length to suit your business using _setCookieTimeout().
A problem with sessions – Google’s override
Important: If you don’t close your browser window and visit the site at a later point in the same session, the referral data might not be entirely accurate.
Consider the following example;
Visit 1: Referral from www.example.com
Visit 2: Google organic search for “custom usb flash drives”
Visit 3: Referral from www.example2.com
This is what the __utmz cookie will look like:
Visit 1: Referral from www.example.com
Visit 2: Google organic search for “custom usb flash drives”
Visit 3: Google organic “custom usb flash drives” – Ooops! The referrer has been overridden!
Our data is inaccurate.
If you haven’t closed your browser then technically you are in the same browsing session and as a result, Google Analytics gives credit to the most important traffic source which it believes to be organic (as in the example above).
However with the advent of tabbed browsing, a new browser application instance isn’t necessarily what signifies a new session. I can open your site in one tab and a different one in another. I may then close your site’s tab and continue browsing for an unknown period of time – potentially weeks given the ability of PC’s to suspend/hibernate – and then return & convert.
To me it’s a different session but Google Analytics doesn’t know that.
Solving the problem – document.referrer & ga.js’ list of search engines
The problem arose because we trusted in what __utmz was telling us about the referral data. We do have access to another source for the referrer data though, Javascript’s document.referrer. We can then compare this with __utmz . If the two don’t agree we know that an override has occurred and can compensate, using document.referrer rather than the value stored in __utmz.
We compared __utmz with document.referrer by checking the referrer’s domain and query string against GA’s own list of search engines which you can extract from GA.js. We also needed to make sure we exclude the site’s own domain from being tracked as a self referrer so we define a variable with this value set.
Where do we go next
The Super Cookie script (in its downloadable format) will only track visitors coming from the standard locations – direct, referral, organic and CPC. The Super Cookie can be modified using Javascript which will allow for advanced customisation which will analyze visitors who come from various traffic sources such as email shots. Additionally, you may wish to adjust the script to ignore other referrers on your website network (if you have one).
Get the code
Download and try the super cookie now!
The download link contains two Javascript files and one HTML file. The HTML file shows you an example implementation of how the two Javascript files and the GATC integrate with eachother.
Commercial Services – would you like to start tracking the full referral path of your campaigns?
As a Google Analytics Authorized Consultant we can help you better understand and manage your Adwords marketing using the Super Cookie.


great. It would be greater if – don’t ask me how :) – this cookie could clear itself after a conversion. The other case is that super cookie inflates on and on and second or third conversion has ten or more sources, some of them already computed in first conversion.
Or am I missing something? :)
Cool script, although the only downside is that you need to use setVar() to track the referral path. I like to segment customers based on setVar() so I guess it dpeends on the business needs of the website before using it.
I think it would be interesting to implemenent just to see how much referral information is lost. I imagine big websites with big marketing budgets will benefit most from such a script.
Will definiately need to give it a try.
[...] una configurazione particolare di Google Analytics, però, è possibile conoscere le informazioni (mezzo, sorgente, parola chiave, ecc.) relative a [...]
Brilliant script guys – congratulations for releasing it into the wild.
Will you be building campaign tracking into a future version?
[...] segregate paid and organic search yet) or Eyeblaster. For a low cost, very basic solution the Google super cookie is an [...]
Hi Charles,
we’re reviewing the Super Cookie script at the moment to see what it will lead to next.
Campaign tracking is on our list but no decision has been made yet. Watch this space!
russ
Great explanation, but still 1 question. When having different sources in 1 session, organic will always win?
Ok – I’m looking at your USB example site (http://www.usb-flashdrive.co.uk/) and notice you first send GA the last value found for your custom variable and then reset that custom variable with new campaign data. Doesn’t this create attribution problems because the custom variable will link a conversion with the FIRST custom variable value reported in this session vs. the last custom variable value where you’re appending the latest campaign data?
Works well on a client site – but it seems to have a weird affect on the bounce rate. Since adding it the bounce has dropped from 20 to 0.8%
Hi all, we’ve been using superCookie for a wee while now and have found that in certain instances the cookie can get too long. For sites running on nginx for example, the web server will reject requests that have super long cookies as they look like overflow hack attempts. Has anyone else come across this or are we doing something wrong?
Just thought I would mention it.
Cheers
Doug
Thanks for this really useful tool!
@Charles – I have seen a decline in Bounce rate too on a test site as the code calls the GA page tracker twice (indicating 2 page views and no bounce). However, the answer appears to be changing the second call to a dummy account ID which should eliminate the problem (Assuming this doesn’t break anything else) – see http://www.google.ru/support/forum/p/Google+Analytics/thread?tid=0e672a6afb56558c&hl=en
Does the super cookie available for the google analytics asynchronous tracking code ?