简体   繁体   English

Google标记管理器-是否可以通过GTM标记插入dataLayer?

[英]Google tag manager - is it possible to push into dataLayer via GTM tag?

For the past few days I have been messing with the basics of tag management and "disassembling" the GTM code, trying to figure out how this thing really works. 在过去的几天里,我一直在迷惑标签管理和“反汇编” GTM代码的基础知识,试图弄清这东西是如何工作的。 There is one thing I cannot figure out: 我无法弄清一件事:

Scenario 1. 场景1。

  • I hardcode dataLayer into the page html 我将dataLayer硬编码到页面html中
  • I append JS code to page elements that I wish to "tag" and push their events into the DL (pdf download, onClick=....) 我将JS代码附加到希望“标记”的页面元素上,并将其事件推送到DL中(pdf下载,onClick = ....)
  • in GTM interface I create a tag which handles this onClick event and retrieves value pushed into the DL 在GTM界面中,我创建了一个标签来处理此onClick事件并检索推送到DL中的值

It works like this: 它是这样的:

  • When pdf download is clicked, object is pushed into the DL 单击pdf下载后,对象被推入DL
  • tag fires and retrieves the event value 标签触发并检索事件值
  • sends it to the GA servers -> all clear here 将其发送到GA服务器->在此处全部清除

Scenario 2. 场景2。

  • I DON'T create dataLayer on the page; 我不会在页面上创建dataLayer; GTM code snippet creates one upon loading the page in the browser GTM代码段在将页面加载到浏览器后创建一个
  • HERE comes the missing link: since I haven't coded DL into the page, I probably haven't appended the .push() method to the appropriate DOM elements as well 这里缺少链接:由于我没有在页面中编码DL,所以我可能也没有将.push()方法附加到适当的DOM元素上

Question: 题:

Can this somehow be done via GTM interface? 是否可以通过GTM接口完成此操作? If yes, this means that I can somehow "inject" extra JS code into my page code after the page has loaded in the browser? 如果是,这意味着在页面加载到浏览器后,我可以以某种方式“注入”额外的JS代码到我的页面代码中吗?

Cheers! 干杯!

EDIT (after more education): 编辑(经过更多的教育):

It seems that it is possible to do a lot. 似乎可以做很多事情。 GTM checks if there is a datalayer on the page and if it cannot find one, it creates it for you. GTM检查页面上是否有数据层,如果找不到,则为您创建一个数据层。 Uou then set up macros to push objects into this DL (events) and finally, you can have tags retrieve information from the DL and send it to the Google analytics. 然后,Uou设置宏以将对象推送到此DL(事件)中,最后,您可以让标签从DL检索信息并将其发送到Google Analytics(分析)。 Am I right? 我对吗?

You could create your own "DataLayer" by creating a dedicated tag declarating an array but this personal DataLayer could not be use in triggers. 您可以通过创建一个声明数组的专用标签来创建自己的“ DataLayer”, 但是此个人DataLayer不能在触发器中使用。

To cover that, you can use another tag with a test (if array contains X then function ...), but I could not see how that is better than your scenario 1. If you do that, be sure to use tag priorities so the first tag is triggerred first. 为了解决这个问题,您可以在测试中使用另一个标签(如果数组包含X,然后是函数...),但是我看不出它比场景1更好。如果这样做,请确保使用标签优先级,这样首先触发第一个标签。

You can use built in Universal Analytics Event tag to track .pdf downloads without dataLayer hard codding. 您可以使用内置的Universal Analytics Event标签来跟踪.pdf下载,而无需进行dataLayer硬编码。

If you want to fire tags after page has loaded you can use "event equals gtm.load" condition in firing trigger. 如果要在页面加载后触发代码,则可以在触发触发器中使用“等于gtm.load的事件”条件。 For example, you can use it to fire customer HTML tag with any kind of Javascript code. 例如,您可以使用它来触发带有任何类型的Javascript代码的客户HTML标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将表单提交推送到谷歌标签管理器 (gtm) 中的数据层 - How to push a form submission to the dataLayer in google tag manager (gtm) Google跟踪代码管理器dataLayer推送未存储对象 - Google Tag manager dataLayer push not storing object 访问 gtm.formsubmit 上的 Google 跟踪代码管理器 dataLayer 字段值 - Access Google Tag Manager dataLayer field values on gtm.formsubmit 尽管执行了DataLayer推送,但Google跟踪代码管理器代码未触发 - Google Tag Manager tag not triggered despite DataLayer push being executed 跟踪代码管理器无法识别Google跟踪代码管理器dataLayer - Google Tag Manager dataLayer unrecognized by Tag Manager Google代码管理器:是否可以通过GTM将CUSTOM HTML代码放入head标签? - Google tag manager: Is it possible to put CUSTOM HTML code in head tag via GTM? Google跟踪代码管理器dataLayer持久性 - Google Tag Manager dataLayer persistency 解析eCommerse数据以推送到Google Tag Manager的dataLayer - Parsing eCommerse data to push into dataLayer for Google Tag Manager Google跟踪代码管理器是否“订阅” dataLayer.push? 如果是,怎么办? - Does Google Tag Manager “subscribe” to dataLayer.push? If yes, how? Firefox 增强的隐私保护正在阻止数据层推送到谷歌标签管理器 - Firefox Enhanced Privacy Protection is blocking Datalayer push to Google Tag Manager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM