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?
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] 删除。
我来说两句