Track Your New Customers with Cookies

It's possible using any number of website analytics tools such as Google Analytics, Mint, or just the tools that may be provided by your Internet host, to get a sense of how people who visit your website found out about it. It's a great way to see what your major referrers are.

I've been a bit more interested in how people who actually end up becoming customers originally came to our website. This one is a bit tricker, because it means tracking visitors all the way from their first visit through their purchase, but it is more revealing.

How can you do something like this for yourself? Well, it depends a lot on how your store works, but I'll outline the basics.

cookiesFirst off, you need to set a cookie when they arrive at any page of our website and the cookie has not yet been set. Just save the value of the HTTP referer [sic] header. If the value is empty (such as when somebody types in the URL, or clicks on a link to your website from an email message), I find that it's better to set a placholder like "direct" so I know for certain that we didn't have a known referrer. If the cookie is already set, don't replace it; they may come back to your website more than once, but it's (probably) the first referrer that you are interested in knowing about.

On our website, we use code injection to emit the following snippet of PHP before the contents of the page are rendered:

if(!isset($_COOKIE['referer'])) {
												$referer = $_SERVER['HTTP_REFERER'];
												if (empty($referer)) $referer = 'direct';
												$ok = setcookie('referer', $referer, 
													time()+3600*24*365, '/', '');
											} else { //cookie already set
												$referer = $_COOKIE['referer'];

We actually use two other bits of "intelligence" about how the user heard about us when they buy. One is an optional input field where we ask the new customer where they heard about us. Some inputs might be as useful as "Recommended through Apple store" or "Creative Pro mailing list" or even a name of a friend; in other cases it might not help much, e.g. "website" or "web search."  (Fortunately we have the referring URL to fill in the gaps.)

The other item we pass through to the purchase is the contents of the "__utmz" cookie that Google Analytics sets to track websites. It's not really meant to be human-readable, but it's pretty easy to figure out what it means. For instance, this example means that the visitor came to our website via a referral from an article on Wikipedia:


In practice, I've found that the "__utmz" cookie and the cookie we set ourselves are usually, but not always, equivalent. Google analytics is able to pick up a bit more (such as a special link from an email newsletter that uses parameters in the URL to indicate the source) that my cookie technique can't pick up. It's not that important to me that they are exact matches.

In any case, after collecting a referral cookie on all of our pages, the next thing you will want to do is pack up whatever referrer information you have and send into your purchase "funnel" so that if the visitor ends up buying your software, it will be stored with your transaction. Though our store uses Ajax, the main point is that I pass the $referer value in a hidden input into the PayPal store that we use as a "custom" parameter, so that it gets recorded with the transaction.

Upon return from PayPal, we know where this new customer came from originally, so I can get a sense of how people are finding us.

Every night, I have a script that emails a report of our last day's sales for me to skim through.  It's interesting to note, for instance, that a substantial number of our customers came about because they were either searching — often generically, where they had a need to fill (e.g. "website creator for mac") — or specifically for our company name or product name. Many of the others didn't have a referring website, which means that they probably typed in the URL directly, so perhaps they had heard about us through word of mouth.  The remainder, though surprisingly small, are links from other websites, except on days where major blogs or news sites covered a recent release.

If you start paying attention to how it is that your customers found you, you can use this to possibly improve your marketing. If you find that most of your referrals seem to be through links from other websites, and you don't find many instances of people just typing in your URL or searching for your product by name, maybe you need to work on word of mouth. If very few people are searching for the kind of problem that your application solves (without using your name), you probably need to do some Search Engine Optimization to make sure that people find you. You get the picture.

I hope you find this useful. If you end up doing this yourself, or if you have already started tracking our referrers through the sales process, please let me know in the comments with your insights.

Copyright © 2005-2014 Karelia Software. All rights reserved. · Terms & Conditions · Privacy Policy · Site Map