Posts Tagged AS3
AnalyticsManager with multi-tracker support
Problem:
I was working on an international website for Le Pain Quotidien.
Depending on which country is chosen on the homepage, an other Google Analytics Tracker had to be used.
Solution:
I wrote a class which allows to create trackers at Runtime, and send tracking information to a specific tracker.
How it works:
The system consists of 2 classes:
- An AnalyticsManager class, which allows to add or remove trackers at runtime.
- An AnalyticsTracker class, which uses ExternalInterface to send the tracking-information to it’s associated tracker.
Code in AS3:
var analytics:AnalyticsManager = new AnalyticsManager ();
analytics.addTracker ("pageTracker1");
analytics.addTracker ("pageTracker2");
analytics.getTracker ("pageTracker1").track ( "tag_for_tracker_1" );
analytics.getTracker ("pageTracker2").track ( "tag_for_tracker_2" );
Code in HTML:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker1 = _gat._getTracker("UA-xxxxxxx-1");
var pageTracker2 = _gat._getTracker("UA-xxxxxxx-2");
pageTracker1 ._trackPageview("/home");
</script>
Files:
You can download the files here:
AnalyticsManager.zip
The class uses a HashMap to save the trackers.
The HashMap classes are included in the zip-file.
AIR Updater
I’ve written a class to make the updating process of AIR-projectors easier.
The class uses the great AIRRemoteUpdater classes, written by Claus Wahlers (http://codeazur.com.br/lab/airremoteupdater/).
How it works:
You create an AIRUpdater object, configure the wanted listeners, and ask it to check for an update.
Code in AS3:
var updater:AIRUpdater = new AIRUpdater ("path_to_air_file", true, true);
updater.addEventListener(AIRUpdaterEvent.COMPLETE, updateCompleteHandler);
updater.addEventListener(AIRUpdaterEvent.CONFIRM, updateConfirmHandler);
updater.addEventListener(AIRUpdaterEvent.WARNING, updateWarningHandler);
updater.addEventListener(AIRUpdaterEvent.CONNECTION_ERROR, updateErrorHandler);
updater.update();
function updateCompleteHandler(event:AIRUpdaterEvent):void
{
// Starting application.
}
function updateConfirmHandler(event:AIRUpdaterEvent):void
{
// Update confirmation requested.
// Current version: updater.localVersion
// Remote version: updater.remoteVersion
// on confirm: updater.update (false);
}
function updateWarningHandler(event:AIRUpdaterEvent):void
{
// Update warning message.
updater.install ();
}
function updateErrorHandler(event:AIRUpdaterEvent):void
{
// Update file not found.
}
The constructor of the class requires the path to the air file, and gives you the choice to stop the updating process for a confirmation and/or a warning.
Files:
You can download the zip-file here:
AIRUpdater.zip
I’ve included the original AIRRemoteUpdater classes in the zip file.
Note that these classes are not written by me, so more recent versions might be available.
Recent Comments