Google Analytics hitCallback事件跟踪无效 [英] Google Analytics hitCallback event tracking not working

查看:532
本文介绍了Google Analytics hitCallback事件跟踪无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用事件跟踪和hitcallback来跟踪被点击的链接。我的分析代码看起来像这样...

 < script type =text / javascript> //< ;! [CDATA [
var _gaq = _gaq || [];
_gaq.push(['_ setAccount','UA-XXXXXXXX-X']);
_gaq.push(['_ 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);
})();
//]]>< / script>

我试图跟踪的链接看起来像这样....

 < a href ='http://cool.com/'onclick =var href = this.href; ga('send','事件','出站','点击',this.href,{'hitCallback':function(){document.location = href;}}); return false;>酷< / a> 

我遵循 http://www.swellpath.com/2013/12/universal-analytics-using-hitcallback/ 但它仍然没有工作。



我缺少什么?

解决方案

问题是您正尝试将Universal Analytics语法(analytics.js)用于您的点击跟踪,但您使用的GA库是旧的 _gaq (ga.js)语法。

_gaq style可以让你指定一个回调函数,虽然它没有记录。在进行 _trackEvent 调用之前,基本上你必须 _set 回调函数。



您的链接应如下所示:

 < a href ='http://cool.com'onclick =var _this = this; _gaq.push(['_ set','hitCallback',function(){document.location = _this.href;}]); _ gaq.push (['_trackEvent','outbound','click',_ this.href]); return false;> cool< / a> 


I am trying to track a link being clicked using event tracking and hitcallback. My analytics code looks like this...

<script type="text/javascript">//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_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);
})();
//]]></script>

And the link I am trying to track looks like this....

<a href='http://cool.com/' onclick="var href = this.href; ga('send','event','outbound','click', this.href, {'hitCallback': function(){document.location = href;}}); return false;">Cool</a>

I followed the hitcallback example from http://www.swellpath.com/2013/12/universal-analytics-using-hitcallback/ but its still not working.

Am I missing something?

解决方案

The problem is you are attempting to use Universal Analytics syntax (analytics.js) for your click tracking, but the GA library you are using is the older _gaq (ga.js) syntax.

_gaq style does let you specify a callback function, though it's undocumented. Basically you have to _set the callback function before you make the _trackEvent call.

Your link should look like this:

<a href='http://cool.com' onclick="var _this=this;_gaq.push(['_set','hitCallback',function(){document.location=_this.href;}]);_gaq.push(['_trackEvent','outbound','click',_this.href]);return false;">cool</a>

这篇关于Google Analytics hitCallback事件跟踪无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆