Um mehrere Domains, die in der Statistik zusammengefasst sein sollen, unter einer einzigen Google Analytics Property zu erfassen und trotzdem keinen hässlichen „_ga“-Parameter beim Domainwechsel an den URLs zu haben, eignet sich folgender Code:
<script> var gaProperty = 'UA-0000000-1'; var disableStr = 'ga-disable-' + gaProperty; if (document.cookie.indexOf(disableStr + '=true') > -1) { window[disableStr] = true; } function gaOptout() { document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/'; window[disableStr] = true; } (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-0000000-1', 'auto', {'allowLinker': true}); ga('require', 'linker'); ga('linker:autoLink', ['www.dom1.xy', 'www.dom2.xy', 'www.dom3.xy'] ); ga('set', 'anonymizeIp', true); ga('send', 'pageview'); $(window).load(function() { currentURL = window.location.href; newURL = currentURL.replace(/&_ga(\=[^&]*)?(?=&|$)|_ga(\=[^&]*)?(&|$)/,""); if(newURL.substr(-1) === "?"){newURL = newURL.slice(0, - 1)} history.replaceState("state", "", newURL); }); </script>
Beispiel-Sites im Code: www.dom1.xy, www.dom2.xy, www.dom3.xy, Beispiel-Property im Code: UA-0000000-1