我正在尝试使用Universal Analytics跟踪跨域调用,我已经直接从google文档中复制粘贴代码,并且由于某种原因,它没有使用预期参数来装饰外部链接(例如{{ 1}})。
以下是我们尝试的确切代码:
_ga=1.182119591.1441315536.1362115890410
我尝试使用动态链接器而不是装饰每个链接:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script type="text/javascript" >
var UAAccount = 'UA-0000000-0';
var UATrackerName = 'pageTracker';
(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','http://www.google-analytics.com/analytics.js','ga');
ga('create', UAAccount, 'auto', {'allowLinker': true });
ga( UATrackerName + '.send', 'pageview');
function decorateMe(event) {
event = event || window.event; // Cross browser hoops.
var target = event.target || event.srcElement;
if (target && target.href) { // Ensure this is a link.
ga('linker:decorate', target);
}
}
// Cross browser way to listen for events.
function addListener(element, type, callback) {
if (element.addEventListener) element.addEventListener(type, callback);
else if (element.attachEvent) element.attachEvent('on' + type, callback);
}
$( document ).ready(function() {
var linker;
var myLink = document.getElementById('pippo'); // Add event listeners to link.
addListener(myLink, 'mousedown', decorateMe);
addListener(myLink, 'keydown', decorateMe);
});
</script>
</head>
<body>
<a href="http://www.goo.gl" id="pippo" target="_self"> anchor </a>
</body>
</html>
但没有成功:外部链接没有ga('require', 'linker');
ga('linker:autoLink', ['goo.gl']);
参数。
答案 0 :(得分:0)
由于某种原因,您为跟踪器命名为“pageTracker”,但在调用对象方法时您没有使用该名称,包括创建和链接器方法:
ga('create', 'UA-XXX-Y', {name: 'pageTracker'});
ga('pageTracker.linker' ...);
ga('pageTracker.require' ...);