Web Marketing and Site Promotion

Web Marketing and Site Promotion provides expert advice on Internet marketing, search engine optimization, and website promotion strategies. Helping you meet marketing objectives within the limits of budgets and resources.

Using Cookies to Track Visitors
from Referrals to Sales

The biggest failing with most forms of tracking (and indeed with all kinds of interaction on the Web) is the lack of effective data persistance. Once a user has left a site, the session is closed.

To combat this, web cookies were introduced. A cookie is a tiny piece of data that is stored on the user's machine by the web browser. The data is stored until it expires, is deleted, or is over-written. This forms the basis of persistant data.

Any web page or server can request to store a cookie on the user's machine, and read back from it later on. There are many restrictions, of course, for security reasons.

A single cookie cannot be larger than 4Kb (which is around 4,000 characters, which is plenty for most needs). No single domain can set more than 20 cookies on a single machine. A user's machine can store no more than the maximum of 300 cookies in total at any one time.

The latter two restrictions are the most problematic for webmasters today. Far too many sites are writting far too many cookies. Since a single site can write as many as 20 cookies, the entire 300 cookie limit can be reached from visiting just 15 websites. This means that most cookies get over-written by newer cookies long before they expire.

This is something that we web-developers ourselves need to address, since most of the sites storing multiple cookies are storing far less than the 4,000 character limit of a single cookie.

Whatever the cause, the fact remains that cookies will generally be over-written by others within a week or two, and could be over-written far sooner. Cookies are therefore unreliable.

Users can choose to refuse cookies, either via their browser settings, or by default with many security applications (such as the popular software firewall, ZoneAlarm). The problem is that many advertising networks and adult sites have abused and exploited cookies, and thus given cookies an unfairly bad name and reputation.

For this reason, and for general politeness, it is very important that if you choose to use cookies on your site, you should have a clearly defined privacy policy. Use this to increase the acceptance of cookies by explaining exactly what you are using them for.

What does the tracking cookie do?

That's most easily shown by example.

The cookie I use, which is my own creation, is a simple JavaScript that carefully and cleverly stores a cookie only under certain circumstances.

  • The cookie is only even thought about on your first page view of this domain, of each session.
  • The cookie is only written or accessed via JavaScript so that it is easily ignored by users who are highly security conscious.
  • The cookie only gets written if there is a known referring page, and not otherwise.

The code for my cookie script is actually very simple:

// JavaScript Cookie Code
// Coding by Ammon Johns
// www.webmarketingplus.co.uk

var cDomain = self.location.hostname;
if(cDomain.indexOf(".") < cDomain.lastIndexOf(".")){
  var domainOffset = cDomain.indexOf(".")+1
  cDomain = cDomain.substr(domainOffset);
}

if(document.referrer.indexOf(cDomain)==-1 && document.referrer!="" && document.cookie.indexOf("referrer=")==-1){
var expDays = 90;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var refdate = new Date();
document.cookie = "referrer=" + escape(document.referrer + "&&&" + refdate.toGMTString()) + "; expires=" + exp.toGMTString() + "; path=/" + "; domain=" + cDomain;
}

var allCookies = document.cookie;
var cPos = allCookies.indexOf("referrer=");
if(cPos != -1){
var cdstart = cPos + 9;
var cdend = allCookies.indexOf(";", cdstart);
if(cdend == -1) cdend = allCookies.length;
var cookieContent = allCookies.substring(cdstart,cdend);
cookieContent = unescape(cookieContent);
var cdatestart = cookieContent.indexOf("&&&", 0);
var cdateend = cookieContent.length;
var cRefer = cookieContent.substring(0,cdatestart);
var cDateRef = cookieContent.substring(cdatestart +2,cdateend)
}
else{
var cRefer = "No cookie";
var cDateRef = "No cookie";
}

You are free to use this code, and/or to vary it for your own purposes, providing that you also produce a privacy policy, and that you additionally provide a crediting link to this site from any site where you are using the cookie. In this way, you are paying for my time in writing the script by helping other webmasters learn to use cookies more responsibly.

The point of a cookie like the one above is that it can track an original referral, even on subsequent visits. I can choose to record this data (if present) when I take an order online, and so can see which marketing or promotion lead to the sale.

I have provided the following guide if you'd like a simple, step-by-step set of instructions for installing and using the cookie.

Introduction to Tracking Web Promotion Results
Using Web Server Logs for Tracking Usage
Using Dedicated Landing Pages to Track Referrals
Using Referal IDs in URLs to Track Referrals
Using Cookies to Track Referrals and Repeat Visits

Copyright ©2001-2007 Ammon Johns

Web Marketing and Site Promotion Privacy Policy / Cookie Usage