java.lang.Object | |
↳ | com.google.android.gms.analytics.Tracker |
Class to send tracking hits to Google Analytics. You can get an instance of this class
by calling newTracker(int)
. A Tracker must be initialized with a tracking id
of an app profile before you can send any hits. You can change the id to send hits to
a different profile. Use this class to set values for measurement protocol parameters using the
setXYZ() methods. A param value set using set(String, String)
method is sent with
all subsequent hits until you overwrite it with another value or clear it by setting it
to null
. You can also override it by specifying a different value in a
send(Map
call. The values passed in the send(Map
are sent only with that hit.
The following example uses the HitBuilders.EventBuilder
helper class to build a param map
to pass to the send(Map
method.
Tracker t = GoogleAnalytics.getInstance(context).newTracker(trackingId); t.setScreenName(screenName); t.send(new HitBuilders.EventBuilder() .setCategory("UX") .setAction("click") .setLabel("someButtonName") .build()); t.send(new HitBuilders.EventBuilder() .setCategory("UX") .setAction("click") .setLabel("somePopupAction") .setScreenName("popupDialogName") .build());A
Tracker
can also be initialized with configuration values from an XML
resource file like this:
Tracker t = GoogleAnalytics.getInstance(ctx).newTracker(R.xml.tracker_config);Where R.xml.tracker_config is the resource id for an XML configuration file. The file should be stored in the app's res/values/xml/ directory and look like this:
<?xml version="1.0" encoding="utf-8" ?> <resources> <screenName name="com.google.foo.FirstActivity"> First Activity </screenName> <screenName name="com.google.foo.AnotherActivity"> Another Activity </screenName> <string name="ga_trackingId">UA-XXXX-Y</string> <string name="ga_sampleFrequency">99.8</string> <integer name="ga_sessionTimeout">2000</integer> <bool name="ga_autoActivityTracking">true</bool> <bool name="ga_anonymizeIp">true</bool> <bool name="ga_reportUncaughtExceptions">true</bool> </resources>Here is a complete list of tracker scoped configuration values that can be specified:
If ga_autoActivityTracking is enabled, an alternate screen name can be specified to substitute
for the full length canonical Activity
name in screen view hit. In order to
specify an alternate screen name use an <screenName> element, with
the name attribute specifying the canonical name, and the value the alias to use instead.
<screenName name="com.google.foo.SampleActivity">Sample Activity</screenName>
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Sets whether the advertising id and ad targeting preference should be collected while
sending hits to GA servers.
| |||||||||||
Enables or disables uncaught exception reporting for a given tracker.
| |||||||||||
Gets the model value for the given key.
| |||||||||||
Merges the model values set on this Tracker via
send(Map) with params and
generates a hit to be sent.
| |||||||||||
Sets the model value for the given key.
| |||||||||||
Sets the id of the App for analytics reports.
| |||||||||||
Sets the Installer Id of the App for analytics reports.
| |||||||||||
Sets the name of the App for analytics reports.
| |||||||||||
Sets the version identifier of the App for analytics reports.
| |||||||||||
Includes the campaign parameters contained in the URI referrer in the next hit.
| |||||||||||
Sets a particular client Id for the device.
| |||||||||||
Sets the language based on user's preferred locale.
| |||||||||||
Set the sample rate for all hits generated by the app.
| |||||||||||
Set the screen name to be associated with all subsequent hits.
| |||||||||||
Sets the screen resolution of the device.
| |||||||||||
Specify the time (in seconds) an app can stay in the background before a
new session is started.
| |||||||||||
Sets whether hits should be sent securely over https.
| |||||||||||
[Expand]
Inherited Methods | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Sets whether the advertising id and ad targeting preference should be collected while sending hits to GA servers. The collection of advertising id and the ad targeting preference is disabled by default and needs to be turned on for mobile audience features and any other features that require advertising id.
enabled | true if the advertising information should be collected. False otherwise. |
---|
Enables or disables uncaught exception reporting for a given tracker. This method is equivalent to using 'ga_reportUncaughtExceptions' in the tracker configuration file. Note that as with the configuration setting, only the uncaught exceptions are reported using this method.
Gets the model value for the given key. Returns null if no model value has been set.
Merges the model values set on this Tracker via send(Map)
with params
and
generates a hit to be sent. The hit may not be dispatched immediately. Note that the hit type
must set for the hit to be considered valid. More information on this can be found at
http://goo.gl/HVIXHR.
params | map of hit data to values which are merged with the existing values which are
already set (using set(String, String) ). Values in this map will override the values set earlier.
The values in this map will not be reused for the subsequent hits. If you need to send a
value in multiple hits, you can use the set(String, String) method.
|
---|
Sets the model value for the given key. All subsequent track or send calls will send this key-value pair along as well. To remove a particular field, simply set the value to null.
key | The key of the field that needs to be set. It starts with "&" followed by the parameter name. The complete list of fields can be found at http://goo.gl/M6dK2U. |
---|---|
value | A string value to be sent to Google servers. A null value denotes that the value should not be sent over wire. |
Sets the id of the App for analytics reports. This value is populated by default using the information provided by the android package manager. This value is usually the package name used by the app.
appId | String representing the name of the app. |
---|
Sets the Installer Id of the App for analytics reports. This value is populated by default using the information provided by the android package manager and the play store.
appInstallerId | String representing the name of the app. |
---|
Sets the name of the App for analytics reports. This value is populated by default using the information provided by the android package manager.
appName | String representing the name of the app. |
---|
Sets the version identifier of the App for analytics reports. This value is populated by default using the information provided by the android package manager.
appVersion | String representing the version of the app. |
---|
Includes the campaign parameters contained in the URI referrer in the next hit. If there is no referrer, or the referrer does not contain campaign parameters, this method does not add anything to the next hit.
Use this method to track in-app events driven by advertising with deep linking campaigns.
Valid campaign parameters are:
Example: http://my.site.com/index.html?referrer=utm_source%3Dsource%26utm_campaign%3Dwow
uri | the uri containing the referrer |
---|
Sets a particular client Id for the device. This Id should be a valid UUID (version 4) string as described in http://goo.gl/0dlrGx. If not specified, the SDK automatically generates one for you and sets it.
clientId | A valid version 4 UUID string. |
---|
Sets the language based on user's preferred locale. The string should be of the format ll-cc where ll is the language and cc is the country. If no value is provided, the default value from the android SDK is used.
language | string that denotes a particular language/locale. |
---|
Set the sample rate for all hits generated by the app. The sampling is done at app level. The default value is 100. To enable sampling, the minimum rate required is 0.01%.
sampleRate | A value between 0 and 100, specifying the percentage of devices that should send hits. |
---|
Set the screen name to be associated with all subsequent hits.
Sets the screen resolution of the device. If no resolution is specified, the default resolution from the android SDK is used.
width | integer representing the width in pixels. |
---|---|
height | integer representing the height in pixels. |
Specify the time (in seconds) an app can stay in the background before a new session is started. Setting this to a negative number will result in a new session never being started. Default is 30 seconds.
sessionTimeout | Session timeout time in seconds. |
---|
Sets whether hits should be sent securely over https. The default value is true.