Parsing __utmz tracking cookie to get referral

Thinker picture Thinker · Jul 31, 2009 · Viewed 15.3k times · Source

I use Google Analytics on my site, and I want to read __umtz cookie to get referring link. I made some research and I wrote such code:

$refer=explode('utmcsr=',$_COOKIE['__utmz']);
if(count($refer)>1) $refer=explode('|',$refer[1]);
$refer=addslashes($refer[0]);

The problem is, this is not always working, sometimes I get junk as result. What I am doing wrong? Maybe someone have a good description of this cookie?

Answer

Joao Correia picture Joao Correia · Jun 14, 2010

Check my Google Analytics Cookie Parser.

Google Analytics PHP Cookie Parser is a PHP Class that you can use to obtain data from GA cookies such as campaign, source, medium, etc. You can use this parser to get this data on your contact forms or CRM.

Just updated to version 1.2 with minor bugfixes and more info, number of pages viewed in current visit.