javascript - Google Analytics multiple tracking on a single web page -
i partnership website, in order put universal analytics tracking code on single web page. website's owner has one.
i've searched on google developers , stack find how use multiple tracking codes. built code i'm not sure whether it's ok, don't want interfere data. want common analytics data in own account.
<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','https://www.google-analytics.com/analytics.js','ga'); //1- create default tracker , mytracker ga('create', 'ua-xxxxx-1', 'auto'); // default tracker ga('create', 'ua-xxxxx-50', 'auto', 'mytracker'); // tracker //2- pageview data of mytracker ga(function(){ var nondefaulttracker = ga.getbyname('mytracker'); var mytrackerpageview = nondefaulttracker.get('pageview'); console.log(mytrackerpageview); }); //3- update mytracker pageview data ga('mytracker.set','pageview'); //4- send mytracker , default tracker pageview data ga('send','pageview'); ga('mytracker.send','pageview'); </script>
someone did ?
thanks!
you not need step 2 , 3. get
method of tracker returns field specified in argument, , since ga not have data field called pageview
undefined
(which value set page path - not want this).
however pageview tracking work fine without trying retrieve values previous tracker. unless have set fields set named tracker both report same thing.
Comments
Post a Comment