Flash_and_Flex_03_2009

Google Analytics for Flash

of tracking: tracking pages and tracking events. For pages, you can clearly grasp the concept when you think of an HTML website. Each time the browser refreshes or changes a page and that page is from your website, a pageview is sent to Google Analytics. Now, you can translate the same concept toFlashand rich internet applications, but they tend to have less pages than HTML websites. When I try to define pages in my Flash website, I try to think in sections, example: the contact section, the home section, the help section etc. Here is the code you would write to track a pageview: Events are a metric that are more suited to Flash and RIA than pageViews. Event tracking is still in beta, so it is not enabled on all profiles. You can ask Google to activate events on your account by filling the form found on this page: http://code.google.com/p/gaforflash/wiki/ EventTrackingRequest Events are best suited to track user's interaction with your project: how many user saw your complete video, how many clicked on the mute sound button, etc. This is what you would write to send an event: _tracker.trackPageview(yourSectionName + "/"); _tracker.trackEvent("English", "Client Satisfaction", "Question 3", value); The trackEvent function can take up to 4 parameters, the last two being optional. They are in order Category, Action, Label and Value and they are all Strings except the last one, which has to be a non-negative integer. Google Analytics suggest some uses of these parameters, but in the end, it is up to you to

On the 'Net

• Google Code – http://code.google.com/p/gaforflash/ • Developer group – http://groups.google.com/group/ga-for-flash?pli=1 • Adobe Max presentation on Google Analytics for Flash – http://tv.adobe.com/#vi+f15385v1040

Figure 3. Example of the Visual Debug

decide how you want to define them. More information about Events can be found here: http://code.google.com/apis/analytics/docs/ eventTrackerGuide.html Bridge vs AS3 I have only talked about the AS3 mode so far, because it is the one I usemost often. It ismostly used when your entire site is made in Flash, or also when your content will be embedded somewhere that you don't have access to the HTML. This is the case for widgets and games that are embedded on multiple sites. The Bridge mode has two cases where I would use it. First, if your Flash is just a part of a larger website that is written in HTML, which already uses Google Analytics, then using the Bridge mode will use the tracker of the HTML’s page and blend in the data of the Flash content with the data of the rest of the site. Secondly, not all of the Google Analytics API is available when using the AS3 mode, so if you need advanced functions or ones that are not enabled, then you have no choice but to use Bridge mode. The code is a bit different from AS3 mode, so I will show a sample: var _tracker:AnalyticsTracker = new GATracker( main, "window.PageTracker", "Bridge"); The first parameter in this case still refers to a DisplayObject on the stage. The second one has to be the name of your Javascript PageTracker

Object, preceded by window . and the last one is to tell the tracker to use the Bridge mode. Since, Flash will need to communicate with the JavaScript while in Bridge mode, you have to be sure that allowScriptAccess is set to always in the HTML page that embeds the Flash content. Visual Debug One cool thing about GA for Flash is the Visual Debug. All you have to do to enable it is add an extra parameter when you initialize the tracker. var _tracker:AnalyticsTracker = new GATracker( main, "UA-7777777-7", "AS3", true); Doing this will add a layer on top of your application where all the actions the tracker performs will be listed, see (Figure 3). What is neat about this is that you can now see instantly what you are tracking. With the JavaScript API, unfortunately, it is hard to see exactly what you are sending, because you have to note down what you did and go check 4-5 hours later to see if it tracked correctly (Google Analytics shows data after a delay of a few hours). With the Visual Debug you can see if you are sending more events than you should or if one label is misspelled etc. Even though Google Analytics for Flash is a great library, it has some drawbacks. The biggest one is that it will add 40k to the size of your Flash content. Even with that in mind, it is worth using in every Flash project.

Figure 2. Analytics component in the Components window in Flash

03/2009 (5)

63

Made with FlippingBook HTML5