2013-04-19 62 views
1

我成功跟踪我网站上的页面以向两个Google Analytics帐户报告,但是,我无法通过出站链接跟踪来跟踪Google Analytics帐户中的事件(这不是在任一方面跟踪)。任何想法为什么recordoutbound链接功能不工作?以下是我的代码: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> 

回答

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

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