<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Simpson &#187; actionscript</title>
	<atom:link href="http://davidsimpson.me/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidsimpson.me</link>
	<description>Developing the web, one page at a time.</description>
	<lastBuildDate>Wed, 16 May 2012 20:14:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>How To Track Events in Flash Movies using WebTrends</title>
		<link>http://davidsimpson.me/2009/03/09/how-to-track-events-in-flash-movies-using-webtrends/</link>
		<comments>http://davidsimpson.me/2009/03/09/how-to-track-events-in-flash-movies-using-webtrends/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 17:07:26 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[analytics]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webtrends]]></category>

		<guid isPermaLink="false">http://davidsimpson.me/?p=106</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton106" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fdavidsimpson.me%2F2009%2F03%2F09%2Fhow-to-track-events-in-flash-movies-using-webtrends%2F&amp;text=How%20To%20Track%20Events%20in%20Flash%20Movies%20using%20WebTrends&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fdavidsimpson.me%2F2009%2F03%2F09%2Fhow-to-track-events-in-flash-movies-using-webtrends%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://davidsimpson.me/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;"></a></div><p><!-- How To Track Events in Flash Movies using WebTrends --></p>
<p>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.</p>
<p>This example uses a intermediary javascript function that sits between the Flash movies and the WebTrends code.</p>
<h3>Benefits</h3>
<ul>
<li>It&#8217;s much easier to debug if the WebTrends javascript is not called within the compiled Flash movie</li>
<li>The WebTrends tracking can be changed later without recompiling the Flash movie or even speaking to your Flash developer</li>
</ul>
<p><span id="more-106"></span></p>
<h3>Drawbacks</h3>
<ul>
<li>Javascript must be enabled to trigger the link to the target web page</li>
<li>Both Flash <i>and</i> Javascript will be required to navigate your website</li>
</ul>
<p><b>This is bad from an accessibility point of view</b>, but I won&#8217;t discuss that here.</p>
<h2>ActionScript for Flash buttons</h2>
<p>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.</p>
<h3>Older ActionScript versions</h3>
<pre class="brush: plain; title: ;">on (release)
{
	getURL(&quot;javascript:myFlashEvent('Open Days','http://www.nottingham.ac.uk/opendays');&quot;);
}</pre>
<h3>ActionScript 3+</h3>
<p>The <code>getURL</code> function was removed in ActionScript 3, so a slightly more complex example is required</p>
<pre class="brush: plain; title: ;">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
	}
}</pre>
<p>The ActionScript calls the Javascript intermediary function <code>myFlashEvent</code>, which in turn registers the event with WebTrends and then loads the new web page.</p>
<h2>Javascript</h2>
<pre class="brush: jscript; title: ;">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;
}</pre>
<p>This function will track the event as a visit to a URI using the <code>DCS.dcsuri</code> parameter.  The page title for the URI will be set to e.g. &#8216;FlashEvent:My Page Title&#8217; using the <code>WT.ti</code> parameter.</p>
<h2>Results</h2>
<p>The click event is showing up nicely in WebTrends as <code>FlashEvent:Open Days</code>, see the screenshot below</p>
<p><img class="hang-1-column" src="http://www.nottingham.ac.uk/~cczdas/images/webtrends-flash-event.png" alt="Screenshot of WebTrends Console" /></p>
<h2>Example code</h2>
<p>A working example of this code can be found <a href="http://www.nottingham.ac.uk/analytics-events/analytics-events/">here</a>.  </p>
<p>Sorry, I don&#8217;t have access to the .fla file, so that is not included.</p>
<h2>Adapting the Javascript for Google Analytics</h2>
<p>The <code>myFlashEvent</code> function can easily be adapted to work with Google Analytics instead:</p>
<pre class="brush: jscript; title: ;">function myFlashEvent(eventDescription, eventValue){

	// Register event
	pageTracker._trackEvent(
		'Flash', 'Link',
		eventDescription, eventValue
	);

	// Go to URL
	document.location.href = eventValue;
}</pre>
<h2>Reference</h2>
<ul>
<li><a href="http://www.arena.no/dokumentasjon/wt85/dcsMultiTrack.pdf">Tracking Complex Web Page Interactions Using dcsMultiTrack (WebTrends)</a></li>
<li><a href="http://blog.webtrends.com/2009/03/09/tracking-visitors-in-a-rich-media-world-part-i-tracking/">Tracking Visitors in a Rich Media World, Part I: Tracking</a></li>
<li><a href="http://code.google.com/apis/analytics/docs/eventTrackerGuide.html">Event Tracking Guide (Google Analytics)</a></li>
<li><strong>Update:</strong> Here&#8217;s a really elegant solution to adding <a href="http://www.embeddedstream.com/2009/02/27/webtrends-tracking-from-flash/">Webtrends tracking to Flash</a> movies</li>
<li><strong>Update:</strong> <a href="http://www.insideria.com/2009/02/using-google-analytics-within.html">Google Analytics within Flex/Flash Applications</a</li>
</ul>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://davidsimpson.me/2009/03/09/how-to-track-events-in-flash-movies-using-webtrends/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

