Disable Google Anayltics cookie from sending to less domain cookie

To optimize my site, I created a static subdomain for content such as images, css and javascript. How do I disable the Google Analytics tracking tracking cookie to send to my static subdomain, but still for example.com and www.example.com?

You have already looked through some documents with no luck

+4
source share
2 answers

You cannot have a cookie that goes to www.example.com and example.com , but not othersubdomain.example.com .

In theory, you might have a cookie that is sent to example.com , but not subdomain.example.com , but it does not work in IE.

That's why you should not use the no-www example.com address when you plan to use subdomains with your own security context. It is best to have only one of www.example.com and example.com as the "correct URL". Therefore, set up redirection for example.com to go to www.example.com and cookies will not be used unless you intentionally set domain=.example.com on them.

+2
source

If you are having problems with Google Analytics creating a cookie for each domain, including your subdomains. Here is my solution that I posted elsewhere on this subject.


According to golly, I think I found a workaround for broken code provided by Google.

If you go to GA and get a non-asynchronous code and select:

 One domain with multiple subdomains Examples: apps.konoro.org store.konoro.org video.konoro.org 

You will see that it gives you sample code from .konoro.org . Change this to www.konoro.org and all cookies will have: .www.konoro.org (with a dot in front of them). A.

Now, if you go back to your Async code, there is only one difference from Async. You need to put ['_setDomainName', 'www.konoro.org'] as the second option, and not after ['_trackPageview'] .

For some reason, since this is the second option, it works great.

My last code is:

 var _gaq = _gaq || []; _gaq.push( ['_setAccount', 'UA-XXXXXXX-1'], ['_setDomainName', 'www.konoro.org'], ['_trackPageview'] ); (function() { var ga = document.createElement('script'); ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; ga.setAttribute('async', 'true'); document.documentElement.firstChild.appendChild(ga); })(); 
+3
source

Source: https://habr.com/ru/post/1315463/


All Articles