开发者

Possible to track a div click with google analytics

开发者 https://www.devze.com 2023-04-10 16:58 出处:网络
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 the

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?


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.


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'

0

精彩评论

暂无评论...
验证码 换一张
取 消