问题描述
我在我的ASPX Web应用程序中实施了analytics.js(新版本)。
我的页面浏览工作正常,但事件通常不会被发送。
在我的例子中,我尝试了3个不同的按钮,但只有一个他们解雇了这个事件。
我为每个事件添加了一个警告框,以验证它是否已被触发,并且全部显示。
这是我的js,放在< / head>
$ b $ pre $ (函数(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-XXXXXXXX-1',{
'cookieDomain':'none'
});
ga('send','pageview',{
'page':'/ team / main',
'title':'Logged in'
}); (),
$(document).ready(function(){
$(。team_button)。 ,'事件','按钮','点击','团队选择按钮',{
'页面':'/ team /'
})
});
$(。calendar_month_prev)。on(click,function(){
ga('send','event','button','click','Calendar:Prev month',{$ b (),$ b $ page':'/ team /'
})
});
$(。calendar_month_next)。 ga('send','event','button','click','Calendar:Next month',{
'page':'/ team /'
})
} );
$(。calendar_day_selected)。on(click,function(){
ga('send','event','button','click','Calendar:Same (click),{
'page':'/ team /'
})
});
$(。calendar_day_active)。 ,function(){
ga('send','event','button','click','Calendar:Select day',{
'page':'/ team /'
})
});
});
在加载新页面时,当前页面上的挂起请求被取消 - 在这种情况下,分析跟踪像素请求。 'async'更多地指分析JavaScript代码的加载,然后是分析数据的处理。
使用ga.js,常见的方法是停止传播单击事件,发送事件,然后在链接之前延迟少量(150毫秒)。
通过analytics.js,而不是延迟,您可以使用 hitCallback
在分析数据存在之后运行代码已经送走了。
请参阅在Google Analytics(分析)文档中
I implemented analytics.js (new version) in my ASPX webapplication.I got pageview working just fine, but events is very often not being send.
In my example, I tried pushing 3 different buttons, but only one of them fired the event.I added an alert-box to each event, to verify that it actually is fired, and these all show.
This is my js, placed just before the </head>
(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-XXXXXXXX-1', {
'cookieDomain': 'none'
});
ga('send', 'pageview', {
'page': '/team/main',
'title': 'Logged in'
});
$(document).ready(function() {
$(".team_button").on("click", function() {
ga('send', 'event', 'button', 'click', 'Team select button', {
'page': '/team/'
})
});
$(".calendar_month_prev").on("click", function() {
ga('send', 'event', 'button', 'click', 'Calendar: Prev month', {
'page': '/team/'
})
});
$(".calendar_month_next").on("click", function() {
ga('send', 'event', 'button', 'click', 'Calendar: Next month', {
'page': '/team/'
})
});
$(".calendar_day_selected").on("click", function() {
ga('send', 'event', 'button', 'click', 'Calendar: Same day reload', {
'page': '/team/'
})
});
$(".calendar_day_active").on("click", function() {
ga('send', 'event', 'button', 'click', 'Calendar: Select day', {
'page': '/team/'
})
});
});
When a new page is being loaded, pending requests on the current page are canceled -- in this case the analytics tracking pixel request. 'async' is referring more to the loading of the analytics javascript code then the processing of analytics data.
With ga.js, a common approach is to stop propagation of the click event, send the event, and then delay for a small amount (150ms) before following the link.
With analytics.js, instead of a delay, you can use hitCallback
to run code after the analytics data has been sent.See Setting the Hit Callback in the Google Analytics docs
这篇关于analytics.js事件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!