弹出窗口不适用于UA和GTM
popup not working with UA and GTM
我们最近将我们的网站更新为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("结束"、"事件……然后一切都停止了。
<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>
如果我们评论掉谷歌标签,弹出窗口会起作用,但不会被跟踪。不幸的是,这在页面上存在,分析在GTM中,但我们通过直接在网站上添加分析进行了测试,但它仍然不起作用。
如有任何帮助/建议,将不胜感激。
用于发送事件的语法不正确。不应该有任何方括号,所以例如,对于unloadStatus函数中的第一个事件,它应该是:
ga('send', 'event', 'onbeforeunload', 'returned from popup');
其余部分也是如此。
相关文章:
- GTM每隔5秒在页面上查找文本
- 什么's特征检测、特征推断和使用UA字符串之间的区别
- 我们是否可以访问 UA 应该为 HTML5 表单 API 维护的无效控件列表
- Adobe DTM - using GTM dataLayer
- X-UA-Compatible 在 ShowModalDialog 启动页面时被忽略
- Google 跟踪代码管理器 (GTM) 新事件侦听器代码出现问题
- _googWcmGet回调无法通过具有动态电话号码的GTM工作
- 使用 GTM 触发动态内容
- 将数据添加到 GTM 中的自定义数据层变量
- Firefox window.controllers已被弃用.请勿将其用于 UA 检测
- ua 和 mw 在 JavaScript 中的含义
- 将值推送到 GTM 数据层的语法
- 使用元标记“X-UA-兼容”
- 如何在谷歌跟踪代码管理器中触发两个不同的基于gtm.timer的事件
- 在涡轮链接下的 GTM(谷歌跟踪代码管理器)容器中触发代码
- 弹出窗口不适用于UA和GTM
- GTM数据层事件回调函数
- 使用GTM在SquareSpace中跟踪表单提交
- GTM触发器基于javascript函数
- 通过GTM宏的UA: ga. getall ()[0].get('clientId') - ga未定义