新的Google Analytics(分析)(analytics.js)设置中没有跟踪事件 [英] Events not being tracked in new Google Analytics (analytics.js) setup
问题描述
我有一个网站,我正在使用新的Universal Analytics(analytics.js)进行跟踪。一切都是使用以下代码片段进行设置和工作(浏览量,引荐等):
< script>
(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-39570713-1','site.com');
ga('send','pageview');
< / script>
位于< / head> $ c $之前c>标签。
我正在使用JQuery来消除事件。我用一个警告消息测试了JQuery,它被调用,所以这不是问题。以下是点击按钮时触发的片段:
$('#submitButton')。on('click' function(){
ga('send','event','button','click','contact form');
});
Google Analytics(分析)的事件部分中没有任何内容。我继续点击按钮,甚至从不同的电脑,以确保它不排除我的IP地址。由于Google提供的 Google Analytics(分析)文档不提供解决方案我解决了这个问题的唯一方法就是回到上一个版本的Google Analytics(分析)(非测试版):
< script type =text / javascript>
var _gaq = _gaq || [];
_gaq.push(['_ setAccount','UA-39570713-2']);
_gaq.push(['_ setDomainName','optimino.com']);
_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>
I have a website that I am using the new Universal Analytics (analytics.js) to track. Everything is setup and working (pageviews, referrals, etc.) using the following code snippet:
<script>
(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-39570713-1', 'site.com');
ga('send', 'pageview');
</script>
That is located before the </head>
tag.
I am using JQuery to fire off an event. I tested the JQuery with an alert message and it is getting called, so that isn't the problem. Here is the snippet that fires when a button is clicked:
$('#submitButton').on('click', function() {
ga('send', 'event', 'button', 'click', 'contact form');
});
Nothing is appearing in the Events section of Analytics. I keep clicking the button, even from different computers just to make sure it isn't excluding my IP address. Because the Analytics doc that Google provides does not provide a whole lot of explanation I'm at a loss here.
The only way I solved the problem was rolling back to the previous version of Analytics (non-beta):
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-39570713-2']);
_gaq.push(['_setDomainName', 'optimino.com']);
_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>
这篇关于新的Google Analytics(分析)(analytics.js)设置中没有跟踪事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!