-
Notifications
You must be signed in to change notification settings - Fork 11
TrackingConfiguration
How to configure the trackers.
The AnalyticsTracker
is responsible to define what is a tracker
and the AnalyticsSender
is responsible to define how the data is sent,
and they need both to be configured.
When you instantiate a tracker you have the option to provide a Configuration
,
if you don't then the configuration is created with its default parameters.
// create your own config
var config:Configuration = new Configuration();
config.forcePOST = true;
// pass it around
var tracker:WebTracker = new WebTracker( "UA-12345-67", config );
In general you would want to configure first then pass the config to the tracker, but technically you can do it every which way, as the config is also accessible as a property of the tracker (but it is read-only).
var tracker:WebTracker = new WebTracker( "UA-12345-67" );
// edit the config property after the tracker was created
tracker.config.forcePOST = true;
You can not overwrite the config
property (eg. it is read-only)
tracker.config = new Configuration(); // this will fail
The tracker is responsible to instantiate the sender,
the logic is that the tracker pass itself as an argument to the sender constructor.
public class MyTracker extends Tracker
{
private var _sender:MySender;
public function MyTracker( trackingId:String,
config:Configuration = null )
{
super();
_sender = new MySender( this );
}
}
and the sender then keep a reference of the tracker around
public class MySender extends HitSender
{
private var _tracker:MyTracker;
public function MySender( tracker:AnalyticsTracker )
{
_tracker = tracker;
}
public function doSomething():void
{
if( _tracker.config.forcePOST )
{
// act accordingly
}
}
}
Which lead to the most important feature of this configuration
The configuration is applied for each hits, if you change properties between hits, it will affect the way hits are processed.
The configuration is instantiated once and passed around as a reference, and checked before each hit requests, so if you change it the hit request will change accordingly.
for Example:
var config:Configuration = new Configuration();
// for some reasons we want to use POST instead of GET
config.forcePOST = true;
var tracker:WebTracker = new WebTracker( "UA-12345-67", config );
// use POST to send the hit request
tracker.pageview( "/hello/world", "Hello World" );
config.forcePOST = false;
// use GET to send the hit request
tracker.pageview( "/hello/world", "Hello World" );
config.forcePOST = true;
// use POST to send the hit request
tracker.pageview( "/hello/world", "Hello World" );
// etc.
The configuration allow to change which AnalyticsSender
is instantiated by the AnalyticsTracker
.
With config.senderType
, which is an empty string by default.
Let's say you would want to see the traces of a HitSender
instead of actually sending the data
you would want to use the TracehitSender
:
var config:Configuration = new Configuration();
config.senderType = "libraries.uanalytics.tracker.senders.TraceHitSender";
var tracker:WebTracker = new WebTracker( "UA-12345-67", config );
With that configuration, instead of instantiating the default sender LoaderHitSender
the tracker instantiate TraceHitSender
.
Here the list of all the senders:
-
TraceHitSender
Flash / AIR / Redtamarin -
DebugHitSender
Flash / AIR -
LoaderHitSender (default)
Flash / AIR -
URLLoaderHitSender
Flash / AIR -
URLStreamSender
Flash / AIR -
BSDSocketHitSender (default)
Redtamarin -
CurlHitSender
Redtamarin
Those are made in such a way you can extend them to customise them to your liking,
or you can also implement the AnalyticsSender
interface and do whatever you want.