Google跟踪代码管理器无法跟踪图片和图标上的链接点击 [英] Google Tag Manager not tracking links clicks on images and icons

查看:60
本文介绍了Google跟踪代码管理器无法跟踪图片和图标上的链接点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google跟踪代码管理器中,我将其设置为跟踪对包含特定类的元素的点击所获得的一些数据,并在Google Analytics(分析)中记录了一个事件.对于文本链接来说,这似乎很好用,但是如果链接中还有用于图像,图标等的其他标签,我就会遇到问题.例如,以下代码会很好:

In Google Tag Manager, I set it up to track some data from clicks on elements that contain a certain class and record an event in Google Analytics. It seems to work just fine for text links, but I run into problems if there is another tag inside the link for an image, icon, etc. For example, the following would work fine:

<a href="link.html" class="track_this" data-tracking-info="my info">Click here</a>

但这不起作用:

<a href="link.html" class="track_this"  data-tracking-info="my info">
  <span class="icon click-here"></span>
</a>

如果您单击文本,则类似的操作将起作用,但如果您单击图标,则将无效:

And something like this will work if you click on the text, but not if you click on the icon:

<a href="link.html" class="track_this"  data-tracking-info="my info">
  <span class="icon click-here"></span> Click Here
</a>

我知道我可以将"track_this"类添加到图标的范围中,但是在更复杂的情况下它会变得非常混乱.想象一下,有一个带有图标的缩略图和位于其下方的一些文本都包裹在一个标签中.我必须在图像标签上放置该类和跟踪信息,图标的跨度,文本的div等.

I know that I could add the "track_this" class into the span for the icon, but it gets REALLY messy in more complicated scenarios. Like imagine having a thumbnail image with an icon and some text below it all wrapped into one a tag. I'd have to put that class and the tracking info on the image tag, the span for the icon, the div for the text, etc.

是否有更好的方法可以做到这一点?谢谢!

Is there a better way to do this? Thanks!

推荐答案

如果我能看到您的GTM设置方式,我可以对此进行更明确的说明,但我的猜测是您使用的是所有元素"触发器来捕获这些链接点击,并过滤点击类别"或点击元素".问题是,当链接标记(<a></a>)包含另一个元素,例如<span>时,即使触发了链接打开,GTM记录为接收点击的元素也是跨度,而不是链接.

I could speak more definitively on this if I could see how your GTM was setup, but my guess is that you are using an "All Elements" trigger to capture these link clicks, and filtering on "Click Classes" or "Click Element". The issue with this is that, when the link tag (<a></a>) contains another element, such as a <span>, even though that triggers your link to open, the element that GTM records as receiving the click is the span, not the link.

如果要解决此问题,有两个选项,其中两个都应该起作用.

If you want to fix this, there are two options, either of which should work.

首先是切换为使用点击-只是链接"触发类型,并在类"track_this"上进行过滤.对于此触发器,GTM允许单击事件冒泡",直到它们击中链接元素为止,然后针对该链接而不是被单击的元素测试触发器.只需使用此触发器类型就可以对您的所有三个样本起作用.

The first is to switch to using a "Click - Just Links" trigger type, and filter on the class "track_this". For this trigger, GTM lets click events "bubble" up until they hit a link element, and then it tests your trigger against that link, instead of the element that was clicked on. Simply using this trigger type should work for all three of your samples.

另一个选择是对点击-所有元素"触发器使用更高级的过滤器.如果您修改触发器,使其触发某些点击",然后使条件点击元素与CSS选择器匹配:"

The other option is to use a more advanced filter with the "Click - All Elements" trigger. If you modify the trigger so it fires on "Some Clicks", and then make the condition that "Click Element matches CSS selector:"

.track_this, .track_this *

然后,它将注册对具有track_this类的任何元素的单击,以及对 这些元素中的任何元素单击的.

then it will register a click on any element that has the track_this class, as well as a click on any element inside those elements.

这篇关于Google跟踪代码管理器无法跟踪图片和图标上的链接点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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