java.lang.Object | |
↳ | com.google.android.gms.analytics.GoogleAnalytics |
This class is a singleton that provides methods for controlling global configuration
and creating Tracker
objects.
Applications can get an instance of this class by calling getInstance(Context)
.
Applications can optionally provide a metadata reference to a global configuration
XML resource file in the <application> element of their AndroidManifest.xml:
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/analytics_global_config" />The configuration file should be stored in the applications res/values/xml directory and look like this:
<?xml version="1.0" encoding="utf-8" ?> <resources> <string name="ga_appName">TestAppName</string> <string name="ga_appVersion">Version1.0</string> <string name="ga_logLevel">verbose</string> <integer name="ga_dispatchPeriod">1000</integer> <bool name="ga_dryRun">true</bool> </resources>Following is a complete list of globally scoped configuration values that can be specified:
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Dispatches queued hits (view, events, or transactions) to Google Analytics
if a network connection is available, and the local dispatching service is
in use.
| |||||||||||
On devices running API level 14 (ICE_CREAM_SANDWICH) or above, applications can
call this method in lieu of making explicit calls to
reportActivityStart(Activity)
and reportActivityStop(Activity) .
| |||||||||||
Returns whether the state of the application-level opt is on.
| |||||||||||
Get the instance of the
GoogleAnalytics class, creating it if necessary.
| |||||||||||
Return the current
Logger implementation in use.
| |||||||||||
Returns whether dry run mode is on.
| |||||||||||
Returns a
Tracker instance with the given trackingId .
| |||||||||||
Returns a
Tracker instance preconfigured with the values specified in
configResId .
| |||||||||||
Report the start of an
Activity , so that it can be tracked by any Tracker s
that have enabled auto activity tracking (see
enableAutoActivityTracking(boolean) .) This will also start a new session if
necessary.
| |||||||||||
Report the end of an
Activity .
| |||||||||||
Sets or resets the application-level opt out flag.
| |||||||||||
Toggles dry run mode.
| |||||||||||
Sets dispatch period for the local dispatcher.
| |||||||||||
Provide a custom implementation of
Logger to use.
|
[Expand]
Inherited Methods | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Dispatches queued hits (view, events, or transactions) to Google Analytics if a network connection is available, and the local dispatching service is in use. This method only works if local dispatching is in use. Local dispatching is only used in the absence of Google Play services on the device. In general, applications should not rely on the ability to dispatch hits manually.
On devices running API level 14 (ICE_CREAM_SANDWICH) or above, applications can
call this method in lieu of making explicit calls to reportActivityStart(Activity)
and reportActivityStop(Activity)
. This method is a noop if called on a device
running API level less than 14.
application | The Application whose activities starts and stops should be
automatically reported.
|
---|
Returns whether the state of the application-level opt is on.
Get the instance of the GoogleAnalytics
class, creating it if necessary.
Return the current Logger
implementation in use. If no Logger
has been set,
a default Logger
is provided that logs to android.util.Log
with Logger.LogLevel
set to WARNING
.
Returns whether dry run mode is on.
Returns a Tracker
instance with the given trackingId
. If the given
trackingId
is not null or empty, it will be set on the tracker and it is ready to
send hits. Calling newTracker() multiple times with the same trackingId
will
create multiple Tracker objects with the same trackingId
.
If the trackingId
is empty, you can still get a tracker, but you must
set the tracking id before sending any hits. This is useful if you do not know the tracking
id at the time of tracker creation, or if you want to use the same tracker instance to track
multiple tracking ids. Using the same instance to track multiple tracking ids is not
recommended since you need to be careful about not mixing the data you are sending to
multiple profiles. It can be useful if you have a lot of tracking ids and you want to avoid
object creation overhead involved in instantiating one tracker per tracking id.
trackingId | string of the form UA-xxxx-y |
---|
Returns a Tracker
instance preconfigured with the values specified in
configResId
. Calling newTracker() multiple times with the same
trackingId
will create multiple Tracker objects with the same configuration.
If the trackingId
is empty, you can still get a tracker, but you must
set the tracking id before sending any hits. This is useful if you do not know the tracking
id at the time of tracker creation, or if you want to use the same tracker instance to track
multiple tracking ids. Using the same instance to track multiple tracking ids is not
recommended since you need to be careful about not mixing the data you are sending to
multiple profiles. It can be useful if you have a lot of tracking ids and you want to avoid
object creation overhead involved in instantiating one tracker per tracking id.
configResId | The resource id of your tracker configuration file. See Tracker
for more information about what configuration elements can be included in that file.
|
---|
Report the start of an Activity
, so that it can be tracked by any Tracker
s
that have enabled auto activity tracking (see
enableAutoActivityTracking(boolean)
.) This will also start a new session if
necessary. This method should be called from the onStart()
method in each
Activity
in your application that you'd like to track.
If auto activity reports are enabled (see enableAutoActivityReports(Application)
)
on a device running API level 14 or above, this method will be a noop.
activity | the Activity that is to be tracked.
|
---|
Report the end of an Activity
. Note that this method should be called
from the onStop()
method in each Activity
in your application
that you'd like to track. For proper operation, this method must be called in all
Activities where reportActivityStart(Activity)
is called.
If auto activity reports are enabled (see enableAutoActivityReports(Application)
)
on a device running API level 14 or above, this method will be a noop.
activity | the Activity that is to be tracked.
|
---|
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 not persist across application starts. The correct value should thus be set in application initialization code.
optOut | true if application-level opt out should be enforced.
|
---|
Toggles dry run mode. In dry run mode, the normal code paths are executed locally, but hits are not sent to Google Analytics servers. This is useful for debugging calls to the Google Analytics SDK without polluting recorded data.
By default, this flag is disabled.
Sets dispatch period for the local dispatcher.
The dispatcher will check for hits to dispatch every dispatchPeriod
seconds. If zero or a negative dispatch period is given, automatic dispatch will
not be enabled, and the application will need to dispatch events
manually using dispatchLocalHits()
.
This method only works if local dispatching is in use. Local dispatching is only used in the
absence of Google Play services on the device. In general, applications should not rely on
the ability to dispatch hits manually.
dispatchPeriodInSeconds | the new dispatch period |
---|
Provide a custom implementation of Logger
to use. This custom Logger
will replace a default Logger
that logs to android.util.Log
.
logger | The Logger implementation to use for logging.
|
---|