Parent Class in Google Tag Manager

aphextwig

I found this Google Tag Manager macro script (http://viget.com/advance/gtm#elementclass) to identify if an element's parent has a specific class value.

function crawlByClassName () {
var el = {{element}};

while (el && el !== document.body && el.className !== 'INSERT CLASS NAME') {
    el = el.parentElement;
}

return el.className === 'INSERT CLASS NAME';
}

Is there a way to modify it to record the value and then use a rule to specify the name? Or is there a different way to achieve this?

aphextwig

Thanks @kevintechie. Your method might work.

I was able to find another way here https://plus.google.com/100582165749296472339/posts/fa6iKeuF6ig

I can use this as the macro:

function() {
return {{element}}.parentElement.className;
}

Then specify the class name in the rule. This means there's only one macro and not one for every class.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

trackingId and clientId with Google tag manager

来自分类Dev

常规广告系列评估Google Tag Manager for Apps

来自分类Dev

找不到Google Tag Manager容器iOS Swift

来自分类Dev

如何从 Java 代码触发 Google Tag Manager 脚本

来自分类Dev

Google Tag Manager Enhanced Ecommerce 的文档有误吗?

来自分类Dev

Google Tag manager:获取完成进度所需的时间(分钟/秒)

来自分类Dev

Google Tag Manager (GTM) - 如何查明是否设置了 anonyizeIp (aip)

来自分类Dev

Google Tag Manager 在我的页面底部创建空按钮

来自分类Dev

Google tag manager: Is it possible to put CUSTOM HTML code in head tag via GTM?

来自分类Dev

如何使用Google Analytics(分析)配置Android Google Tag Manager v4

来自分类Dev

如何在本地地址上使用Google Analytics(分析)和Google Tag Manager 2?

来自分类Dev

如何在 Google Tag Manager 中使用 Google Analytics 的自定义维度和指标?

来自分类Dev

iOS Google Tag Manager购买事件发送0(零)作为数量参数

来自分类Dev

iOS Google Tag Manager购买事件发送0(零)作为数量参数

来自分类Dev

Google Tag Manager 和 Oracle APEX:跟踪关闭对话框

来自分类Dev

Google Tag Manager - Python - 创建自定义事件触发器

来自分类Dev

将 amp-form 事件连接到 Google Tag Manager Ads-conversion 标签

来自分类Dev

Duplicate id, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment

来自分类Dev

tag.class和tag .class有什么区别?

来自分类Dev

Get child class from parent

来自分类Dev

Adobe Dynamic Tag Manager(DTM)-回滚到以前的版本

来自分类Dev

Google Deployment Manager从父目录导入文件

来自分类Dev

您如何调试Google Deployment Manager模板?

来自分类Dev

通过Google Cloud Deployment Manager创建的Google数据流

来自分类Dev

Google Cloud Build + Google Secret Manager替代问题

来自分类Dev

get parent element by class using jquery

来自分类Dev

jQuery - Remove prop if parent has class

来自分类Dev

CSS:Tag.class和.class标签之间的区别

来自分类Dev

使用Google Publisher Tag注册事件

Related 相关文章

  1. 1

    trackingId and clientId with Google tag manager

  2. 2

    常规广告系列评估Google Tag Manager for Apps

  3. 3

    找不到Google Tag Manager容器iOS Swift

  4. 4

    如何从 Java 代码触发 Google Tag Manager 脚本

  5. 5

    Google Tag Manager Enhanced Ecommerce 的文档有误吗?

  6. 6

    Google Tag manager:获取完成进度所需的时间(分钟/秒)

  7. 7

    Google Tag Manager (GTM) - 如何查明是否设置了 anonyizeIp (aip)

  8. 8

    Google Tag Manager 在我的页面底部创建空按钮

  9. 9

    Google tag manager: Is it possible to put CUSTOM HTML code in head tag via GTM?

  10. 10

    如何使用Google Analytics(分析)配置Android Google Tag Manager v4

  11. 11

    如何在本地地址上使用Google Analytics(分析)和Google Tag Manager 2?

  12. 12

    如何在 Google Tag Manager 中使用 Google Analytics 的自定义维度和指标?

  13. 13

    iOS Google Tag Manager购买事件发送0(零)作为数量参数

  14. 14

    iOS Google Tag Manager购买事件发送0(零)作为数量参数

  15. 15

    Google Tag Manager 和 Oracle APEX:跟踪关闭对话框

  16. 16

    Google Tag Manager - Python - 创建自定义事件触发器

  17. 17

    将 amp-form 事件连接到 Google Tag Manager Ads-conversion 标签

  18. 18

    Duplicate id, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment

  19. 19

    tag.class和tag .class有什么区别?

  20. 20

    Get child class from parent

  21. 21

    Adobe Dynamic Tag Manager(DTM)-回滚到以前的版本

  22. 22

    Google Deployment Manager从父目录导入文件

  23. 23

    您如何调试Google Deployment Manager模板?

  24. 24

    通过Google Cloud Deployment Manager创建的Google数据流

  25. 25

    Google Cloud Build + Google Secret Manager替代问题

  26. 26

    get parent element by class using jquery

  27. 27

    jQuery - Remove prop if parent has class

  28. 28

    CSS:Tag.class和.class标签之间的区别

  29. 29

    使用Google Publisher Tag注册事件

热门标签

归档