“点击类别"之间的差异和“点击元素"在Google跟踪代码管理器中 [英] Differences between "Click Classes" and "Click Element" in Google Tag Manager

查看:86
本文介绍了“点击类别"之间的差异和“点击元素"在Google跟踪代码管理器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解Google跟踪代码管理器中点击类"和点击元素"之间的区别.我不了解这些事件的预期用途,也不了解它们在包含"和"CSS选择器"方面的各自行为.

I don't really understand the differences between "Click classes" and "Click Element" in Google Tag Manager. I don't understand the expected use of these event and I don't understand their respective behavior regarding "contains" and "CSS selector".

假设我有class="buttons primary small".

工作原理:

Click Element -> Matches CSS selector -> .buttons.small 
Click Classes -> contains -> small 

什么不起作用

Click Element -> contains -> .buttons.small 
Click Classes -> Matches CSS selector -> small 

如果点击类"是对象上的类的数组",那么在进行此类操作时GTM的幕后"到底发生了什么?

if Click Classes is "an array of the classes on an object", What's really happen "under the hood" of GTM when doing this kind of manipulation ?

这并不是我有一个真正的问题,只是试图正确理解.

It's not that I have a real issues, just trying to understand properly.

推荐答案

Click类返回作为操作目标的HTML元素的class属性值.它始终是一个字符串,在您的示例中将返回"buttons primary small"(尽管不一定按此顺序).

Click Classes returns the value of the class attribute of the HTML element that was the target of the action. It is always a string, and in your example would return "buttons primary small" though not necessarily in that order.

Click元素返回作为操作目标的HTML元素.

Click Element returns the HTML element that was the target of the action.

包含"是GTM中用于字符串的匹配类型.这就是为什么它适用于Click类(返回字符串)而不是Click元素的原因.

"contains" is a match type in GTM that you use against strings. That's why it works with Click Classes (which returns a string) and not Click Element.

匹配CSS选择器"用于检查是否有任何给定的元素与给定的CSS选择器匹配.因此,必须对HTML元素执行匹配CSS选择器".这就是为什么它可以与Click元素一起使用,而不与Click类一起使用的原因.

"Matches CSS Selector" is a check whether any given element matches a given CSS selector. "Matches CSS Selector" must thus be done against an HTML element. That's why it works with Click Element and not Click Classes.

我认为,点击类是多余的,因为相对于点击类,最好还是对点击元素进行CSS选择器检查,而不是对点击类进行字符串匹配.这样更健壮,并且您也不必担心类名称在类属性值中按特定顺序排列.

In my opinion, Click Classes is redundant, since you're always better off doing a CSS selector check against Click Element rather than a string match against Click Classes. It's more robust that way, and you also don't need to worry about the class names being in a certain order in the class attribute value.

换句话说,更好:

点击元素匹配CSS选择器 .buttons.primary.small

Click Element matches CSS selector .buttons.primary.small

更差:

点击类包含主要小按钮

这篇关于“点击类别"之间的差异和“点击元素"在Google跟踪代码管理器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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