gpt4 book ai didi

javascript - 弹出窗口不适用于 UA 和 GTM

转载 作者:行者123 更新时间:2023-12-03 11:27:03 24 4
gpt4 key购买 nike

我们最近将网站更新为 Universal Analytics 和 GTM。我们有一个弹出窗口,会在退出页面时出现,并根据选择发送事件。现在,如果我们尝试标记事件,弹出窗口将不起作用。如果我们注释掉弹出窗口的事件,但我们没有对其进行任何跟踪。下面是脚本,它最初是如何工作的,然后是经过更改的脚本,现在使弹出窗口无法工作。

在脚本有效之前:

<script>
var goodExit = false;
var through_onbeforeunload = false;
var count_onbeforeunload = 1;

function unloadStatus() {
if(through_onbeforeunload) {
through_onbeforeunload = false;
_gaq.push(['_trackEvent', 'onbeforeunload', 'returned from popup']);
}
}

$(document).ready(function(){

setInterval("unloadStatus()", 500);

window.onbeforeunload = function() {
through_onbeforeunload = true;
_gaq.push(['_trackEvent', 'onbeforeunload', 'saw popup', '', count_onbeforeunload++]);

if(!goodExit) {
var my_string = '--------------------------------------------\n';
my_string += 'YOUR APPLICATION HAS NOT YET BEEN SUBMITTED!\n';
my_string += '--------------------------------------------\n';
my_string += 'You are minutes away from completing your application.\n';
my_string += 'If you exit this page your information will not be saved.\n';
my_string += '\n';
my_string += 'CLICK THE STAY ON THIS PAGE BUTTON\n';
my_string += 'TO CONTINUE THE APPLICATION PROCESS.\n';
my_string += '--------------------------------------------';
return my_string;
}
}

window.onunload = function() {
if(through_onbeforeunload) {
_gaq.push(['_trackEvent', 'onbeforeunload', 'left through popup']);
}
}

$('.js-app-submit').click(function() {
goodExit = true;
window.onbeforeunload = null;
});
});
</script>

下面,当我们实现 UA 和 GTM 时,我们将 gaq.push 更改为 ga('send','event...,然后一切都停止了。

<script>
var goodExit = false;
var through_onbeforeunload = false;
var count_onbeforeunload = 1;

function unloadStatus() {
if(through_onbeforeunload) {
through_onbeforeunload = false;
ga(['send', 'event', 'onbeforeunload', 'returned from popup']);
}
}

$(document).ready(function(){

setInterval("unloadStatus()", 500);

window.onbeforeunload = function() {
through_onbeforeunload = true;
ga(['send', 'event', 'onbeforeunload', 'saw popup', count_onbeforeunload++]);

if(!goodExit) {
var my_string = '--------------------------------------------\n';
my_string += 'YOUR APPLICATION HAS NOT YET BEEN SUBMITTED!\n';
my_string += '--------------------------------------------\n';
my_string += 'You are minutes away from completing your application.\n';
my_string += 'If you exit this page your information will not be saved.\n';
my_string += '\n';
my_string += 'CLICK THE STAY ON THIS PAGE BUTTON\n';
my_string += 'TO CONTINUE THE APPLICATION PROCESS.\n';
my_string += '--------------------------------------------';
return my_string;
}
}

window.onunload = function() {
if(through_onbeforeunload) {
ga(['send', 'event', 'onbeforeunload', 'left through popup']);
}
}

$('.js-app-submit').click(function() {
goodExit = true;
window.onbeforeunload = null;
});
});
</script>

如果我们注释掉 Google 标签,弹出窗口会起作用,但不会跟踪任何内容。不幸的是,它存在于页面上,分析位于 GTM 中,但我们通过直接在网站上添加分析进行测试,但它仍然不起作用。

任何帮助/建议,我们将不胜感激。

最佳答案

您用于发送事件的语法不正确。不应有任何方括号,因此例如对于 unloadStatus 函数中的第一个事件,它应该是:

ga('send', 'event', 'onbeforeunload', 'returned from popup'); 

其余部分相同。

关于javascript - 弹出窗口不适用于 UA 和 GTM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26875098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com