Parsing __utmz tracking cookie to get referral

你说的曾经没有我的故事 提交于 2019-12-09 17:17:55

问题


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?


回答1:


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.




回答2:


You could use $_SERVER['HTTP_REFERER'] to get the Referer.

Overall it is a bad idea to use other's people's cookies to get data unless you know exactly how they work, and when they update, or you use an API that THEY have made available.

Lets say the Google decides to revamp the cookie altogether so that the Referer information isn't available on the cookie, your system would break. It is best to get data directly from your own sources rather than someone else's.



来源:https://stackoverflow.com/questions/1214069/parsing-utmz-tracking-cookie-to-get-referral

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!