Tag Your Visitors With Cookie Hacks

by admin on July 23, 2009

If you haven’t already noticed, I have been researching quite a bit regarding hacking up the standard Google Analytics code, specifically how cookies are set, in order to further refine the data that you are collecting. This week was inspired off a post from the Official Google Analytics Blog outlining a few tips regarding adding demographic data to the numbers, giving them more meaning.

I want to take it in a little bit of a different direction. I find it difficult (probably as most bloggers do) to generate feedback on my posts in the form of comments or tracbacks. And to be honest, I can’t really determine what would influence someone to leave a comment versus someone who reads regularly. The more experienced bloggers would be able to give me a clear answer, however I am going to try to work it out with Google Analytics.

Modifying the GA Code - setVar

The answer lies with the pageTracker._setVar() function of the Analytics API. What this function does according to the documentation is allow you to create custom variables that you can tag your visitors with when they visit your website. It adds it to the __utmv cookie and lasts for 2 years.

How we are going to do it today is everytime someone comments on a blog that I author for, it will tag that visitor as a “commenter”. That will allow me to monitor their movement through the website and determine any correlations between commenters, return visitors and converters.

How do we do it in Wordpress?

Very easily in fact. Look for the file that generates your comments template and styling. Generally it is in your theme directory and the comments.php file.

Much like all the other Javascript function calls, I will be attaching it as an onclick event on the submit button. We make the assumption that someone has filled in all the key elements of the comment (name, email, the comment itself) and is now ready to submit. Whether the person is a spammer or not, or even if the comment is approved or not does not matter. The fact is someone (or something) was motivated enough to leave something behind on their visit.

My submit button code now looks like this:


After about 24 hours or so, you will be able to view your Google Analytics User Defined Reports and see that information in there. For further refinement you can even set up a separate profile to generate reports specific to their actions across the website.

Tune in next week as I further dig around the cookie structures of Analytics and see what other gems are in store. After a few months of data collection, I will be giving tips on what to do with the data once we have collected it.

{ 4 trackbacks }

Ольга
April 6, 2010 at 11:41 am
Валентин
April 9, 2010 at 1:33 pm
ВАн4ezzZ
May 2, 2010 at 5:14 pm
Light
June 7, 2010 at 4:16 pm

{ 0 comments… add one now }

Leave a Comment