|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.analytics.tracking.android.EasyTracker
public class EasyTracker
EasyTracker is a class designed to easy the burden of adding tracking code to your application. Ensure that all of your Activities call EasyTracker on your activity's onStart and onStart:
@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.
For convenience, TrackedActivity
, TrackedExpandableListActivity
,
TrackedListActivity
, TrackedPreferenceActivity
, and
TrackedTabActivity
are provided whose only purpose is to
override these two methods and call EasyTracker.
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:
Method Summary | |
---|---|
void |
activityStart(Activity activity)
Track the start of an Activity , but only if autoActivityTracking 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 . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
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 autoActivityTracking
is true.
This method will start a new session if necessary, and will send an empty
event to Google Analytics if autoActivityTracking
is false to ensure proper
application-level tracking. This method should be called from the
onStart
method in each Activity
in your application. You may
extend TrackedActivity
(or its other cousins)
instead of Activity
to use this method.
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.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |