public class Tracker
extends java.lang.Object
GoogleAnalytics.getTracker(java.lang.String)
.
Only track calls queue hits to be dispatched.
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the
Tracker . |
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 |
isAnonymizeIpEnabled()
Returns whether or not anonymize IP mode is on.
|
boolean |
isUseSecure()
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 |
sendEvent(java.lang.String category,
java.lang.String action,
java.lang.String label,
java.lang.Long value)
Tracks an event.
|
void |
sendException(java.lang.String description,
boolean fatal)
Tracks that an exception occurred.
|
void |
sendException(java.lang.String threadName,
java.lang.Throwable exception,
boolean fatal)
Tracks that an exception occurred.
|
void |
sendSocial(java.lang.String network,
java.lang.String action,
java.lang.String target)
Tracks a social hit.
|
void |
sendTiming(java.lang.String category,
long intervalInMilliseconds,
java.lang.String name,
java.lang.String label)
Tracks a user timing hit.
|
void |
sendTransaction(Transaction transaction)
Tracks an eCommerce transaction.
|
void |
sendView()
Tracks entering a view with the current app screen name.
|
void |
sendView(java.lang.String appScreen)
Tracks entering a view with a new app screen name.
|
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 index,
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 index,
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 |
setThrottlingEnabled(boolean throttlingEnabled) |
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)
Deprecated.
|
void |
trackException(java.lang.String description,
boolean fatal)
Deprecated.
|
void |
trackException(java.lang.String threadName,
java.lang.Throwable exception,
boolean fatal)
Deprecated.
|
void |
trackSocial(java.lang.String network,
java.lang.String action,
java.lang.String target)
Deprecated.
|
void |
trackTiming(java.lang.String category,
long intervalInMilliseconds,
java.lang.String name,
java.lang.String label)
Deprecated.
|
void |
trackTransaction(Transaction transaction)
Deprecated.
|
void |
trackView()
Deprecated.
|
void |
trackView(java.lang.String appScreen)
Deprecated.
|
public void setStartSession(boolean startSession)
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.
startSession
- true if a new session should be started with the next hitpublic void setAppName(java.lang.String appName)
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.
public void setAppVersion(java.lang.String appVersion)
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.
public void setAppScreen(java.lang.String appScreen)
appScreen
- the new app screen name (null or empty string clears any existing app screen
name)@Deprecated public void trackView()
sendView()
.public void sendView()
@Deprecated public void trackView(java.lang.String appScreen)
sendView()
.public void sendView(java.lang.String appScreen)
appScreen
- the new app screen name@Deprecated public void trackEvent(java.lang.String category, java.lang.String action, java.lang.String label, java.lang.Long value)
sendEvent(java.lang.String, java.lang.String, java.lang.String, java.lang.Long)
.public void sendEvent(java.lang.String category, java.lang.String action, java.lang.String label, java.lang.Long value)
category
- the event categoryaction
- the event actionlabel
- the event labelvalue
- the event value. Pass null if no value is to be set.@Deprecated public void trackTransaction(Transaction transaction)
sendTransaction(com.google.analytics.tracking.android.Transaction)
.public void sendTransaction(Transaction transaction)
@Deprecated public void trackException(java.lang.String description, boolean fatal)
sendException(java.lang.String, boolean)
.public void sendException(java.lang.String description, boolean fatal)
description
- the type of exceptionfatal
- true if the exception is fatal@Deprecated public void trackException(java.lang.String threadName, java.lang.Throwable exception, boolean fatal)
sendException(java.lang.String, boolean)
.public void sendException(java.lang.String threadName, java.lang.Throwable exception, boolean fatal)
ExceptionParser
class set for this tracker. See setExceptionParser(com.google.analytics.tracking.android.ExceptionParser)
and
StandardExceptionParser
.threadName
- the name of the @{link Thread} that got the exception, or nullexception
- the Throwable
to reportfatal
- true if the exception is fatal@Deprecated public void trackTiming(java.lang.String category, long intervalInMilliseconds, java.lang.String name, java.lang.String label)
sendTiming(java.lang.String, long, java.lang.String, java.lang.String)
.public void sendTiming(java.lang.String category, long intervalInMilliseconds, java.lang.String name, java.lang.String label)
category
- the category of the timingintervalInMilliseconds
- the timing interval, in millisecondsname
- the optional name of the timinglabel
- the optional label@Deprecated public void trackSocial(java.lang.String network, java.lang.String action, java.lang.String target)
sendSocial(java.lang.String, java.lang.String, java.lang.String)
.public void sendSocial(java.lang.String network, java.lang.String action, java.lang.String target)
network
- the social networkaction
- the social actiontarget
- the social target, may be nullpublic void close()
public void send(java.lang.String hitType, java.util.Map<java.lang.String,java.lang.String> params)
ModelFields
in
order for that value to appear in the hit.hitType
- the type of the hitparams
- 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)
)public java.lang.String get(java.lang.String key)
public void set(java.lang.String key, java.lang.String value)
public java.lang.String getTrackingId()
trackingId
used by this Tracker
public void setAnonymizeIp(boolean anonymizeIp)
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.
anonymizeIp
- if true, turns on anonymize IP modepublic boolean isAnonymizeIpEnabled()
public void setSampleRate(double sampleRate)
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.
sampleRate
- a value between 0.0 and 100.0public double getSampleRate()
public void setUseSecure(boolean useSecure)
useSecure
- if true, use Https to send hits, otherwise use Httppublic boolean isUseSecure()
public void setReferrer(java.lang.String referrer)
referrer
- the new referrer informationpublic void setCampaign(java.lang.String campaign)
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
campaign
- the campaign information, as a sequence of URL parameters separated by &public void setAppId(java.lang.String appId)
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.appId
- the new appId
or nullpublic java.lang.String getAppId()
public void setAppInstallerId(java.lang.String appInstallerId)
PackageManager#getInstallerPackageName
method.appInstallerId
- the new appInstallerId
or nullpublic java.lang.String getAppInstallerId()
public void setExceptionParser(ExceptionParser exceptionParser)
ExceptionParser
to be used by this Tracker.public ExceptionParser getExceptionParser()
ExceptionParser
currently in use for this Tracker.public void setCustomDimension(int index, java.lang.String value)
index
- the dimension indexvalue
- the dimension valuepublic void setCustomMetric(int index, java.lang.Long value)
index
- the metric indexvalue
- the metric value, or null to clear a previously set valuepublic void setCustomDimensionsAndMetrics(java.util.Map<java.lang.Integer,java.lang.String> dimensions, java.util.Map<java.lang.Integer,java.lang.Long> metrics)
dimensions
- a Map of the custom dimension indices to custom dimension valuesmetrics
- a Map of the custom metric indices to custom metric valuespublic 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)
send(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)
.public java.util.Map<java.lang.String,java.lang.String> constructTransaction(Transaction trans)
send(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)
.public java.util.Map<java.lang.String,java.lang.String> constructException(java.lang.String exceptionDescription, boolean fatal)
send(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)
.public java.util.Map<java.lang.String,java.lang.String> constructRawException(java.lang.String threadName, java.lang.Throwable exception, boolean fatal) throws java.io.IOException
send(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)
.java.io.IOException
public java.util.Map<java.lang.String,java.lang.String> constructTiming(java.lang.String category, long intervalInMilliseconds, java.lang.String name, java.lang.String label)
send(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)
.public java.util.Map<java.lang.String,java.lang.String> constructSocial(java.lang.String network, java.lang.String action, java.lang.String target)
send(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)
.public void setThrottlingEnabled(boolean throttlingEnabled)