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.

Installing and Using the
JavaScript Tracking Cookie.

In these pages you will find a simple, step-by-step guide to installing and using a JavaScript cookie tracking solution to track visitors (and sales) to the original referral.

This enables you to make more accurate assessments of the ROI (return on investment) of your marketing and advertising campaigns.

The first thing you need is the JavaScript file that will do all of the cookie writing and reading for you. To make this as simple as possible, I have provided this file ready to use. You just need to save this file and later upload it to your site.

Step 1. Get the JavaScript file

Right-click on the link to make the context menu appear, and choose 'Save As' from the menu options, then save the file to a folder where you'll easily find it later.
The JavaScript file (refercookie.js)
Again, remember to save the file from the link above, not merely to view it.

Note:
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, and in providing instructions for using it, by helping other webmasters learn to use cookies more responsibly.

The JavaScript cookie for referral tracking that is provided here should not need any adaptation for most users. It configures itself to whatever website domain name it is installed on and called from.

If you should need to adapt the cookie, you can edit a .JS file like this in any plain text editor (such as Notepad). You should never use a Word Processor (such as Word) for plain-text format files because this would add extra formatting that would prevent the file working

Step 2. Upload the file to your site

Once you have saved the JavaScript file () for your use, the next step is to upload it to your own website. It is generally easiest to install the file to the root directory of your site, but it can be installed to any sub-directory you may wish.

On my own site here, it has been uploaded to the root directory, and thus has the following URL:
http://www.webmarketingplus.co.uk/refercookie.js

Wherever you install the JavaScript file to, make a note of the URL of the JavaScript file on your own web server for use in the installation process.

Step 3. Installing the Cookie JavaScript

Within each page of your site, you need to add one small line of code to call the JavaScript that you have just uploaded into action.

You will need the URL of the JavaScript file that you made a note of in the previous step. The URL of the JavaScript file is the source of your script.

In each page of your site, preferrably within the page header (i.e. between the <HEAD> and the </HEAD> tags of each page) you need to call the JavaScript with <SCRIPT> tags, as follows:

<script language="JavaScript" type="text/javascript" src="http://www.webmarketingplus.co.uk/refercookie.js"> </script>

Note: Replace the URL (marked in red) with that of your own copy of the JavaScript, the source URL that you noted earlier in step 2.

Once you have added this code to every page, and uploaded the changed pages, the referral cookie JavaScript is installed and working throughout your website.

Step 4. Using the cookie referral data

Using the data stored in the cookie is as simple as referring to the JavaScript variables that are built in to the script you have installed.

There are two variables:
cRefer - This variable contains the referral URL.
cDateRef - This variable contains the full date of the initial referral.

To include the data within a form, you can use the following simple JavaScript lines within the HTML of the form:

<script language="JavaScript" type="text/javascript">
<!--//start hiding
document.write('<input type="hidden" name="ReferURL" value="' + cRefer + '">');
document.write('<input type="hidden" name="ReferDate" value="' + cDateRef + '">');
//end hiding-->
</script>

The code above creates two hidden fields in the form to contain the data from the cookie.

You could alternately choose to pass the variables through to another page, even one on another domain/server through use of a query string.

example:

<a href="cookie1.html" onClick="top.location.href='cookie1.html?' + cookieContent; return false">Click me</a>

Which displays as:

Click me

Step 5. Track the data

By including the data in your order forms, contact forms, or wherever you wish to, you can look up the original referral that lead to the specific action where you are tracking the data. In this way, you can spot truly important trends in the quality of referrals, rather than just the volume that other tracking solutions focus upon.

Copyright ©2001-2007 Ammon Johns

Web Marketing and Site Promotion Privacy Policy / Cookie Usage