com.google.analytics.tracking.android
Class GoogleAnalytics

java.lang.Object
  extended by com.google.analytics.tracking.android.GoogleAnalytics
All Implemented Interfaces:
Analytics

public class GoogleAnalytics
extends java.lang.Object
implements Analytics

Implementation of the Analytics interface. This implementation is a singleton and will pass hits to an instance of AnalyticsThread for further processing and dispatch. It also manages trackers such that only one Tracker can exist for any particular trackingId.

This class also manages the debug flag.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.google.analytics.tracking.android.Analytics
Analytics.AppOptOutCallback
 
Method Summary
 void closeTracker(Tracker tracker)
          Closes the tracker.
 boolean debugEnabled()
          Returns whether debug mode is on.
 Tracker getDefaultTracker()
          Returns the default Tracker if one exists.
static GoogleAnalytics getInstance(Context context)
          Get the instance of the GoogleAnalytics class, creating it if necessary.
 Tracker getTracker(java.lang.String trackingId)
          Multiple instances of a Tracker can be created as long as each has its own trackingId.
 void requestAppOptOut(Analytics.AppOptOutCallback callback)
          Requests whether the state of the application-level opt is on.
 void sendHit(java.util.Map<java.lang.String,java.lang.String> hit)
          Create and queue a hit based on the data in hitData.
 void setAppOptOut(boolean optOut)
          Sets or resets the application-level opt out flag.
 void setDebug(boolean debug)
          Toggles debug mode.
 void setDefaultTracker(Tracker tracker)
          Sets the default Tracker.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static GoogleAnalytics getInstance(Context context)
Get the instance of the GoogleAnalytics class, creating it if necessary.


setDebug

public void setDebug(boolean debug)
Description copied from interface: Analytics
Toggles debug mode. In debug mode, debug messages will be written to the log. This is useful for debugging calls to the Google Analytics SDK.

By default, this flag is disabled.

Specified by:
setDebug in interface Analytics

debugEnabled

public boolean debugEnabled()
Description copied from interface: Analytics
Returns whether debug mode is on.

Specified by:
debugEnabled in interface Analytics

getTracker

public Tracker getTracker(java.lang.String trackingId)
Description copied from interface: Analytics
Multiple instances of a Tracker can be created as long as each has its own trackingId. If a Tracker has already been created (and not yet closed) for a given trackingId, that will be returned.

Specified by:
getTracker in interface Analytics
Parameters:
trackingId - string of the form UA-xxxx-y

getDefaultTracker

public Tracker getDefaultTracker()
Description copied from interface: Analytics
Returns the default Tracker if one exists. By default, the default Tracker is the first one created.

Specified by:
getDefaultTracker in interface Analytics

setDefaultTracker

public void setDefaultTracker(Tracker tracker)
Description copied from interface: Analytics
Sets the default Tracker.

Specified by:
setDefaultTracker in interface Analytics

closeTracker

public void closeTracker(Tracker tracker)
Closes the tracker. Call this method when a tracker will no longer be used.

Parameters:
tracker - the tracker that is no longer needed

sendHit

public void sendHit(java.util.Map<java.lang.String,java.lang.String> hit)
Create and queue a hit based on the data in hitData.

Parameters:
hit - the data for the hit

setAppOptOut

public void setAppOptOut(boolean optOut)
Description copied from interface: Analytics
Sets or resets the application-level opt out flag. If set, no hits will be sent to Google Analytics. The value of this flag will persist across app starts.

Specified by:
setAppOptOut in interface Analytics
Parameters:
optOut - true if application-level opt out should be enforced

requestAppOptOut

public void requestAppOptOut(Analytics.AppOptOutCallback callback)
Description copied from interface: Analytics
Requests whether the state of the application-level opt is on. The Analytics.AppOptOutCallback.reportAppOptOut(boolean) method will be called with the answer once it's been calculated. The callback Analytics.AppOptOutCallback.reportAppOptOut(boolean) may be called either before or after this method returns.

It may be called from a different thread.

Specified by:
requestAppOptOut in interface Analytics
Parameters:
callback - to use to report application-level opt out flag