-
Notifications
You must be signed in to change notification settings - Fork 11
TrackingDetailsAndTricks
Manually Add Parameters to a Tracker
set( field:String, value:String )
allow you to add a permanent parameter for all following hit requests.
For example add the application name:
tracker.set( Tracker.APP_NAME, "My Game" );
tracker.screenview( "High Scores" );
setOneTime( field:String, value:String )
allow you to add a "one shot" parameter for the next hit request.
For example change temporarily the data source
tracker.setOneTime( Tracker.DATA_SOURCE, "advertising" );
tracker.screenview( "Game Over" );
add( values:Dictionary )
works like the set()
method but allow you to add parameters in batch
from a Dictionnary
of field/value pairs.
For example define the application datas:
var gameinfo:Dictionnary = new Dictionnary();
gameinfo[ Tracker.APP_NAME ] = "My Game";
gameinfo[ Tracker.APP_ID ] = "com.something.mygame";
gameinfo[ Tracker.APP_VERSION ] = "1.0.0";
gameinfo[ Tracker.APP_INSTALLER_ID ] = "Amazon App Store";
tracker.add( gameinfo );
tracker.screenview( "Intro" );
Automatically Add Parameters to a Tracker
You can use functions and/or classes helpers like:
ApplicationInfo
, SystemInfo
, TimingInfo
, etc.
generateFlashSystemInfo()
, generateAIRSystemInfo()
, generateCLISystemInfo()
, etc.
For example you would want to always add the System info:
var sysinfo:SystemInfo = generateFlashSystemInfo();
tracker.add( sysinfo.toDictionary() );
Or for example you would want to dynamically generate the application info from the AIR application descriptor:
var appinfo:ApplicationInfo = generateAIRAppInfo();
tracker.add( appinfo.toDictionary() );
Throttling
Our library may throttle events, as well as other hits,
if a large number of send calls are made in a short period of time.
By default our trackers use a RateLimiter
-
Online SWF files (equivalent to analytics.js)
theWebTracker
starts with 20 hits
that are replenished at a rate of 2 hits per second. -
AIR applications (equivalent to Android SDK/iOS SDK)
theAppTracker
starts with 60 hits
that are replenished at a rate of 1 hit every 2 seconds. -
RedTamarin (command-line and server-side)
theCliTracker
starts with 100 hits
that are replenished at a rate of 10 hits per second.
Sampling
By default our trackers use a sample rate of 100%,
that means all hits are send, but then if your sites or apps
reach millions of users you might consider sampling down
your data to maybe 40% more or less.
By sampling the hits for your site or app, you will still get reliable report results while staying within the hit limits for your account.
see: How sampling works
By default, Google Analytics will group hits that are received within 30 minutes of one another into the same session. This period is configurable at the property level.
see: Learn how to configure this session timeout period
Manual Session Management
You can manually start a new session when sending a hit to Google Analytics.
The following example shows how to start a new session when sending a screen view:
tracker.setOneTime( Tracker.SESSION_CONTROL, SessionControl.START );
tracker.screenview( "Home Screen" );
Automatic Session Management
Not supported yet.
Tracking pages is sending a "pageview" hit request:
tracker.pageview( "/hello/world", "Hello World" );
You can use UTF-8 in both the page path and title:
tracker.pageview( "/hello/€", "Hello €" );
Our trackers automatically add a domain name when sending a "pageview"
checkout the utilities: getHostname()
, getCLIHostname()
.
You can override the hostname this way:
tracker.set( Tracker.DOCUMENT_HOSTNAME, "www.as3lang.org" );
Modifying page URLs
In some specific cases you would want to rewrite URLs containing identifying informations,
for example /user/USER_ID/account
would become /user/account
.
Tracking virtual pageviews
From inside an online SWF file or an AIR application when you track pageviews
you are basically tracking virtual pages.
This is very similar to Single Page Application Tracking when an HTML page load content dynamically via AJAX.
Automatic Screen Measurement
Depending on how you're managing the navigation of your application
you could automate the tracking of screens.
For example, you could take the convention that a screen is "visited"
when a DisplayObject
is added to the Stage:
public class MyScreen extends Sprite
{
public function MyScreen()
{
super();
name = "My Screen Name";
if( stage )
{
onAddedToStage();
}
else
{
addEventListener( Event.ADDED_TO_STAGE, onAddedToStage );
}
}
//...
private function onAddedToStage( event:Event = null ):void
{
removeEventListener( Event.ADDED_TO_STAGE, onAddedToStage );
tracker.screenview( this.name );
}
}
Use Events to collect data about interactions with your content.
See: About Events
Non-interaction events
In some cases you might want to send an event as a non-interaction event.
For example to indicate that a video autoplay (eg. without the user actually clicking the "play" button).
tracker.setOneTime( Tracker.NON_INTERACTION, "1" );
tracker.event( "Videos", "play", "Mr. Robot: Official Trailer" );
Caught Exceptions
Caught exceptions are errors in your app for which you've defined
exception handling code, such as the occasional timeout of a network connection
during a request for data.
Measure a caught exception by setting the exception field values on the tracker and sending the hit, as in this example:
try
{
//an error is thrown here
}
catch( e:Error )
{
tracker.exception( e.name + ":" + e.errorID, false );
}
Warning
Never send the exception message (
e.message
) to Google Analytics as it may contain personally identifiable information.
Uncaught Exception Measurement
Uncaught exceptions represent instances where your app encountered unexpected
conditions at runtime and are often fatal, causing the app to crash.
Uncaught exceptions can be sent to Google Analytics automatically
by setting a listener to the UncaughtErrorEvent.UNCAUGHT_ERROR
event.
public class MyScreen extends Sprite
{
public function MyScreen()
{
super();
loaderInfo.uncaughtErrorEvents.addEventListener( UncaughtErrorEvent.UNCAUGHT_ERROR, onGlobalErrors );
if( stage )
{
onAddedToStage();
}
else
{
addEventListener( Event.ADDED_TO_STAGE, onAddedToStage );
}
}
//...
private function onGlobalErrors( event:UncaughtErrorEvent ):void
{
if (event.error is Error)
{
var error:Error = event.error as Error;
// do something with the error
tracker.exception( error.name + ":" + error.errorID );
}
else if (event.error is ErrorEvent)
{
var errorEvent:ErrorEvent = event.error as ErrorEvent;
// do something with the error
tracker.exception( "Error:" + errorEvent.errorID );
}
else
{
// a non-Error, non-ErrorEvent type was thrown and uncaught
tracker.exception( "unknown error occured" );
}
}
}
Read the Custom dimensions & metrics documentation.
Create and edit custom dimensions and metrics first in the Google Analytics backend.
There are limits
- 20 indices for custom dimensions (200 for Premium account)
- 20 indices for custom metrics (200 for Premium account)
- you can create them but not delete them, only disable them
- you should avoid reusing a custom dimension/metric for another one
A bit confusing right?
Let's see how a custom metric works
- you define it in the backend with the name "Memory" in "Admin" then "Custom Definitions"
- the index will be
1
- the type will be
Integer
other choices are:Currency (decimal)
,Time
- you can also define optional minimum and maximum values
- the scope will be
Hit
other choices are:Product
- be sure the variable is Active
Then you define it in your source code:
var priv_mem:Number = System.privateMemory; // bytes
var memory:uint = priv_mem / 1024 / 1024; // MB
tracker.set( Tracker.CUSTOM_METRIC(1), memory );
And you track it.
Then in a custom reports you will be able to find a "Memory" custom metric showing you the amount of memory (in MegaBytes) used by the application.
See Create and manage Custom Reports then include non-standard data in your reports.
Our follow a tutorial like How to Access Custom Dimensions in Google Analytics which explains it with coffee bean and coffee drinkers.
So that's the trick, you can select a custom dimension in the default reports but you will need to create a custom report to see custom metrics, and in both case you need to define those custom definitions on the backend before being able to collect them or see them in any reports.
Note:
Our trackers can track E-Commerce Transaction and Item but it seems
those will be deprecated in favour of Enhanced E-Commerce which uses
more complex parameters that we don't support yet.
In fact, analytics.js
need to load an additional ecommerce.js
,
see Ecommerce Tracking.
We may not support that at all as our focus is on the Measurement Protocol.