css - 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?
解决方案
如果您正在寻找父锚标签以不将事件捕获到图像标签,您可以调用event.stopPropagation()
它。
默认情况下,事件确实会通过捕获阶段到达最嵌套的元素。这是 API 的链接: https ://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation
推荐阅读
- laravel - 如何在 Vue.js 中对我的数据的输入应用用户过滤器?
- sql - 在存储过程中将日期强制为每月的第一天
- node.js - Try-catch 没有捕捉到 .then().catch() 抛出的错误
- aws-lambda - Cognito Lambda 授权方如何根据用户限制对 Lambda 的访问
- android - 如何查看芯片组中的所有芯片?
- python - 如何在 Spark 中使用 Python 查找 DataFrame 中的分区数以及如何在 Spark 中使用 Python 在 DataFrame 中创建分区
- pine-script - Pine 脚本:2 种不同的背景颜色
- laravel - CalDAV 的 Sabre 集成
- javascript - D3 在更新之前不删除 rect
- javascript - 无法在 node.js 中导入模块