可以使用谷歌分析跟踪 div 点击

发布于 2024-12-07 23:35:57 字数 425 浏览 2 评论 0原文

我在网站的 div 中播放视频。该视频需要点击才能播放。我想知道是否可以对父 div 应用一些分析事件跟踪,以便在 div 内单击时进行跟踪。

我知道您可以将 onClick 事件与分析一起使用,但我不太确定它是否可以应用于 div 而不是像这样的出站链接:

<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'vid 1']);">Click Here</a>

有人做过这样的事情吗?我意识到这有一些缺点(用户反复单击播放/暂停)等。

谢谢。

*编辑 - 我可能应该提到我不清楚如何将 div 变成可点击事件。

假设我的 div 是 .我需要做什么才能使整个 div 成为 onClick 事件?

I have a video playing within a div on a site. The video requires a click to play. I'm wondering if it would be possible to apply some analytic event tracking tO the parent div that tracks anytime there is a click within the div.

I know you can use an onClick event with analytics, but am not quite sure if it could be applied to a div rather than, say, an outbound link like this:

<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'vid 1']);">Click Here</a>

Has anybody body ever done something like this? I realize there are some downfalls to this (user repeatedly clicking play/pause) etc.

Thanks.

*Edit - I should probably have mentioned that I am unclear of how I would turn the div into a clickable event.

Say my div is . What would I need to do to make the whole div into an onClick event?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南…巷孤猫 2024-12-14 23:35:57

您当然可以执行以下操作:

<div onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'vid 1'])" 
    style="cursor: pointer;"> Your content here </div>

但是:当您将 Flash 放入其中时,点击传播可能会出现问题,具体取决于您的浏览器。最好尝试一下这个库:

Google Analytics Tracking适用于 Adob​​e Flash 库。

You can certainly do something like this:

<div onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'vid 1'])" 
    style="cursor: pointer;"> Your content here </div>

However: when you place flash inside, there could be issues with click propagation, depending on your browser. It is better to give this library a try:

Google Analytics Tracking for Adobe Flash Library.

人生戏 2024-12-14 23:35:57

或者,如果您使用的是 Google 较新的 Analytics.js 跟踪代码:

<div  onclick="ga('send', 'event', 'link', 'click', 'My Wonderful Div');" style="cursor: pointer;"> Your content here </div>

要进行测试,假设您有一个 Google Analytics 帐户并且 Analytics.js 嵌入在您的页面中,这将显示在您的 Google Analytics 仪表板中的“标准报告”> 下。 '实时'> “事件”...事件操作:单击,事件标签:My Wonderful Div

或更永久地位于

“行为”> 下“活动”

Or if you are using Google's newer analytics.js tracking code:

<div  onclick="ga('send', 'event', 'link', 'click', 'My Wonderful Div');" style="cursor: pointer;"> Your content here </div>

To test, provided you have a google analytics account and the analytics.js is embedded in your page, this will show up in your Google Analytics Dashboard under 'Standard Reports' > 'Real-Time' > 'Events'... Event Action: click, Event Label: My Wonderful Div

or more permanently under

'Behavior' > 'Events'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文