public class RakamClient extends Object
Rakam.getInstance().logEvent();Rakam.getInstance().initialize(this, "APIKEY").enableForegroundTracking(getApplication())| Modifier and Type | Class and Description |
|---|---|
static interface |
RakamClient.CleanerFunction |
| 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 static RakamClient |
instance
The default shared instance.
|
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.
|
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 Object |
userId
The user's ID value.
|
| Constructor and Description |
|---|
RakamClient()
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 |
disableLocationListening()
Disable location listening in the SDK.
|
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.
|
protected long |
getCurrentTimeMillis()
Internal method to fetch the current time millis.
|
String |
getDeviceId()
Get the current device id.
|
static RakamClient |
getInstance()
Gets the default RakamClient instance.
|
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.
|
RakamClient |
initialize(android.content.Context context,
String apiKey)
Initialize the Rakam SDK with the Android application context and your Rakam
App API key.
|
RakamClient |
initialize(android.content.Context context,
String apiKey,
String userId)
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 endpoint,
String body,
long maxId,
RakamClient.CleanerFunction cleanerFunction)
Internal method to generate the event upload post request.
|
protected long |
recordAction(org.json.JSONObject event)
Save event log.
|
protected long |
recordIdentify(String identify) |
protected Object |
replaceWithJSONNull(Object obj)
Internal method to replace null event fields with JSON null object.
|
void |
setApiUrl(URL apiUrl) |
RakamClient |
setDeviceId(String deviceId)
Sets a custom device id.
|
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 |
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 |
setUserId(int userId)
Sets the user id (can be null).
|
RakamClient |
setUserId(long userId)
Sets the user id (can be null).
|
RakamClient |
setUserId(String userId)
Sets the user id (can be null).
|
void |
setUserProperties(org.json.JSONObject userProperties)
Sets user properties.
|
protected void |
syncEventsWithServer()
Internal method to upload unsent events.
|
protected void |
syncEventsWithServer(boolean limit)
Internal method to upload unsent events.
|
RakamClient |
trackSessionEvents(boolean trackingSessionEvents)
Track session events rakam client.
|
protected org.json.JSONArray |
truncate(org.json.JSONArray array)
Truncate values in a JSON array.
|
protected org.json.JSONObject |
truncate(org.json.JSONObject object)
Truncate values in a JSON object.
|
protected String |
truncate(String value)
Truncate a string to 1024 characters.
|
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 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 static RakamClient instance
Rakam.getInstance()protected android.content.Context context
protected okhttp3.OkHttpClient httpClient
protected io.rakam.api.DatabaseHelper dbHelper
protected String apiKey
protected Object userId
protected String deviceId
public RakamClient()
public static RakamClient getInstance()
public RakamClient initialize(android.content.Context context, String apiKey)
context - the Android application contextapiKey - your Rakam App API keypublic RakamClient setSuperProperties(org.json.JSONObject superProperties)
superProperties - Super propertiespublic org.json.JSONObject getSuperProperties()
public RakamClient initialize(android.content.Context context, String apiKey, String userId)
context - the Android application contextapiKey - your Rakam App API keyuserId - the user id to setpublic RakamClient enableForegroundTracking(android.app.Application app)
app - the Android applicationpublic 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 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 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 recordAction(org.json.JSONObject event)
event - the eventpublic long getSessionId()
public 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)
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 Propertiesprotected long recordIdentify(String identify)
protected org.json.JSONObject truncate(org.json.JSONObject object)
object - the objectprotected org.json.JSONArray truncate(org.json.JSONArray array)
throws org.json.JSONException
array - the arrayorg.json.JSONException - the json exceptionprotected String truncate(String value)
value - the valuepublic Object getUserId()
public RakamClient setUserId(String userId)
userId - the user idpublic RakamClient setUserId(long userId)
userId - the user idpublic RakamClient setUserId(int userId)
userId - the user idpublic RakamClient setDeviceId(String deviceId)
deviceId - the device idpublic void uploadEvents()
protected void syncEventsWithServer()
protected void syncEventsWithServer(boolean limit)
limit - the limitprotected void makeEventUploadPostRequest(okhttp3.OkHttpClient client,
String endpoint,
String body,
long maxId,
RakamClient.CleanerFunction cleanerFunction)
public String getDeviceId()
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 © 2016. All rights reserved.