从PHP阅读Google Analytics Cookie

时间:2022-08-16 15:14:45

I'm trying to read __utma Google Analytics cookie from PHP to find out if the user is a new one or not.

我正在尝试从PHP中读取__utma Google Analytics Cookie,以确定用户是否是新用户。

My website is on www.domain.com without HTTPS

我的网站在没有HTTPS的www.domain.com上

I've noticed with the chrome console that cookie domain is .www.domain.com ie with a point before the domain. Thus when I try to read cookies with php variable $_COOKIE it does not show up.

我已经注意到Chrome控制台的cookie域名是.www.domain.com,即在域名之前有一个点。因此,当我尝试使用php变量$ _COOKIE读取cookie时,它不会显示出来。

I've also notice that with a HTTPS domain, two cookies are created : one with .www.domain.com and a second one with .domain.com which can be read.

我还注意到,使用HTTPS域,会创建两个cookie:一个带有.domain.com,另一个带有.domain.com,可以读取。

Lastly I can read .www.domain.com using Javascript but I would like to do it with PHP.

最后我可以使用Javascript阅读.www.domain.com,但我想用PHP来做。

What am I missing ?

我错过了什么?

Demo page : http://gandi.buypacker.com/ga/example.php

演示页面:http://gandi.buypacker.com/ga/example.php

2 个解决方案

#1


0  

Apparantly others have had this same issue. Someone has made a class to help parse GA cookies: https://github.com/joaolcorreia/Google-Analytics-PHP-cookie-parser

其他人也有同样的问题。有人创建了一个类来帮助解析GA cookie:https://github.com/joaolcorreia/Google-Analytics-PHP-cookie-parser

#2


0  

Make sure you set your cookie domain explicitly in your Google Analytics JS code:

确保在Google Analytics JS代码中明确设置Cookie域:

_gaq.push(['_setDomainName', 'www.domain.com']);

#1


0  

Apparantly others have had this same issue. Someone has made a class to help parse GA cookies: https://github.com/joaolcorreia/Google-Analytics-PHP-cookie-parser

其他人也有同样的问题。有人创建了一个类来帮助解析GA cookie:https://github.com/joaolcorreia/Google-Analytics-PHP-cookie-parser

#2


0  

Make sure you set your cookie domain explicitly in your Google Analytics JS code:

确保在Google Analytics JS代码中明确设置Cookie域:

_gaq.push(['_setDomainName', 'www.domain.com']);