public class AnalyticsClient extends Object implements com.amazonaws.mobileconnectors.pinpoint.internal.core.util.JSONSerializable
AnalyticsEvent objects are created, recorded, and submitted to the
Amazon Pinpoint Service. Recording Events Example:
// get the event client from your PinpointManager instance
AnalyticsClient analyticsClient = pinpointManager.getAnalyticsClient();
// create and record an event
Event level1CompleteEvent = analyticsClient.createEvent("level1Complete");
analyticsClient.recordEvent(level1CompleteEvent);
Submitting Events:
The example below demonstrates how to submit events to the Amazon Pinpoint
Service. You have direct control over when events are submitted in
your app. Events are submitted in a background thread.
Example:
// submit events to the website
AnalyticsClient analyticsClient = pinpointManager.getAnalyticsClient();
analyticsClient.submitEvents();
Amazon recommends that you call submitEvents once you stop the session.
Note: This client will store at most 5MiB of event data locally. Past that
events will be dropped. When events successfully submitted, they are removed
from the local database.| Constructor and Description |
|---|
AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext context)
A client to manage creating and sending analytics events.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addGlobalAttribute(String attributeName,
String attributeValue)
Adds the specified attribute to all subsequently created events Note: The
maximum allowed attributes and metrics on a single event is 40.
|
void |
addGlobalAttribute(String eventType,
String attributeName,
String attributeValue)
Adds the specified attribute to all subsequently created events with the
specified event type Note: The maximum allowed attributes and metrics on
a single event is 40.
|
void |
addGlobalMetric(String metricName,
Double metricValue)
Adds the specified metric to all subsequently created events Note: The
maximum allowed attributes and metrics on a single event is 40.
|
void |
addGlobalMetric(String eventType,
String metricName,
Double metricValue)
Adds the specified metric to all subsequently created events with the
specified event type Note: The maximum allowed attributes and metrics on
a single event is 40.
|
void |
closeDB()
Closes the database
|
AnalyticsEvent |
createEvent(String eventType)
Create an event with the specified eventType.
|
protected AnalyticsEvent |
createEvent(String eventType,
long sessionStart,
Long sessionEnd,
Long sessionDuration) |
List<org.json.JSONObject> |
getAllEvents()
Returns a list of all events
|
String |
getSessionId()
Get the current sessionId
|
long |
getSessionStartTime()
Get the session start time
|
void |
recordEvent(AnalyticsEvent event)
Record the specified event to the local filestore Please note if the
amount of data stored events takes up EXCEEDS 5MiB further recordings
will be dropped
|
void |
removeGlobalAttribute(String attributeName)
Removes the specified attribute.
|
void |
removeGlobalAttribute(String eventType,
String attributeName)
Removes the specified attribute.
|
void |
removeGlobalMetric(String metricName)
Removes the specified metric.
|
void |
removeGlobalMetric(String eventType,
String metricName)
Removes the specified metric.
|
void |
setCampaignAttributes(Map<String,String> campaign)
Deprecated.
|
void |
setSessionId(String sessionId)
Sets the sessionId
|
void |
setSessionStartTime(long sessionStartTime)
Set the session start time
|
void |
submitEvents()
Submit all recorded events.
|
org.json.JSONObject |
toJSONObject() |
String |
toString() |
void |
updateEventSourceGlobally(Map<String,String> attributes)
Replaces the current event source attributes (if any)
with a new set of event source attributes
|
public AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext context)
context - The PinpointContext of the Pinpoint Managerpublic AnalyticsEvent createEvent(String eventType)
eventType - the type of event to createprotected AnalyticsEvent createEvent(String eventType, long sessionStart, Long sessionEnd, Long sessionDuration)
public void recordEvent(AnalyticsEvent event)
event - The event to persistpublic void submitEvents()
PinpointConfiguration
for customizing which Internet connection the SDK can submit on.public void addGlobalAttribute(String attributeName, String attributeValue)
attributeName - the name of the attribute to addattributeValue - the value of the attributepublic void addGlobalAttribute(String eventType, String attributeName, String attributeValue)
eventType - the type of events to add the attribute toattributeName - the name of the attribute to addattributeValue - the value of the attributepublic void addGlobalMetric(String metricName, Double metricValue)
metricName - the name of the metric to addmetricValue - the value of the metricpublic void addGlobalMetric(String eventType, String metricName, Double metricValue)
eventType - the type of events to add the metric tometricName - the name of the metric to addmetricValue - the value of the metricpublic void removeGlobalAttribute(String attributeName)
attributeName - the name of the attribute to removepublic void removeGlobalAttribute(String eventType, String attributeName)
eventType - the type of events to remove the attribute fromattributeName - the name of the attribute to removepublic void removeGlobalMetric(String metricName)
metricName - the name of the metric to removepublic void removeGlobalMetric(String eventType, String metricName)
eventType - the type of events to remove the metric frommetricName - the name of the metric to remove@Deprecated public void setCampaignAttributes(Map<String,String> campaign)
updateEventSourceGlobally(Map)campaign - public void updateEventSourceGlobally(Map<String,String> attributes)
attributes - map of attribute valuespublic org.json.JSONObject toJSONObject()
toJSONObject in interface com.amazonaws.mobileconnectors.pinpoint.internal.core.util.JSONSerializablepublic void closeDB()
public List<org.json.JSONObject> getAllEvents()
public String getSessionId()
public void setSessionId(String sessionId)
sessionId - The sessionIdpublic long getSessionStartTime()
public void setSessionStartTime(long sessionStartTime)
sessionStartTime - The sessionStartTimeCopyright © 2020. All rights reserved.