我使用Google跟踪代码管理器在我的网站上触发代码。变量“undefined”在任何版本的Internet Explorer的自定义代码中 [英] I use Google Tag Manager to fire tags on my website.Variables "undefined" in custom code for any version of Internet Explorer

查看:158
本文介绍了我使用Google跟踪代码管理器在我的网站上触发代码。变量“undefined”在任何版本的Internet Explorer的自定义代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google跟踪代码管理器在我的网站上触发代码。除了Internet Explorer(任何版本)之外,所有浏览器中的标记都正确触发。发生的事情是在使用Internet Explorer时,我的自定义Javascript中没有填充GTM宏。但是,如果我刷新页面,则会填充它们。基于此,我假设问题是标签在DOM完全加载之前触发。我在规则中使用 {{event}} equals gtm.dom 。我还尝试在规则中使用 {{event}} equals gtm.load ,但这也不起作用。这是我如何定义GTM宏,规则和标记。更奇怪的是,当我在GTM中以预览模式测试标签时,它每次都有效,没有问题。但是一旦我发布它,除非我刷新页面,否则它不再有效。我做错了什么?

I am using Google Tag Manager to fire tags on my website. The tags are firing correctly in all browsers except Internet Explorer (any version). What is happening is that the GTM macro is not getting populated in my custom Javascript when using Internet Explorer. However, if I refresh the page they get populated. Based on this I assume the issue is that the tag is firing before the DOM is completely loaded. I am using {{event}} equals gtm.dom in the "Rule". I have also tried to use {{event}} equals gtm.load in the "Rule", but that doesn't work either. Here is how I have the GTM Macro, Rule and Tag defined. The thing that is even more odd is that when I test the tag in "Preview" mode in GTM, it works every time, no issues. But once I publish it, it no longer works unless I refresh the page. What am I doing wrong?

宏名称: PDP-ProdID

宏类型:自定义JavaScript

自定义Javascript:

Macro Name: PDP-ProdID
Macro Type: Custom JavaScript
Custom Javascript:

function () {
    var pdp_prodid = document.getElementsByName('sku')[0].value;
    return pdp_prodid;
}

规则名称: FullSite_Product_Detail_Page - 页脚

条件:

{{url}}包含gohastings.com/product /

{{event}}等于gtm.dom

Rule Name: FullSite_Product_Detail_Page - Footer
Conditions:
{{url}} contains gohastings.com/product/
{{event}} equals gtm.dom

标记名称: Fetchback_Smart_Pixel -Remarketing-PDP

标记类型:自定义HTML标记

HTML:

< iframe src ='{{protocol}}:// pixel.fetchback.com/serve/fb/pdj?cat =& name = landing& sid = 6288& browse_products = {{PDP-ProdID}} 'scrolling ='no'width ='1'height ='1'marginheight ='0'marginwidth ='0'frameborder ='0'>< / iframe>

Tag Name: Fetchback_Smart_Pixel-Remarketing-PDP
Tag Type: Custom HTML Tag
HTML:
<iframe src='{{protocol}}://pixel.fetchback.com/serve/fb/pdj?cat=&name=landing&sid=6288&browse_products={{PDP-ProdID}}' scrolling='no' width='1' height='1' marginheight='0' marginwidth='0' frameborder='0'></iframe>

触发规则:FullSite_Product_Detail_Page - 页脚

Firing Rules: FullSite_Product_Detail_Page - Footer

网站: qa.gohastings .com(但是,我的QA网站上有一些问题,因此请使用此链接,因为它会直接转到产品详细信息页面。

http://qa.gohastings.com/product /BOOK/Fifty-Shades-of-Grey-Bk-1/sku/287​​464232.uts (产品详情页面)

Site: qa.gohastings.com (However, I have some issues on my QA site, so use this link as it will take you directly to a product detail page.
http://qa.gohastings.com/product/BOOK/Fifty-Shades-of-Grey-Bk-1/sku/287464232.uts (product detail page)

首页加载时标记的结果

< iframe width =1height =1src =http://pixel.fetchback.com / serve / fb / pdj?cat =& name = landing& sid = 6288& browse_products = undefinedframeBorder =0marginWidth =0marginHeight =0scrolling =no>

页面重新加载后的标记结果

< iframe width =1 height =1src =http://pixel.fetchback.com/serve/fb/pdj?cat=&name=landing&sid=6288&browse_products=287464232frameBorder =0marginWidth =0 marginHeight =0scrolling =no>

推荐答案

我遇到了类似的问题使用Google Analytics跟踪电子商务交易。在设置交易详情之前, gtm.dom 事件将会触发。我最终做的是在设置数据层而不是使用 gtm.dom 事件后触发自定义事件。

I had a similar problem tracking e-commerce transactions with Google Analytics. The gtm.dom event would fire before I set up the transaction details. What I ended up doing was trigger a custom event after I set up the data layer instead of using the gtm.dom event.

您可以将规则条件更改为 {{event}}等于myPageLoad ,然后在页面加载后您知道所有内容已准备就绪(使用 $(document).ready(...)在jQuery中,例如),调用:

You can change the rule condition to {{event}} equals myPageLoad, then after the page loads and you know everything is ready that you need (using $(document).ready(...) in jQuery, for example), call:

dataLayer.push({ event: 'myPageLoad' });

这篇关于我使用Google跟踪代码管理器在我的网站上触发代码。变量“undefined”在任何版本的Internet Explorer的自定义代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆