Flash_and_Flex_03_2009

ActionScript Development

GoogleAnalytics for Flash

by Dominic Gélineau

In this time of economic crisis, marketing budgets are shifting from traditional to digital because of the latter's ability to provide data about its effects.

youwouldwith anHTMLwebsite, but in the end you gainmore control. All youhave to do is import the libraries and create the tracker like this: import com.google.analytics.AnalyticsTracker; import com.google.analytics.GATracker; var _tracker:AnalyticsTracker = new GATracker( main, "UA-7777777-7", "AS3"); The first parameter in this case refers to a DisplayObject on the stage or the stage itself. The second parameter is the id for the Google Analytics profile you want the data to be sent to. The third parameter is the mode in which the tracker will function, in this case AS3 mode. An other mode that the tracker can be set to is the Bridge mode and I will discuss the difference between the two modes later on. You are now ready to track. The tracker you just created will give you access to two method

What you will learn… • How to install Google Analytics for Flash • How to send data to Google Analytics • Concepts about web analytics

What you should know… • Basic knowledge of ActionScript • Basic knowledge of Google Analytics

the same results. First, you can use a Subversion client like, TurtleSVN to checkout (download) the source code of the library. This will give you access to the Actionscript files ( .as ) that were used to make the SWC library. Once you have those files just copy them into your project directory and you are ready to go. If you don't want to bother with SVN, you can copy the SWC files into the Component directory of your Flash installation. Now this is the intended use of the SWC files by the makers, but I found it is more complicated than it should have been. If you want to do it that way, copy the SWC files in the following folder in windows: • C:\Program Files\Adobe\Adobe Flash CS3\language\Configuration\Compo - nents

Level of difficulty

F lash has never been great at web analytics, but a new library, Google Analytics for Flash , is going to change this. This article will focus onhow to install this library, how to use it and will explain some of its key concepts. Installation The first thing to do is to install the library. This might not be as obvious as it should be, so I thought it would be good to explain it here. When you download the zip file from the Google Code page for Google Analytics for Flash http: //code.google.com/p/gaforflash/ , what you will get is two SWC files. SWC files are a common things in the Flexworld, but they are not so common in the Flashworld. This is where the difficulty lies. Flash CS4 There is a new feature in Flash CS4 that enables you to import SWClibraries like youwoulddo it in Flex. All you have to do is open the publish profile and click on the Flash tab. Then, click on the Actionscript 3 settings; on the window that will pop-up you will see a red envelope icon, clicking on it will enable you to import the SWC file, see (Figure 1). Flash CS3 It is not that easy for Flash developers still using Flash CS3, but I have found two ways of getting

And the following folder if you are using a Mac:

• Macintosh HD:Applications:Adobe Flash CS3:Configuration:Components

The next time you will start Flash, in your component window, you should see the Google Analytics for Flash components. Drag the component in the library and you can go on to the next step, see (Figure 2). On to tracking Tracking is the easiest part of the process and is fairly intuitive. Youhave todo abitmorework than

Figure 1. Where to include SWC file in Flash CS4

03/2009 (5)

62

Made with FlippingBook HTML5