无法在jquery中触发GA事件
此代码中的跟踪将不起作用 但如果我在GA跟踪事件代码下面添加一个警报代码。跟踪工作正常。就像下面的代码一样无法在jquery中触发GA事件,jquery,google-analytics,Jquery,Google Analytics,此代码中的跟踪将不起作用 但如果我在GA跟踪事件代码下面添加一个警报代码。跟踪工作正常。就像下面的代码一样 dp("a.download-2").click(function(){ var e=dp(this).attr("id"); var t=dp(this).attr("name"); var n=dp(this).attr("rel"); var r=navigator.platform; var i=r.substring(0,3);
dp("a.download-2").click(function(){
var e=dp(this).attr("id");
var t=dp(this).attr("name");
var n=dp(this).attr("rel");
var r=navigator.platform;
var i=r.substring(0,3);
if(i=="Win"){
jQuery("#fb_pixel").addClass("fb_conversion");
_gaq.push(["_trackEvent",n,"download",t]);
window.location.href="http://"+e+".rackcdn.com/abc123.exe";
}else if(i=="Mac"){
jQuery("#fb_pixel").addClass("fb_conversion");
_gaq.push(["_trackEvent",n,"download",t]);
window.location.href="http://"+e+".rackcdn.com/abc123.dmg";
}else{
alert("The software only supports Windows and Mac operating system.");return false}});
我不知道为什么这个警报会影响你。当然不应该
感谢您的高级支持。行
window.location.href=“http://“+e+”.rackcdn.com/abc123.exe”代码>强制浏览器在GA代码有机会工作之前重定向
因此,在编写GA代码后,您可以尝试在代码中使用setTimeout
。这样可以确保GA代码在重定向页面之前运行
警报之所以有效,是因为它会暂停执行,直到您单击“确定”,这对于任何javascript来说都是足够的时间在它之前工作。看起来重定向是在GA有机会发送请求之前触发的。。。因此,尝试使用类似于setTimeout(function(){window.location.href=“http://“+e+”.rackcdn.com/abc123.dmg”;},50)
它的工作很好!谢谢你,阿伦!就像阿伦建议的那样。setTimeout(function(){window.location.href=“http://“+e+”。rackcdn.com/abc123.dmg";}, 50);它现在起作用了。对。他比我快:)
dp("a.download-2").click(function(){
var e=dp(this).attr("id");
var t=dp(this).attr("name");
var n=dp(this).attr("rel");
var r=navigator.platform;
var i=r.substring(0,3);
if(i=="Win"){
jQuery("#fb_pixel").addClass("fb_conversion");
_gaq.push(["_trackEvent",n,"download",t]);
alert(n+" "+t);
window.location.href="http://"+e+".rackcdn.com/abc123.exe";
}else if(i=="Mac"){
jQuery("#fb_pixel").addClass("fb_conversion");
_gaq.push(["_trackEvent",n,"download",t]);
alert(n+" "+t);
window.location.href="http://"+e+".rackcdn.com/abc123.dmg";
}else{
alert("The software only supports Windows and Mac operating system.");return false}});