Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics - Setting 'ga' cookie domain to '.www.example.com'

This is how the cookie domain is usually set in Google Analytics's tracking code. I understand auto and none are the other two options.

ga('create', 'UA-45015643-1', 'example.com');

The above code, which is a part of Universal Tracking code, sets the cookie domain to .example.com.

Cookies when viewd in EditThisCookie chrome extension

Setting cookie domain to .example.com makes cookie accessible to all of its subdomains. But I have set up a cookie-free domain http://static.example.com to download static contents and I don't want cookies to be sent along with this type of static resource request. So, I tried this:

ga('create', 'UA-45015643-1', 'www.example.com');

This resulted the cookie domain to be set to .www.example.com. The tracking was working fine after this update (I used Realtime view to verify), apparently.

But I want to be sure if this actually have no side effects or is not a bad practice.

like image 562
Dilip Raj Baral Avatar asked Oct 21 '22 06:10

Dilip Raj Baral


1 Answers

GA recommends you set the cookie to the TLD (example.com) so that if you go from let's say www.example.com to cart.example.com or secure.example.com in the checkout process, your visitors would still share the main example.com cookie.

If this isn't a concern for you, then you can use the www.example.com configuration above without consequence.

like image 162
TomFuertes Avatar answered Oct 23 '22 00:10

TomFuertes