public class Analytics
extends java.lang.Object
with(android.content.Context)
for the global singleton instance or construct your own instance
with Analytics.Builder
.Modifier and Type | Class and Description |
---|---|
static class |
Analytics.Builder
Fluent API for creating
Analytics instances. |
static class |
Analytics.BundledIntegration |
static interface |
Analytics.Callback
A callback interface that is invoked when the Analytics client initializes bundled
integrations.
|
static class |
Analytics.LogLevel
Controls the level of logging.
|
Modifier and Type | Method and Description |
---|---|
void |
alias(java.lang.String newId)
The alias method is used to merge two user identities, effectively connecting two sets of user
data as one.
|
void |
alias(java.lang.String newId,
Options options)
The alias method is used to merge two user identities, effectively connecting two sets of user
data as one.
|
void |
flush()
Asynchronously flushes all messages in the queue to the server, and tells bundled integrations
to do the same.
|
AnalyticsContext |
getAnalyticsContext()
Get the
AnalyticsContext used by this instance. |
android.app.Application |
getApplication()
Return the
Application used to create this instance. |
Log |
getLogger()
Return the
Log instance used by this client. |
Analytics.LogLevel |
getLogLevel()
Deprecated.
This will be removed in a future release.
|
StatsSnapshot |
getSnapshot()
Creates a
StatsSnapshot of the current stats for this instance. |
void |
group(java.lang.String groupId)
The group method lets you associate a user with a group.
|
void |
group(java.lang.String groupId,
Traits groupTraits,
Options options)
The group method lets you associate a user with a group.
|
void |
identify(java.lang.String userId)
Identify lets you tie one of your users and their actions to a recognizable
userId . |
void |
identify(java.lang.String userId,
Traits newTraits,
Options options)
Identify lets you tie one of your users and their actions to a recognizable
userId . |
void |
identify(Traits traits)
Identify lets you tie one of your users and their actions to a recognizable
userId . |
void |
logout()
Deprecated.
Use
reset() instead |
void |
onIntegrationReady(Analytics.BundledIntegration bundledIntegration,
Analytics.Callback callback)
Register to be notified when a bundled integration is ready.
|
void |
reset()
Resets the analytics client by clearing any stored information about the user.
|
void |
screen(java.lang.String category,
java.lang.String name) |
void |
screen(java.lang.String category,
java.lang.String name,
Properties properties) |
void |
screen(java.lang.String category,
java.lang.String name,
Properties properties,
Options options)
The screen methods let your record whenever a user sees a screen of your mobile app, and
attach
a name, category or properties to the screen.
|
static void |
setSingletonInstance(Analytics analytics)
Set the global instance returned from
with(android.content.Context) . |
void |
shutdown()
Stops this instance from accepting further requests.
|
void |
track(java.lang.String event)
The track method is how you record any actions your users perform.
|
void |
track(java.lang.String event,
Properties properties)
The track method is how you record any actions your users perform.
|
void |
track(java.lang.String event,
Properties properties,
Options options)
The track method is how you record any actions your users perform.
|
static Analytics |
with(android.content.Context context)
Return a reference to the global default
Analytics instance. |
public static Analytics with(android.content.Context context)
Analytics
instance.
This instance is automatically initialized with defaults that are suitable to most
implementations.
If these settings do not meet the requirements of your application, you can override defaults
in analytics.xml
, or you can construct your own instance with full control over the
configuration by using Analytics.Builder
.
By default, events are uploaded every 30 seconds, or every 20 events (whichever occurs first),
and debugging is disabled.public static void setSingletonInstance(Analytics analytics)
with(android.content.Context)
.
This method must be called before any calls to with(android.content.Context)
and may only be called once.public void identify(java.lang.String userId)
userId
. It
also lets you record traits
about the user, like their email, name, account type, etc.
This method will simply set the userId for the current user.identify(String, Traits, Options)
public void identify(Traits traits)
userId
. It
also lets you record traits
about the user, like their email, name, account type, etc.
This method will simply add the given traits to the user profile.identify(String, Traits, Options)
public void identify(java.lang.String userId, Traits newTraits, Options options)
userId
. It
also lets you record traits
about the user, like their email, name, account type, etc.
Traits and userId will be automatically cached and available on future sessions for the same
user. To update a trait on the server, call identify with the same user id (or null). You can
also use identify(Traits)
for this purpose.userId
- Unique identifier which you recognize a user by in your own database. If this
is null or empty, any previous id we have (could be the anonymous id) will be
used.newTraits
- Traits about the useroptions
- To configure the calljava.lang.IllegalArgumentException
- if both userId
and newTraits
are not providedpublic void group(java.lang.String groupId)
group(String, Traits, Options)
public void group(java.lang.String groupId, Traits groupTraits, Options options)
identify(String, Traits, Options)
before, this will automatically
remember the userId. If not, it will fall back to use the anonymousId instead.groupId
- Unique identifier which you recognize a group by in your own database. Must not
be null or empty.options
- To configure the calljava.lang.IllegalArgumentException
- if groupId is null or an empty stringpublic void track(java.lang.String event)
track(String, Properties, Options)
public void track(java.lang.String event, Properties properties)
track(String, Properties, Options)
public void track(java.lang.String event, Properties properties, Options options)
event
- Name of the event. Must not be null or empty.properties
- Properties
to add extra information to this calloptions
- To configure the calljava.lang.IllegalArgumentException
- if event name is null or an empty stringpublic void screen(java.lang.String category, java.lang.String name)
public void screen(java.lang.String category, java.lang.String name, Properties properties)
public void screen(java.lang.String category, java.lang.String name, Properties properties, Options options)
category
- A category to describe the screenname
- A name for the screenproperties
- Properties
to add extra information to this calloptions
- To configure the callpublic void alias(java.lang.String newId)
alias(String, Options)
public void alias(java.lang.String newId, Options options)
Usage:
analytics.track("user did something");
analytics.alias(newId);
analytics.identify(newId);
newId
- The new ID you want to alias the existing ID to. The existing ID will be either
the previousId if you have called identify, or the anonymous ID.options
- To configure the calljava.lang.IllegalArgumentException
- if newId is null or emptypublic void flush()
public AnalyticsContext getAnalyticsContext()
AnalyticsContext
used by this instance.public StatsSnapshot getSnapshot()
StatsSnapshot
of the current stats for this instance.public android.app.Application getApplication()
Application
used to create this instance.@Deprecated public Analytics.LogLevel getLogLevel()
Analytics.LogLevel
for this instance.@Deprecated public void logout()
reset()
insteadpublic void reset()
public void shutdown()
public void onIntegrationReady(Analytics.BundledIntegration bundledIntegration, Analytics.Callback callback)
callback
will remove the previous callback for that integration.
The callback is invoked on the same thread we call integrations on, so if you want to update
the UI, make sure you move off to the main thread.
Usage:
analytics.onIntegrationReady(BundledIntegration.AMPLITUDE, new Callback() {
@Override public void onIntegrationReady(Object instance) {
Amplitude.enableLocationListening();
}
});
analytics.onIntegrationReady(BundledIntegration.MIXPANEL, new Callback() {
@Override public void onIntegrationReady(Object instance) {
((MixpanelAPI) instance).clearSuperProperties();
}
})*