The primary way to track marketing and word-of-mouth about your product is to look at web site referrers. Easy. Just install “Mint”:http://www.haveamint.com/ and you’re done.
But not all referrers are created equal. A prominent link on Digg might lead to sales or it might lead to dozens of “wish it was free” comments on your blog. To really judge the effectiveness of referrers (and in turn give a better idea about where resources should be placed in the future) take it one step further to track the initial referrer link all the way through to purchase. You want to know where the customer first learned about your product.
This isn’t a new idea and I’m certainly not the first to do it. Wil Shipley spoke at length about this technique during “his C4 talk”:http://www.viddler.com/explore/rentzsch/videos/4/ in 2007, in the context of online advertising. In talking with other developers it became clear to me that most people don’t do this, even though it can be achieved in about a dozen lines of code.
The basics are pretty simple:
- When a link comes in to your site, see if a special cookie is set. I called mine “WiiTransferRef”.
If the cookie is set, you have a repeat visitor. Nothing to do at this point.
If the cookie is missing, this user is likely visiting your site for the first time. Put the referrer value in the cookie.
After a purchase is complete, check for this cookie and add an entry to the database with the referrer value and timestamp for the order.
You can add more intelligence as suits your requirements and available time, but the basics don’t need to be any more complex than this. For bonus points and slightly improved security, you could add a database entry that tracks the referrer value and use the cookie as a session that simply points to that row, updating the database to show completed orders, but I chose not to do that to keep the database uncluttered.
Here’s the PHP source for my main product page:
And then the source for the final “thanks!” page after a purchase is complete:
Note that because I am using simple PayPal buttons, not all customers actually reach the last page, because they can ignore the “return to seller” link after a completed transaction and instead go wherever they chose. This limitation goes away if you have rolled your own store or used something like “PotionStore”:http://www.potionfactory.com/potionstore.
I’ve been tracking these for over a year now. I’ll share some stats about what I’ve learned in a future blog post.