com.google.analytics.tracking.android
Interface Tracker

All Known Implementing Classes:
GoogleTracker

public interface Tracker

This defines the interface for doing Analytics tracking. A Tracker is responsible for tracking a particular web property.

Only track calls queue hits to be dispatched.


Method Summary
 boolean anonymizeIpEnabled()
          Returns whether or not anonymize IP mode is on.
 void close()
          Closes the session.
 java.util.Map<java.lang.String,java.lang.String> constructEvent(java.lang.String category, java.lang.String action, java.lang.String label, java.lang.Long value)
          Creates model fields for an event.
 java.util.Map<java.lang.String,java.lang.String> constructException(java.lang.String exceptionDescription, boolean fatal)
          Creates model fields for an exception.
 java.util.Map<java.lang.String,java.lang.String> constructRawException(java.lang.String threadName, java.lang.Throwable exception, boolean fatal)
          Creates model fields for an exception.
 java.util.Map<java.lang.String,java.lang.String> constructSocial(java.lang.String network, java.lang.String action, java.lang.String target)
          Creates model fields for social.
 java.util.Map<java.lang.String,java.lang.String> constructTiming(java.lang.String category, long intervalInMilliseconds, java.lang.String name, java.lang.String label)
          Creates model fields for timing.
 java.util.Map<java.lang.String,java.lang.String> constructTransaction(Transaction trans)
          Creates model fields for a transaction.
 java.lang.String get(java.lang.String key)
          Gets the model value for the given key.
 java.lang.String getAppId()
           
 java.lang.String getAppInstallerId()
           
 ExceptionParser getExceptionParser()
           
 double getSampleRate()
          Returns the sample rate.
 java.lang.String getTrackingId()
           
 boolean getUseSecure()
          Returns the current setting for useSecure.
 void send(java.lang.String hitType, java.util.Map<java.lang.String,java.lang.String> params)
          Tracks the given hit.
 void set(java.lang.String key, java.lang.String value)
          Sets the model value for the given key.
 void setAnonymizeIp(boolean anonymizeIp)
          Turns on or off anonymize IP mode.
 void setAppId(java.lang.String appId)
          Set the appId.
 void setAppInstallerId(java.lang.String appInstallerId)
          Set the id of the app that installed this app.
 void setAppName(java.lang.String appName)
          Set the application name to appName.
 void setAppScreen(java.lang.String appScreen)
          Stores the place to be sent with subsequent track calls.
 void setAppVersion(java.lang.String appVersion)
          Set the application version to appVersion.
 void setCampaign(java.lang.String campaign)
          Set the campaign.
 void setCustomDimension(int slot, java.lang.String value)
          Sets the value for a custom dimension.
 void setCustomDimensionsAndMetrics(java.util.Map<java.lang.Integer,java.lang.String> dimensions, java.util.Map<java.lang.Integer,java.lang.Long> metrics)
          Sets the values for several custom dimensions and metrics at once.
 void setCustomMetric(int slot, java.lang.Long value)
          Sets the value for a custom metric.
 void setExceptionParser(ExceptionParser exceptionParser)
          Sets the ExceptionParser to be used by this Tracker.
 void setReferrer(java.lang.String referrer)
          Set the referrer.
 void setSampleRate(double sampleRate)
          Sets the sample rate.
 void setStartSession(boolean startSession)
          Specifies whether a new session should be started.
 void setUseSecure(boolean useSecure)
          Determines whether hits are sent securely.
 void trackEvent(java.lang.String category, java.lang.String action, java.lang.String label, java.lang.Long value)
          Tracks an event.
 void trackException(java.lang.String description, boolean fatal)
          Tracks that an exception occurred.
 void trackException(java.lang.String threadName, java.lang.Throwable exception, boolean fatal)
          Tracks that an exception occurred.
 void trackSocial(java.lang.String network, java.lang.String action, java.lang.String target)
          Tracks a social hit.
 void trackTiming(java.lang.String category, long intervalInMilliseconds, java.lang.String name, java.lang.String label)
          Tracks a user timing hit.
 void trackTransaction(Transaction transaction)
          Tracks an eCommerce transaction.
 void trackView()
          Tracks entering a view with the current app screen name.
 void trackView(java.lang.String appScreen)
          Tracks entering a view with a new app screen name.
 

Method Detail

setStartSession

void setStartSession(boolean startSession)
Specifies whether a new session should be started. This method does not send a hit, but will add a parameters to the next hit marking it as the beginning of a new session if the input parameter is true.

If you don't explicitly mark session starts by calling setStartSession with a value of true, sessions will be created automatically on the backend.

By default, trackers are created with startSession set to true.

Parameters:
startSession - true if a new session should be started with the next hit

setAppName

void setAppName(java.lang.String appName)
Set the application name to appName. If not set, the Tracker will use the package name.

Note that if this method is called after any tracking activity has happened, the call will be ignored.


setAppVersion

void setAppVersion(java.lang.String appVersion)
Set the application version to appVersion. If not set, the Tracker will use the version reported in the package.

Note that if this method is called after any tracking activity has happened, the call will be ignored.


setAppScreen

void setAppScreen(java.lang.String appScreen)
Stores the place to be sent with subsequent track calls.

Parameters:
appScreen - the new app screen name (null or empty string clears any existing app screen name)

trackView

void trackView()
Tracks entering a view with the current app screen name.


trackView

void trackView(java.lang.String appScreen)
Tracks entering a view with a new app screen name.

Parameters:
appScreen - the new app screen name

trackEvent

void trackEvent(java.lang.String category,
                java.lang.String action,
                java.lang.String label,
                java.lang.Long value)
Tracks an event. Events have a category, action, label and value. This method can be used to track events such as button presses or other user interactions with your application.

Parameters:
category - the event category
action - the event action
label - the event label
value - the event value. Pass null if no value is to be set.

trackTransaction

void trackTransaction(Transaction transaction)
Tracks an eCommerce transaction.


trackException

void trackException(java.lang.String description,
                    boolean fatal)
Tracks that an exception occurred. Note that the description is optional. If you don't want to send a description simply set the input parameter to null.

Parameters:
description - the type of exception
fatal - true if the exception is fatal

trackException

void trackException(java.lang.String threadName,
                    java.lang.Throwable exception,
                    boolean fatal)
Tracks that an exception occurred. The exception reported will be parsed using an ExceptionParser class set for this tracker. See setExceptionParser(com.google.analytics.tracking.android.ExceptionParser) and StandardExceptionParser.

Parameters:
threadName - the name of the @{link Thread} that got the exception, or null
exception - the Throwable to report
fatal - true if the exception is fatal

trackTiming

void trackTiming(java.lang.String category,
                 long intervalInMilliseconds,
                 java.lang.String name,
                 java.lang.String label)
Tracks a user timing hit. Category and label are optional.

Parameters:
category - the category of the timing
intervalInMilliseconds - the timing interval, in milliseconds
name - the optional name of the timing
label - the optional label

trackSocial

void trackSocial(java.lang.String network,
                 java.lang.String action,
                 java.lang.String target)
Tracks a social hit. Target is optional.

Parameters:
network - the social network
action - the social action
target - the social target

close

void close()
Closes the session. Call when you are done with the Tracker.


send

void send(java.lang.String hitType,
          java.util.Map<java.lang.String,java.lang.String> params)
Tracks the given hit. Note that hitType must be a value found in the ModelFields in order for that value to appear in the hit.

Parameters:
hitType - the type of the hit
params - map of hit data to values which are appended to the existing values which are already set (using set(java.lang.String, java.lang.String))

get

java.lang.String get(java.lang.String key)
Gets the model value for the given key. Returns null if no model value has been set.


set

void set(java.lang.String key,
         java.lang.String value)
Sets the model value for the given key. All subsequent track or send calls will send this key-value pair along as well.


getTrackingId

java.lang.String getTrackingId()
Returns:
the trackingId used by this Tracker

setAnonymizeIp

void setAnonymizeIp(boolean anonymizeIp)
Turns on or off anonymize IP mode. In anonymize IP mode, Google Analytics will anonymize the IP address information collected by zeroing out some of the least significant bits of the address. By default, this flag is disabled.

In the case of IPv4 addresses, the last octet is set to zero. For IPv6 addresses, the last 10 octets are set to zero, although this is subject to change in the future.

Parameters:
anonymizeIp - if true, turns on anonymize IP mode

anonymizeIpEnabled

boolean anonymizeIpEnabled()
Returns whether or not anonymize IP mode is on.


setSampleRate

void setSampleRate(double sampleRate)
Sets the sample rate. The sampleRate parameter controls the probability that the visitor will be sampled. By default, sampleRate is 100, which signifies no sampling. sampleRate may be set to any double value between 0 and 100, inclusive. A value of 90 requests 90% of visitors to be sampled (10% of visitors to be sampled out).

When a visitor is not sampled, no data is submitted to Google Analytics about that visitor's activity. If your application is subject to heavy traffic spikes, you may wish to adjust the sample rate to ensure uninterrupted report tracking. Sampling in Google Analytics occurs consistently across unique visitors, ensuring integrity in trending and reporting even when sampling is enabled, because unique visitors remain included or excluded from the sample, as set from the initiation of sampling.

Note that sampleRate can be set down to hundredths of a percent.

Parameters:
sampleRate - a value between 0.0 and 100.0

getSampleRate

double getSampleRate()
Returns the sample rate.


setUseSecure

void setUseSecure(boolean useSecure)
Determines whether hits are sent securely. If set, hits are sent using Https if possible. Otherwise, hits are sent using Http. Default is not secure.

Parameters:
useSecure - if true, use Https to send hits, otherwise use Http

getUseSecure

boolean getUseSecure()
Returns the current setting for useSecure.


setReferrer

void setReferrer(java.lang.String referrer)
Set the referrer. Note that referrer is similar to HTTP referrer. This field, if set, will be sent with the next hit for this tracker.

Parameters:
referrer - the new referrer information

setCampaign

void setCampaign(java.lang.String campaign)
Set the campaign. The input string may be a set of URL parameters or a full URL. The URL parameters may or may not be encoded. Valid campaign parameters are:

Implementations should handle input of the form http://my.site.com/index.html?utm_campaign=wow&utm_source=source as well as input of the form utm_campaign=wow&utm_source=source.

For more information on auto-tagging, see http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55590

For more information on manual tagging, see http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55518

Parameters:
campaign - the campaign information, as a sequence of URL parameters separated by &

setAppId

void setAppId(java.lang.String appId)
Set the appId. By default, the appId will be set to the packageName of the application. This works for Google Play, but other stores will have different appIds. This method allows changing the appId for other stores.

Parameters:
appId - the new appId or null

getAppId

java.lang.String getAppId()

setAppInstallerId

void setAppInstallerId(java.lang.String appInstallerId)
Set the id of the app that installed this app. By default, the app installer id will be set based on the PackageManager#getInstallerPackageName method.

Parameters:
appInstallerId - the new appInstallerId or null

getAppInstallerId

java.lang.String getAppInstallerId()

setExceptionParser

void setExceptionParser(ExceptionParser exceptionParser)
Sets the ExceptionParser to be used by this Tracker.


getExceptionParser

ExceptionParser getExceptionParser()
Returns:
the ExceptionParser currently in use for this Tracker.

setCustomDimension

void setCustomDimension(int slot,
                        java.lang.String value)
Sets the value for a custom dimension. Note that all custom dimensions are sent with the next hit and then cleared.

Parameters:
slot - the dimension slot
value - the dimension value, or null to clear a previously set value

setCustomMetric

void setCustomMetric(int slot,
                     java.lang.Long value)
Sets the value for a custom metric. Note that all custom metrics are sent with the next hit then cleared.

Parameters:
slot - the metric slot
value - the metric value, or null to clear a previously set value

setCustomDimensionsAndMetrics

void setCustomDimensionsAndMetrics(java.util.Map<java.lang.Integer,java.lang.String> dimensions,
                                   java.util.Map<java.lang.Integer,java.lang.Long> metrics)
Sets the values for several custom dimensions and metrics at once. Note that the custom dimension slot namespace is separate from the custom metric slot namespace.

Parameters:
dimensions - a Map of the custom dimension slots to custom dimension values
metrics - a Map of the custom metric slots to custom metric values

constructEvent

java.util.Map<java.lang.String,java.lang.String> constructEvent(java.lang.String category,
                                                                java.lang.String action,
                                                                java.lang.String label,
                                                                java.lang.Long value)
Creates model fields for an event. The results of this method can be used to call send(java.lang.String, java.util.Map).


constructTransaction

java.util.Map<java.lang.String,java.lang.String> constructTransaction(Transaction trans)
Creates model fields for a transaction. The results of this method can be used to call send(java.lang.String, java.util.Map).


constructException

java.util.Map<java.lang.String,java.lang.String> constructException(java.lang.String exceptionDescription,
                                                                    boolean fatal)
Creates model fields for an exception. The results of this method can be used to call send(java.lang.String, java.util.Map).


constructRawException

java.util.Map<java.lang.String,java.lang.String> constructRawException(java.lang.String threadName,
                                                                       java.lang.Throwable exception,
                                                                       boolean fatal)
                                                                       throws java.io.IOException
Creates model fields for an exception. The results of this method can be used to call send(java.lang.String, java.util.Map).

Throws:
java.io.IOException

constructTiming

java.util.Map<java.lang.String,java.lang.String> constructTiming(java.lang.String category,
                                                                 long intervalInMilliseconds,
                                                                 java.lang.String name,
                                                                 java.lang.String label)
Creates model fields for timing. The results of this method can be used to call send(java.lang.String, java.util.Map).


constructSocial

java.util.Map<java.lang.String,java.lang.String> constructSocial(java.lang.String network,
                                                                 java.lang.String action,
                                                                 java.lang.String target)
Creates model fields for social. The results of this method can be used to call send(java.lang.String, java.util.Map).