I want to migrate classic to Universal Google Analytics tracking, I want to track content and events only for the live domain (not staging):
Currently, I have used method for classic version:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'TRACKING ID']);
_gaq.push(['_setDomainName', 'mydomain.com']);
_gaq.push(['_trackPageview']);
I have tried below method but it is not working:
ga('create', 'TRACKING ID', {'cookieDomain': '.mydomain.com'});
also tried below method:
ga('create', 'TRACKING ID', 'auto', {'legacyCookieDomain': 'mydomain.com'});
Can you please help on this?
I you are using Adwords & Doubleclick you should consider gtag.js instead of Universal
Using '.domain.com' or 'auto' on create event generates the same result. Check Google Analytics cookieDomain documentation. This option is used in order to share the cookie between subdomains.
If you want to avoid collecting data from other domains or subdomains, use a filter (include only your domain).