2
votes

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

My website is on www.domain.com without HTTPS

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.

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.

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

What am I missing ?

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

2

2 Answers

0
votes

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

0
votes

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

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