[英]How to add a custom event tracking with Google Analytics
Google Analytics custom event not working, as it is not tracked on Google Analytics statistic View. Google Analytics自定义事件无法正常运行,因为它未在Google Analytics统计信息视图中进行跟踪。 I written code for onclick, but it is not tracked.
我为onclick编写代码,但没有跟踪。 Here is my code:
这是我的代码:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-42651041-1']);
_gaq.push(['_trackPageview']);
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-42651041-1', '1800accountant.com');
ga('send', 'pageview', '/Step1');
</script>
<script type="text/javascript">
function test(){
_gaq.push(['_trackEvent','Popup','Click','Step1']);
alert("GA Code executed");
}
</script>
<p onClick="return test()" style="cursor:pointer;">Click Here</p>
This is because you are using the old syntax gaq.push
, which is for the Classic Analytics. 这是因为您使用的是旧语法
gaq.push
,它适用于Classic Analytics。 You have actually implemented the newer version of GA called Universal Analytics, which uses a different syntax for sending events. 您实际上已经实现了名为Universal Analytics的更新版GA,它使用不同的语法来发送事件。
The correct code to use, according to the Google Developer information , it should be written like this: 根据Google Developer信息 ,使用正确的代码,它应该是这样编写的:
ga('send', 'event', 'category', 'action', 'label', value);
So, using your example, I'd write it something like this: 所以,使用你的例子,我会写这样的东西:
ga('send', 'event', 'Popup', 'Click','Step1');
Event , category and action are mandatory, while label and value are optional. 事件 , 类别和操作是必需的,而标签和值是可选的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.