public class EasyTracker
extends java.lang.Object
@Override
public void onStart() {
super.onStart();
EasyTracker.getInstance().activityStart(this);
}
@Override
public void onStop() {
super.onStop();
EasyTracker.getInstance().activityStop(this);
}
Additionally, if you want to make EasyTracker calls in other classes or methods,
you should ensure to call setContext(Context) in each Activity's onCreate
method before making any such calls. You can make this call in your Application's
onCreate method instead.
Next, create an .xml file (analytics.xml, perhaps) and set various resources within that file. You can turn on tracking by providing a String resource of the name ga_trackingId with a value of your tracking id (form UA-12345-6). You can provide various parameters as String, Bool or Integer resources (such as sampleRate) as well. Just use the proper type for the parameter (String for String, Bool for boolean and Integer for int).
Information about the application, by default, are retrieved programatically. The Application name will be retrieved from the app_name string in your Android resources. The application version will be retrieved from the versionName in your manifest. To override either of these, provide ga_appName or ga_appVersion String resources.
If you want to track your Activities as well as the application, you can add
the Bool resource ga_autoActivityTracking and give it a value of true.
Here is a complete list of parameters that can be passed to EasyTracker:
| Modifier and Type | Method and Description |
|---|---|
void |
activityStart(Activity activity)
Track the start of an
Activity, but only if mIsAutoActivityTracking is true. |
void |
activityStop(Activity activity)
Track the end of an
Activity and/or application. |
void |
dispatch()
Dispatches pending hits.
|
static EasyTracker |
getInstance()
Returns a singleton instance of
EasyTracker. |
static Tracker |
getTracker()
Get the
Tracker used by EasyTracker. |
void |
setContext(Context ctx)
Sets the context to use to the applicationContext of the input
Context. |
public static EasyTracker getInstance()
EasyTracker.public static Tracker getTracker()
Tracker used by EasyTracker. Note that EasyTracker must
have been initialized by calling either setContext(Context) or
activityStart(Activity) before calling this method. Otherwise an
IllegalStateException will be thrown.Tracker used by EasyTrackerpublic void setContext(Context ctx)
Context.
If the input is not null, this method will then go on to initialize
EasyTracker with parameters from the resource files. If ga_trackingId is specified, this method will enable Google Analytics tracking.
If not, it will leave tracking disabled.ctx - the Context to use to fetch the applicationContextpublic void activityStart(Activity activity)
Activity, but only if mIsAutoActivityTracking is true.
This method will start a new session if necessary, and will send an empty
event to Google Analytics if mIsAutoActivityTracking is false to ensure proper
application-level tracking. This method should be called from the
onStart method in each Activity in your application.activity - the Activity that is to be trackedpublic void activityStop(Activity activity)
Activity and/or application. This is done by sending
an empty event to Google Analytics. Note that this method should be called
from the onStop method of each Activity in your application.activity - the Activity that is to be trackedpublic void dispatch()
ServiceManager.dispatch() for details.