SDK Methods
All public methods and properties of the Android SDK 2.0.0. Each entry links to its description on the topic page, with parameters and examples. Everything is in the package com.user.sdk, except ProductEventType in com.user.sdk.events.
Setup
| Method or property | What it does |
|---|---|
UserCom.initialize(application, apiKey, baseUrl, fcmToken) | Creates the SDK instance and sets UserCom.default. Sends nothing by itself. fcmToken is optional. |
UserCom.default | The shared SDK instance, null before initialize. In Java UserCom.getDefault(). |
setFcmToken(token) | Stores the FCM token and sends a ping. |
Contact
| Method or property | What it does |
|---|---|
ping(fcmToken, callback) | Creates or updates the contact with device data. Both parameters are optional. |
updateContact(contact, fcmToken, callback) | Adds the data of a Contact to the current contact, with an optional FCM token, in one request. |
Contact | Contact data: userId, email, firstName, lastName, phoneNumber, attributes. |
logout(fcmToken, callback) | Records a logout and starts a new anonymous contact that keeps the push token. |
userKey | The key of the current contact in Positive User. |
Events
| Method | What it does |
|---|---|
sendEvent(name, attributes, callback) | Sends a custom event. |
trackScreen(name, callback) | Sends a screen event with a name you choose. |
sendProductEvent(productId, eventType, attributes, callback) | Sends a product event. |
ProductEventType | The product event types. |
attributes and callback are optional in every method.
Push notifications
| Method or constant | What it does |
|---|---|
handleNotification(data) | Passes a received FCM message to the SDK: shows push notifications in the foreground and in-app messages, never counts a click. Returns whether the message is from Positive User. |
handleNotificationClick(intent) | Passes the intent of your launcher activity to the SDK: counts a new tap once. Returns true only for a new tap. |
isUserComNotification(data) | Checks whether message data is a Positive User message. |
UserCom.NOTIFICATION_CHANNEL_ID | The ID of the notification channel, for creating it with your own settings. |
In-app messages
| Property | What it does |
|---|---|
UserCom.inAppMessagesEnabled | Pauses and resumes in-app messages. Static, default true. |
inAppMessageClickHandler | Receives button links before the SDK opens them. |
fontResolver | Provides custom fonts for message text. |
customTabsIntent | The Custom Tabs used to open web links, or null for the browser. |
Email links
| Method | What it does |
|---|---|
handleEmailLink(url, callback) | Counts the click on a link from a Positive User email that opened the app and returns the target of the link. Also available as a suspend function. |
Errors
| Type or property | What it does |
|---|---|
UserComError | The error every failure reports, with code 1 to 8. |
UserCom.errorHandler | Receives every error on the main thread, also from calls without a callback. |
Logs
| Property | What it does |
|---|---|
UserCom.debugLogging | Turns SDK logs on. Static, default false. |
UserCom.logger | Receives SDK logs instead of Logcat, while debugLogging is on. Static. |
SDK logs never contain keys, tokens, request bodies or contact data. Without a logger, they go to Logcat with the tag UserCom. With a logger, the SDK passes each line with its Android log priority, for example to Timber:
UserCom.debugLogging = BuildConfig.DEBUG
UserCom.logger = UserComLogger { priority, message -> Timber.tag("UserCom").log(priority, message) }
In Java: UserCom.setDebugLogging(true), UserCom.setLogger((priority, message) -> ...), UserCom.setErrorHandler(error -> ...).
Callbacks
All callbacks are fun interface types, so you can pass a Kotlin lambda or a Java lambda.
| Type | Method | Used by |
|---|---|---|
UserComCallback | onResult(error: UserComError?), null on success | ping, updateContact, logout, sendEvent, trackScreen, sendProductEvent |
UserComErrorHandler | onError(error: UserComError) | UserCom.errorHandler |
InAppMessageClickHandler | onClick(url: Uri): Boolean | inAppMessageClickHandler |
InAppFontResolver | resolveFont(name: String, size: Float): Typeface? | fontResolver |
EmailLinkCallback | onResult(target: Uri?) | handleEmailLink |
UserComLogger | log(priority: Int, message: String) | UserCom.logger |
Every callback runs on the main thread, and never before the call returns.
Deprecated
These still work and stay until 3.0. See the Migration Guide.
| Deprecated | Use instead |
|---|---|
UserCom.Builder(application, apiKey, integrationsApiKey, baseUrl)...build() | UserCom.initialize(application, apiKey, baseUrl) and ping(). build() still sends a ping. |
Builder.trackAllActivities(true) | trackScreen(name) |
Builder.setDefaultCustomer(customer), Builder.setOnSdkInitializedListener(listener) | updateContact(contact, fcmToken, callback) |
Builder.openLinksInChromeCustomTabs, Builder.setCustomTabsBuilder | customTabsIntent |
UserCom.getInstance() | UserCom.default. getInstance() throws when the SDK is not initialized. |
register(Customer, CustomerUpdateCallback), Customer | updateContact(contact, fcmToken, callback), Contact |
onNotification(Context, RemoteMessage) | handleNotification(remoteMessage.data) |
handleRouteFromNotification(Intent) | handleNotificationClick(intent) |
setInAppNotificationClickHandler(ClickHandler) | inAppMessageClickHandler |
setFontResolver(FontResolver) | fontResolver |
@ScreenName | trackScreen(name) |
@TrackArguments | None. Has no effect. |