views:

15

answers:

1

A client has a site where video content is populated by AJAX from a video CDN. Each link is built like so:

<a class="thumb-link" href="/?video='.$video->id.'" onclick="show_video('.$video->id.', \''.$section.'\'); return false;"><img src="'.$thumb.'" width="100" height="65" alt="" align="left" /></a>

But they report that analytics is not tracking the href, since the onclick is telling a Flash player to load the content via javascript instead of go to a page and load the video.

What can I do (without going to a physical page) to track this click as if they clicked through to a page?

Can I add to the onclick and do something like:

http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview

Add to the anchor: onclick="trackVideo();"

Then, with javascript:

function trackVideo() {
    path = $(this).attr("href");
    var pageTracker = _gat._getTracker("UA-XXXXX-XX");
    pageTracker._trackPageview(path);
}

I am not too familiar with Analytics, so if someone could get me in the right direction that would be great.

+1  A: 

Your example is correct. That would do exactly what you want :)

WoLpH
I remember reading somewhere where attr("href") might not work as expected in IE, any truth to that?
Kevin
There are no issues that I know of. But if you want to be absolutely sure, use this instead: `onclick="trackVideo(this.href);"`
WoLpH