View Sidebar
Google Analytics for Flash Sites

Google Analytics for Flash Sites

August 27, 2012 23:36

Tracking flash site content both in AS2, AS3.

Tracking with

  • SWF Address (Deep linked sites) & SWF Object.
  • Using Google Analytics API for Flash.
  • Combination of Javascript and Actionscript.

AS2

There are two ways to accomplish this

1. Using combination of ActionScript and JavaScrip

  • Insert the normal GA Code in html page which contains Flash Object.
  • Use ExternalInterface function of AS2 to pass the values to be tracked to the JavaScript function.

AS2 Call to JavaScript

ExternalInterface.call (“_gaq.push ([‘_trackPageview’, ‘STRING TO REPORT TO G.A.’])”);

2. Only using JavaScript (Works only for Deeplinked Flash Sites)

Using SWFAddress for deeplinking allows Flash to talk back to browser, the advantages of deeplinking is, it gives user ability to link to and share specific parts of Flash websites. It also records history states in the browser, enabling the back, forward and refresh buttons in the browser. Using SWFAddress we can tell Google Analytics which page the user is visiting, without using ActionScript.

<script>

var _gaq = _gaq || [];
_gaq.push([‘_trackPageview’]);
_gaq.push([‘_setAccount’, ‘UA-XXXXXX-XX’]);
(function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’;
ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ :
‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0];
s.parentNode.insertBefore(ga, s);
})();
// Tracker for SWFAddress
var pageTracker = {Ā Ā Ā  _trackPageview: function (url) {_gaq.push ([‘_trackPageview’, url ]);}};
</script>
<script type=”text/javascript” src=”assets/js/swfobject.js”></script>
<script type=”text/javascript” src=”assets/js/swfaddress.js?tracker=pageTracker._trackPageview”></script>

You need to load script in following order

  1. Google Analytics Code
  2. SwfObject
  3. SwfAddress

AS3

There are three ways to accomplish this

1. Using combination of ActionScript and JavaScript

Similar to AS2 method using ExternalInterface

2. Only using JavaScript (Works only for Deeplinked Flash Sites)

Similar to AS2

3. Using Google Analytics API for Flash (GAforFlash)

Reference: http://code.google.com/p/gaforflash/

import com.google.analytics.GATracker;

import com.google.analytics.AnalyticsTracker;

var tracker:AnalyticsTracker;

//GATracker(display:DisplayObject, account:String, mode:String = “AS3”, visualDebug:Boolean = false, config:ConfigurationĀ  = null, debug:DebugConfigurationĀ  = null);

tracker = new GATracker(this, “UA-XXXXXXX-X”, “AS3”, true); // Google Analytics Event Tracking Example tracker.tracePageview(ā€œString to Trackā€);

If you like the article please share

Leave a reply

You must be logged in to post a comment.