How To Track Events in Flash Movies using WebTrends

If your website contains Flash movies that link offsite or to microsites, you may wish to register the offsite link using WebTrends. This article provides an introduction. It assumes a little knowledge of ActionScript, Javascript as well as WebTrends.

This example uses a intermediary javascript function that sits between the Flash movies and the WebTrends code.

Benefits

  • It’s much easier to debug if the WebTrends javascript is not called within the compiled Flash movie
  • The WebTrends tracking can be changed later without recompiling the Flash movie or even speaking to your Flash developer

Drawbacks

  • Javascript must be enabled to trigger the link to the target web page
  • Both Flash and Javascript will be required to navigate your website

This is bad from an accessibility point of view, but I won’t discuss that here.

ActionScript for Flash buttons

Edit your Flash movies so that the button that links to your external website or microsite has an ActionScript event handler which will trigger a call to Javascript.

Older ActionScript versions

on (release)
{
	getURL("javascript:myFlashEvent('Open Days','http://www.nottingham.ac.uk/opendays');"); 
}

ActionScript 3+

The getURL function was removed in ActionScript 3, so a slightly more complex example is required

if (ExternalInterface.available)
{
	try
	{
		ExternalInterface.call(
			'myFlashEvent',                        // function name
			'Open Days',                           // function parameter 1
			'http://www.nottingham.ac.uk/opendays' // function parameter 2
		);
	}
	catch (error:Error)
	{
		// Error handling here
	}
	catch (error:SecurityError)
	{
		// Error handling here
	}
}

The ActionScript calls the Javascript intermediary function myFlashEvent, which in turn registers the event with WebTrends and then loads the new web page.

Javascript

function myFlashEvent(eventDescription, eventValue){

	// Register Event with WebTrends		
	dcsMultiTrack(
		'DCS.dcsuri', eventValue,                  // name/value pair for URL
		'WT.ti', 'FlashEvent:' + eventDescription  // name/value pair for page title
	);
	
	// Go to URL
	document.location.href = eventValue;
}

This function will track the event as a visit to a URI using the DCS.dcsuri parameter. The page title for the URI will be set to e.g. ‘FlashEvent:My Page Title’ using the WT.ti parameter.

Results

The click event is showing up nicely in WebTrends as FlashEvent:Open Days, see the screenshot below

Screenshot of WebTrends Console

Example code

A working example of this code can be found here.

Sorry, I don’t have access to the .fla file, so that is not included.

Adapting the Javascript for Google Analytics

The myFlashEvent function can easily be adapted to work with Google Analytics instead:

function myFlashEvent(eventDescription, eventValue){
	
	// Register event 	
	pageTracker._trackEvent(
		'Flash', 'Link', 
		eventDescription, eventValue
	);
	
	// Go to URL
	document.location.href = eventValue;
}

Reference

6 comments on “How To Track Events in Flash Movies using WebTrends

  1. Pingback: aknecht
  2. Pingback: webtrends hacks
  3. Media says:

    If I were to place the same Flash movie on two different locations and would like to track these two Flash movies separately, how would I do this? Do I need to create two separate instances of the Flash movie and have two separate function parameters for the movies?

    Appreciate your help.

    1. David says:

      Media: You could add the page location to the event tracking
      e.g. for WebTrends:

      function myFlashEvent(eventDescription, eventValue){
      
      	// Get the page location
      	var pageLocation = location.href.substr( (location.protocol + '://' +location.host).length - 1);
      
      	// Register Event with WebTrends
      	dcsMultiTrack(
      		'DCS.dcsuri', eventValue,                  // name/value pair for URL
      		'WT.ti', 'FlashEvent:' + pageLocation + '/' + eventDescription  // name/value pair for page title
      	);
      
      	// Go to URL
      	document.location.href = eventValue;
      }

      …or for Google Analytics:

      function myFlashEvent(eventDescription, eventValue){
      
      	// Get the page location
      	var pageLocation = location.href.substr( (location.protocol + '://' +location.host).length - 1);
      
      	// Register event with Google Analytics
      	pageTracker._trackEvent(
      		'Flash', 'Link',
      		eventDescription, pageLocation + '/' + eventValue
      	);
      
      	// Go to URL
      	document.location.href = eventValue;
      }

      This would mean that the flash could be exactly the same, but now you’d also be tracking a combination of the web page location and the flash event value.

  4. Pingback: Steve Fleckenstein
  5. stanleyneville says:

    Just simply wanted to say I am thankful that i stumbled on your site.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

WP-SpamFree by Pole Position Marketing