首页 > 解决方案 > Google Tag Manager link click image

问题描述

I'm using Google Tag Manager to send an event to Google Analytics when you click an <a> or a<button> tag, which works fine.

However I also have an <a> tag wrapping an <img> and the event is not firing because the element getting clicked is not the <a> tag, it's the <img> tag.

I've tried to move my .sau-btn to the <img> tag but this doe not work either. I've also tried to move my a tag to act as a hotspot on top of it.

<a href="#" @click="openSaleOfferModal(true, 'enterprise')" style="display:inline-block; border:1px solid red; background-color:green z-index:99; position:relative;"><v-img :src="require('@/assets/img/sales-banner-enterprise.jpg')" class="gtm-btn" data-gtm-category="Sales Offer" data-gtm-action="Test Link" data-gtm-label="Image Real Link One" alt="alt tag"></v-img></a>

How get I get my event to fire when you click anything inside of the class that it is holding?

Google Tag Manager

标签: cssgoogle-analyticsgoogle-tag-manager

解决方案


如果您正在寻找父锚标签以不将事件捕获到图像标签,您可以调用event.stopPropagation()它。

默认情况下,事件确实会通过捕获阶段到达最嵌套的元素。这是 API 的链接: https ://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation


推荐阅读