i have a slider which the link code looks like this:
<a href="#" gtm-class="item-1"><img></a>
I want to pass the click custom attribute value to a variable in gtm.
This using custom js doesent work:
function () {
var el = {{Click Element}}, gtmDataEvent = el.getAttribute('gtm-class');
return gtmDataEvent;
}
please help
答案 0 :(得分:0)
您的HTML看起来不正确。什么是<img>
?那是图片标签吗?使用真实代码,当您单击它时,您的单击元素可能引用图像,而不是锚点。你必须检查并测试它。如果是这样,那么你需要做类似的事情:
function () {
var el = {{Click Element}}, gtmDataEvent = el.closest('a').getAttribute('gtm-class');
return gtmDataEvent;
}