[JavaScript][GA] Google analytics – 兩組帳號、多帳號並存一網站 (通用分析)

看以下Code即可:

<script>
  (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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-12345678-1', 'auto');   //建立第一個帳號
  ga('create', 'UA-87654321-2', 'auto', 'secondGA'}); //建立第二個帳號
  ga('require', 'displayfeatures');  //啟用客層和興趣報表
  ga('send', 'pageview');            //送出第一個帳號PV
  ga('secondGA.send','pageview');    //送出第二個帳號PV
</script>

Refer:https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers

Leave a Reply

Your email address will not be published. Required fields are marked *