首页 文章

Google Analytics - 两个帐户的出站链接跟踪

提问于
浏览
1

我已成功跟踪我网站上的网页以向两个Google Analytics帐户报告,但是,我无法通过出站链接跟踪来跟踪Google Analytics帐户中的事件(它也没有跟踪) . 任何想法为什么recordoutbound链接功能不起作用?以下是我的代码:

<script type="text/javascript">

  var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-1xxxxxx-x']); 
_gaq.push(['_setDomainName', 'mysite.com']); 
_gaq.push(['_setAllowLinker', true]); 
_gaq.push(['_trackPageview']); 


_gaq.push(['b._setAccount', 'UA-2xxxxxx-x']);
_gaq.push(['b._setDomainName', 'mysite.com']);
_gaq.push(['b._setAllowLinker', true]);
_gaq.push(['b._trackPageview']);

  (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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

function recordOutboundLink(link, category, action) { 
try { 
var onePageTracker = _gat._getTracker("UA-1xxxxxx-x"); 
var twoPageTracker = _gat._getTracker("UA-2xxxxxx-x");
onePageTracker._trackEvent(category, action); 
twoPageTracker._trackEvent(category, action);
setTimeout('document.location = "' + link.href + '"', 100) 
} catch (err) { } 
} 
</script>

2 回答

  • 1

    您似乎正在使用基于Google旧的出站链接跟踪示例的代码,该示例存在一些错误 .

    尝试以下,使用 _gaq.push 代替:

    function recordOutboundLink(link, category, action) { 
      try{
        _gaq.push(['_trackEvent', category,  action]);
        _gaq.push(['b._trackEvent', category,  action]);
      } catch(ignore){};
      setTimeout(function(){document.location.href = link.href;}, 100);
    }
    
  • 0

    你可以压缩一点...因为你认为你不需要重新定义跟踪对象,特别是因为你正在命名它们(你只命名一个,b) .

    对于实际的事件跟踪,您使用与pageview相同的_gaq.push(参见下文) .

    此外,不是100%肯定,但如果您尝试将2个跟踪器设置为相同的域名,则可能会发生冲突...我似乎记得在该场景中遇到跨多个子域的跟踪问题,并且必须将前缀1设置为点 .

    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['a._setAccount', 'UA-1xxxxxx-x'],
                  ['a._setDomainName', 'mysite.com'],
                  ['a._setAllowLinker', true],
                  ['a._trackPageview'],
                  ['b._setAccount', 'UA-2xxxxxx-x'],
                  ['b._setDomainName', '.mysite.com'],
                  ['b._setAllowLinker', true],
                  ['b._trackPageview']);
    
          (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';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();
    
        function recordOutboundLink(link, category, action) { 
            try { 
                _gaq.push(['a._trackEvent', category, action, link],
                          ['b._trackEvent', category, action, link]); 
                setTimeout('document.location = "' + link.href + '"', 100); 
            } catch (err) { } 
        } 
    </script>
    

相关问题