public class RakamClient extends Object
Rakam.getInstance().logEvent();Rakam.getInstance().initialize(this, "APIKEY").enableForegroundTracking(getApplication())| Modifier and Type | Field and Description |
|---|---|
protected String |
apiKey
The Rakam App API key.
|
protected android.content.Context |
context
The Android App Context.
|
protected io.rakam.api.DatabaseHelper |
dbHelper
The shared Rakam database helper instance.
|
static String |
DEVICE_ID_KEY
The pref/database key for the device ID value.
|
protected String |
deviceId
The user's Device ID value.
|
static String |
END_SESSION_EVENT
The event type for end session events.
|
protected okhttp3.OkHttpClient |
httpClient
The shared OkHTTPClient instance.
|
protected boolean |
initialized |
protected String |
instanceName
The name for this instance of RakamClient.
|
static okhttp3.MediaType |
JSON |
static String |
LAST_EVENT_ID_KEY
The pref/database key for the last event ID value.
|
static String |
LAST_EVENT_TIME_KEY
The pref/database key for the last event time.
|
static String |
LAST_IDENTIFY_ID_KEY
The pref/database key for the last identify ID value.
|
static String |
OPT_OUT_KEY
The pref/database key for the opt out flag.
|
protected String |
platform
The device's Platform value.
|
static String |
PREVIOUS_SESSION_ID_KEY
The pref/database key for the previous session ID value.
|
static String |
START_SESSION_EVENT
The event type for start session events.
|
static String |
SUPER_PROPERTIES_KEY
The pref/database key for the super properties.
|
static String |
TAG
The class identifier tag used in logging.
|
static String |
USER_ID_KEY
The pref/database key for the user ID value.
|
protected String |
userId
The user's ID value.
|
| Constructor and Description |
|---|
RakamClient()
Instantiates a new default instance RakamClient and starts worker threads.
|
RakamClient(String instance)
Instantiates a new RakamClient and starts worker threads.
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
bytesToHexString(byte[] bytes)
Internal method to convert bytes to hex string
|
void |
clearSuperProperties()
Clear super properties.
|
void |
clearUserProperties()
Clear user properties.
|
protected boolean |
contextAndApiKeySet(String methodName)
Internal method to check whether application context and api key are set
|
RakamClient |
disableDiagnosticLogging() |
RakamClient |
disableLocationListening()
Disable location listening in the SDK.
|
RakamClient |
enableDiagnosticLogging() |
RakamClient |
enableForegroundTracking(android.app.Application app)
Enable foreground tracking for the SDK.
|
RakamClient |
enableLocationListening()
Enable location listening in the SDK.
|
RakamClient |
enableLogging(boolean enableLogging)
Enable/disable message logging by the SDK.
|
RakamClient |
enableNewDeviceIdPerInstall(boolean newDeviceIdPerInstall)
Deprecated.
|
String |
getApiUrl() |
protected long |
getCurrentTimeMillis()
Internal method to fetch the current time millis.
|
String |
getDeviceId()
Get the current device id.
|
long |
getSessionId()
Gets the current session id.
|
org.json.JSONObject |
getSuperProperties()
Get super property keys for the user.
|
Object |
getUserId()
Gets the user's id.
|
void |
identify(Identify identify)
Identify.
|
void |
identify(Identify identify,
boolean outOfSession)
Identify.
|
RakamClient |
initialize(android.content.Context context,
URL apiUrl,
String apiKey)
Initialize the Rakam SDK with the Android application context and your Rakam
App API key.
|
RakamClient |
initialize(android.content.Context context,
URL apiUrl,
String apiKey,
String userId)
Initialize the Rakam SDK with the Android application context and your Rakam
App API key.
|
RakamClient |
initialize(android.content.Context context,
URL apiUrl,
String apiKey,
String userId,
String platform,
boolean enableDiagnosticLogging)
Initialize the Rakam SDK with the Android application context, your Rakam App API
key, and a user ID for the current user.
|
boolean |
isOptedOut()
Returns whether or not the user is opted out of tracking.
|
void |
logEvent(String eventType)
Log an event with the specified event type.
|
void |
logEvent(String eventType,
org.json.JSONObject eventProperties)
Log an event with the specified event type and event properties.
|
void |
logEvent(String eventType,
org.json.JSONObject eventProperties,
boolean outOfSession)
Log an event with the specified event type and event properties.
|
protected long |
logEvent(String eventType,
org.json.JSONObject eventProperties,
long timestamp,
boolean outOfSession)
Log event.
|
protected void |
logEventAsync(String eventType,
org.json.JSONObject properties,
long timestamp,
boolean outOfSession)
Log event async.
|
void |
logEventSync(String eventType)
Log an event with the specified event type.
|
void |
logEventSync(String eventType,
org.json.JSONObject eventProperties)
Log an event with the specified event type and event properties.
|
void |
logEventSync(String eventType,
org.json.JSONObject eventProperties,
boolean outOfSession)
Log an event with the specified event type, event properties, with optional out of session
flag.
|
void |
logRevenue(Revenue revenue)
Log revenue.
|
protected void |
makeEventUploadPostRequest(okhttp3.OkHttpClient client,
String body,
long maxEventId,
long maxIdentifyId)
Internal method to generate the event upload post request.
|
protected android.util.Pair<android.util.Pair<Long,Long>,org.json.JSONArray> |
mergeEventsAndIdentifys(List<org.json.JSONObject> events,
List<org.json.JSONObject> identifys,
long numEvents)
Internal method to merge unsent events and identifies into a single array by sequence number.
|
RakamClient |
regenerateDeviceId()
Regenerates a new random deviceId for current user.
|
protected Object |
replaceWithJSONNull(Object obj)
Internal method to replace null event fields with JSON null object.
|
protected long |
saveEvent(String eventType,
org.json.JSONObject event)
Save event long.
|
void |
setApiUrl(URL apiUrl) |
RakamClient |
setDeviceId(String deviceId)
Sets a custom device id.
|
RakamClient |
setDiagnosticEventMaxCount(int eventMaxCount) |
RakamClient |
setEventMaxCount(int eventMaxCount)
Sets event max count.
|
RakamClient |
setEventUploadMaxBatchSize(int eventUploadMaxBatchSize)
Sets event upload max batch size.
|
RakamClient |
setEventUploadPeriodMillis(int eventUploadPeriodMillis)
Sets event upload period millis.
|
RakamClient |
setEventUploadThreshold(int eventUploadThreshold)
Sets event upload threshold.
|
RakamClient |
setFlushEventsOnClose(boolean flushEventsOnClose)
Enable/disable flushing of unsent events on app close (enabled by default).
|
RakamClient |
setLogLevel(int logLevel)
Sets the logging level.
|
RakamClient |
setMinTimeBetweenSessionsMillis(long minTimeBetweenSessionsMillis)
Sets min time between sessions millis.
|
RakamClient |
setOffline(boolean offline)
Sets offline.
|
RakamClient |
setOptOut(boolean optOut)
Sets opt out.
|
RakamClient |
setSessionTimeoutMillis(long sessionTimeoutMillis)
Sets session timeout millis.
|
RakamClient |
setSuperProperties(org.json.JSONObject superProperties)
Sets super property keys for the user.
|
RakamClient |
setTrackingOptions(TrackingOptions trackingOptions) |
RakamClient |
setUserId(int userId)
Sets the user id (can be null).
|
RakamClient |
setUserId(String userId)
Sets the user id (can be null).
|
RakamClient |
setUserId(String userId,
boolean startNewSession)
Sets the user id (can be null).
|
void |
setUserProperties(org.json.JSONObject userProperties)
Sets user properties.
|
void |
setUserProperties(org.json.JSONObject userProperties,
boolean replace)
Deprecated.
|
boolean |
startNewSessionIfNeeded(long timestamp)
Public method to start a new session if needed.
|
RakamClient |
trackSessionEvents(boolean trackingSessionEvents)
Track session events rakam client.
|
org.json.JSONArray |
truncate(org.json.JSONArray array)
Truncate values in a JSON array.
|
org.json.JSONObject |
truncate(org.json.JSONObject object)
Truncate values in a JSON object.
|
protected void |
updateServer()
Internal method to upload unsent events.
|
protected void |
updateServer(boolean limit)
Internal method to upload unsent events.
|
void |
uploadEvents()
Force SDK to upload any unsent events.
|
RakamClient |
useAdvertisingIdForDeviceId()
Whether to use the Android advertising ID (ADID) as the user's device ID.
|
protected boolean |
validateLogEvent(String eventType)
Validate the event type being logged.
|
public static final okhttp3.MediaType JSON
public static final String TAG
"RakamClient";public static final String START_SESSION_EVENT
public static final String END_SESSION_EVENT
public static final String DEVICE_ID_KEY
public static final String USER_ID_KEY
public static final String SUPER_PROPERTIES_KEY
public static final String OPT_OUT_KEY
public static final String LAST_EVENT_TIME_KEY
public static final String LAST_EVENT_ID_KEY
public static final String LAST_IDENTIFY_ID_KEY
public static final String PREVIOUS_SESSION_ID_KEY
protected android.content.Context context
protected okhttp3.OkHttpClient httpClient
protected io.rakam.api.DatabaseHelper dbHelper
protected String apiKey
protected String instanceName
protected String userId
protected String deviceId
protected boolean initialized
protected String platform
public RakamClient()
public RakamClient(String instance)
public RakamClient initialize(android.content.Context context, URL apiUrl, String apiKey)
context - the Android application contextapiUrl - your Rakam API UrlapiKey - your Rakam App API keypublic RakamClient initialize(android.content.Context context, URL apiUrl, String apiKey, String userId)
context - the Android application contextapiUrl - your Rakam API UrlapiKey - your Rakam App API keyuserId - your Application User Idpublic RakamClient initialize(android.content.Context context, URL apiUrl, String apiKey, String userId, String platform, boolean enableDiagnosticLogging)
context - the Android application contextapiUrl - your Rakam App API UrlapiKey - your Rakam App API keyuserId - your Application User Idplatform - The platform nameenableDiagnosticLogging - Enable error tracking to Rakam APIspublic RakamClient setSuperProperties(org.json.JSONObject superProperties)
superProperties - Super propertiespublic org.json.JSONObject getSuperProperties()
public RakamClient enableForegroundTracking(android.app.Application app)
app - the Android applicationpublic RakamClient enableDiagnosticLogging()
public RakamClient disableDiagnosticLogging()
public RakamClient setDiagnosticEventMaxCount(int eventMaxCount)
public RakamClient enableNewDeviceIdPerInstall(boolean newDeviceIdPerInstall)
newDeviceIdPerInstall - whether to set a new device ID on app install.public RakamClient useAdvertisingIdForDeviceId()
public RakamClient enableLocationListening()
public RakamClient disableLocationListening()
public RakamClient setEventUploadThreshold(int eventUploadThreshold)
eventUploadThreshold - the event upload thresholdpublic RakamClient setEventUploadMaxBatchSize(int eventUploadMaxBatchSize)
eventUploadMaxBatchSize - the event upload max batch sizepublic RakamClient setEventMaxCount(int eventMaxCount)
eventMaxCount - the event max countpublic RakamClient setEventUploadPeriodMillis(int eventUploadPeriodMillis)
eventUploadPeriodMillis - the event upload period millispublic RakamClient setMinTimeBetweenSessionsMillis(long minTimeBetweenSessionsMillis)
minTimeBetweenSessionsMillis - the min time between sessions millispublic RakamClient setSessionTimeoutMillis(long sessionTimeoutMillis)
sessionTimeoutMillis - the session timeout millispublic RakamClient setTrackingOptions(TrackingOptions trackingOptions)
public RakamClient setOptOut(boolean optOut)
optOut - whether or not to opt the user out of trackingpublic boolean isOptedOut()
public RakamClient enableLogging(boolean enableLogging)
enableLogging - whether to enable message logging by the SDK.public RakamClient setLogLevel(int logLevel)
logLevel - the log levelpublic RakamClient setOffline(boolean offline)
offline - whether or not the SDK should be offlinepublic RakamClient setFlushEventsOnClose(boolean flushEventsOnClose)
flushEventsOnClose - whether to flush unsent events on app closepublic RakamClient trackSessionEvents(boolean trackingSessionEvents)
trackingSessionEvents - whether to enable tracking of session eventspublic void logEvent(String eventType)
eventType - the event typepublic void logEvent(String eventType, org.json.JSONObject eventProperties)
eventType - the event typeeventProperties - the event propertiespublic void logEvent(String eventType, org.json.JSONObject eventProperties, boolean outOfSession)
eventType - the event typeeventProperties - the event propertiesoutOfSession - the out of sessionpublic void logEventSync(String eventType)
eventType - the event typepublic void logEventSync(String eventType, org.json.JSONObject eventProperties)
eventType - the event typeeventProperties - the event propertiespublic void logEventSync(String eventType, org.json.JSONObject eventProperties, boolean outOfSession)
eventType - the event typeeventProperties - the event propertiesoutOfSession - the out of sessionprotected boolean validateLogEvent(String eventType)
eventType - the event typeprotected void logEventAsync(String eventType, org.json.JSONObject properties, long timestamp, boolean outOfSession)
eventType - the event typeproperties - the request propertiestimestamp - the timestampoutOfSession - the out of sessionprotected long logEvent(String eventType, org.json.JSONObject eventProperties, long timestamp, boolean outOfSession)
eventType - the event typeeventProperties - the event propertiestimestamp - the timestampoutOfSession - the out of sessionprotected long saveEvent(String eventType, org.json.JSONObject event)
eventType - the event typeevent - the eventpublic long getSessionId()
public boolean startNewSessionIfNeeded(long timestamp)
timestamp - the timestamppublic void logRevenue(Revenue revenue)
Revenue object to hold your revenue data and
properties, and log it as a revenue event using logRevenue.revenue - a Revenue objectRevenue,
Tracking Revenuepublic void setUserProperties(org.json.JSONObject userProperties,
boolean replace)
Identify API to set multiple user properties with a single
command. Note: the replace parameter is deprecated and has no effect.userProperties - the user propertiesreplace - the replace - has no effectpublic void setUserProperties(org.json.JSONObject userProperties)
Identify API to set multiple user properties with a single
command.userProperties - the user propertiespublic void clearUserProperties()
public void clearSuperProperties()
public void identify(Identify identify)
Identify object containing
user property operations to Rakam server.identify - an Identify objectIdentify,
User Propertiespublic void identify(Identify identify, boolean outOfSession)
Identify object containing
user property operations to Rakam server. If outOfSession is true, then the identify
event is sent with a session id of -1, and does not trigger any session-handling logic.identify - an Identify objectoutOfSession - whther to log the identify event out of sessionIdentify,
User Propertiespublic org.json.JSONObject truncate(org.json.JSONObject object)
object - the objectpublic org.json.JSONArray truncate(org.json.JSONArray array)
throws org.json.JSONException
array - the arrayorg.json.JSONException - the json exceptionpublic Object getUserId()
public RakamClient setUserId(String userId)
userId - the user idpublic RakamClient setUserId(String userId, boolean startNewSession)
userId - the user idpublic RakamClient setUserId(int userId)
userId - the user idpublic RakamClient setDeviceId(String deviceId)
deviceId - the device idpublic RakamClient regenerateDeviceId()
public void uploadEvents()
protected void updateServer()
protected void updateServer(boolean limit)
limit - the limitprotected android.util.Pair<android.util.Pair<Long,Long>,org.json.JSONArray> mergeEventsAndIdentifys(List<org.json.JSONObject> events, List<org.json.JSONObject> identifys, long numEvents) throws org.json.JSONException
events - the eventsidentifys - the identifysnumEvents - the num eventsorg.json.JSONException - the json exceptionprotected void makeEventUploadPostRequest(okhttp3.OkHttpClient client,
String body,
long maxEventId,
long maxIdentifyId)
client - the clientbody - request bodymaxEventId - the max event idmaxIdentifyId - the max identify idpublic String getDeviceId()
public String getApiUrl()
public void setApiUrl(URL apiUrl)
protected Object replaceWithJSONNull(Object obj)
obj - the objprotected boolean contextAndApiKeySet(String methodName)
methodName - the parent method name to print in error messageprotected String bytesToHexString(byte[] bytes)
bytes - the bytesprotected long getCurrentTimeMillis()
Copyright © 2019. All rights reserved.