【问题标题】:Google Analytics - Outbound Link Tracking for two accountsGoogle Analytics - 两个帐户的出站链接跟踪
【发布时间】:2013-04-12 08:38:30
【问题描述】:

我成功地跟踪了我网站上的页面以向两个 Google Analytics(分析)帐户报告,但是,我无法使用出站链接跟踪来跟踪 Google Analytics(分析)帐户中的事件(两者都没有跟踪)。为什么记录出站链接功能不起作用的任何想法?以下是我的代码:

<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> 

【问题讨论】:

    标签: google-analytics event-tracking


    【解决方案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);
    } 
    

    【讨论】:

      【解决方案2】:

      您可以稍微浓缩一下...因为有人认为您不需要重新定义跟踪对象,尤其是因为您正在命名它们(您只命名了一个,b)。

      对于实际的事件跟踪,您使用与浏览量相同的 _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> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多