Archive for March, 2009

How to track clicks and events in Flash with Google Analytics

Monday, March 9th, 2009

Bookmark this Google page and keep it around for reference. Tracking click-throughs in Flash with Google Analytics turned out to be easier than I thought. Use the following ActionScript to make your visitors’ clicks in Flash register with Google Analytics.

on (release) {
getURL("javascript:pageTracker._trackPageview('/path/to/page.php');");
_root.gotoAndPlay(3); //your action here
}

Of course, it’s the pageTracker._trackPageview() JavaScript function that’s really doing the work, so I assume you can call this function from within Flash wherever you can use the getURL() ActionScript function.

I am building a landing page for an online coupon campaign, and am using this code to track the number of downloads of the PDF coupon to compare to pageviews.

EDIT: Here’s another great post with a bunch of examples of tracking click throughs in Flash. Careful though, these examples are for use with the older Urchin Google Analytics JavaScript snippet.