Google analytics event tracking on Multiple accounts not working

我只是一个虾纸丫 提交于 2019-12-11 07:22:31

问题


I have multiple accounts on some pages - I am trying to track some events - they fire beautifully when I test them on Fiddler - but they are not coming into my analytics - the code is below - what am I doing wrong? Three days later any help would be GREAT.

<script type="text/javascript"> 
    var _gaq = _gaq || [];

    _gaq.push(
        //tracking for first
        ['_setAccount', 'UA-XXXXXX-1'],
        ['_trackPageview'],

        //tracking for second
        ['b._setAccount', 'UA-XXXXXX-16'],
        ['b._trackPageview'],
        ['b._trackEvent'],
        ['b._trackPageLoadTime']
    );

    (function() { 
        var ga = document.createElement('script'); ga.type = 'text/javascript';
        ga.async = true; 
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www')
        + '.google-analytics.com/ga.js'; 
        (document.getElementsByTagName('head')[0] ||
        document.getElementsByTagName('body')[0]).appendChild(ga); 
    })();
</script>

<li><a href="#anchor_2" class="gray"
onClick="_gaq.push(['b._trackEvent', 'button3', 'menu', 'clicked']);">link</a></li>

回答1:


Note that _trackPageLoadTime is deprecated now. You don't need that anymore. Also the event on the top doesn't make sense. Events must have at least two string parameters and they have optional 3rd string parameter and 4th integer parameter.

So your code on the top should look like this:

 var _gaq = _gaq || []; 
_gaq.push(
  //tracking for first
  ['_setAccount', 'UA-XXXXXX-1'],
  ['_trackPageview'],
  //tracking for second
  ['b._setAccount', 'UA-XXXXXX-16'],
  ['b._trackPageview']

Then when you're firing the event you are only sending this to your b account and I believe you want to send to both. So for that reason you should do something like this:

<li><a href="#anchor_2" class="gray" onClick="_gaq.push(['_trackEvent', 'button3', 'menu', 'clicked']);_gaq.push(['b._trackEvent', 'button3', 'menu', 'clicked']);">take me somewhere</a></li>


来源:https://stackoverflow.com/questions/9264348/google-analytics-event-tracking-on-multiple-accounts-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!