[英]Google Tag Manager custom javascript failed in IE 8
I am a beginner to use GTM, and I want to track how many users click on the two links. 我是使用GTM的初学者,我想跟踪有多少用户单击这两个链接。
<ul>
<li><a href="XXX.XXX.XXX" title="ABC"><span>YYY</span></a></li>
<li><a href="XXX.XXX.XXX">YYY</a></li>
</ul>
The only different between the two link is one has "title" and is surrounded by "span" tag. 这两个链接之间唯一的区别是一个链接带有“标题”,并被“ span”标签包围。
I try to use custom javascript to return different value. 我尝试使用自定义javascript返回不同的值。
function(){
var ele = {{element}}; //this should be the "a" tag
var ref = ele.getAttribute("href");
var tit = ele.getAttribute("title");
var inner = ele.innerHTML.toString();
if({{user_if_mpf}} == true && (tit !== null)){
var str = ele.childNodes[0].innerHTML + " (From First line)";
return str;
}
else if({{user_if_mpf}} == true){
return ele.innerHTML + " (From Second line)";
}
}
This works fine in Chrome, but when I test it on IE8, when I click the first line, it returns YYY (From Second line) 这在Chrome中工作正常,但是当我在IE8上进行测试时,当我单击第一行时,它返回YYY(来自第二行)
Can someone help me to solve this problem. 有人可以帮我解决这个问题。 Thank you.
谢谢。
If you can add a class to your anchor tags, you can fire the tags using the Link Click event listener tag. 如果您可以将一个类添加到定位标记,则可以使用“链接点击”事件侦听器标记触发这些标记。
For example, add gtm_phone to anchor tag: 例如,将gtm_phone添加到锚标记:
<ul>
<li><a href="XXX.XXX.XXX" title="ABC" class="gtm_phone"><span>YYY</span></a></li>
<li><a href="XXX.XXX.XXX" class="gtm_phone">YYY</a></li>
</ul>
Then, create an event within GTM: 然后,在GTM中创建一个事件:
The {{element - text}}
macro is just a Auto-Event Variable > Element Text: {{element - text}}
宏只是一个自动事件变量>元素文本:
Finally, add your rule: 最后,添加您的规则:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.