Skip to main content

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 propertyWhat it does
UserCom.initialize(application, apiKey, baseUrl, fcmToken)Creates the SDK instance and sets UserCom.default. Sends nothing by itself. fcmToken is optional.
UserCom.defaultThe shared SDK instance, null before initialize. In Java UserCom.getDefault().
setFcmToken(token)Stores the FCM token and sends a ping.

Contact​

Method or propertyWhat 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.
ContactContact data: userId, email, firstName, lastName, phoneNumber, attributes.
logout(fcmToken, callback)Records a logout and starts a new anonymous contact that keeps the push token.
userKeyThe key of the current contact in Positive User.

Events​

MethodWhat 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.
ProductEventTypeThe product event types.

attributes and callback are optional in every method.


Push notifications​

Method or constantWhat 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_IDThe ID of the notification channel, for creating it with your own settings.

In-app messages​

PropertyWhat it does
UserCom.inAppMessagesEnabledPauses and resumes in-app messages. Static, default true.
inAppMessageClickHandlerReceives button links before the SDK opens them.
fontResolverProvides custom fonts for message text.
customTabsIntentThe Custom Tabs used to open web links, or null for the browser.
MethodWhat 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 propertyWhat it does
UserComErrorThe error every failure reports, with code 1 to 8.
UserCom.errorHandlerReceives every error on the main thread, also from calls without a callback.

Logs​

PropertyWhat it does
UserCom.debugLoggingTurns SDK logs on. Static, default false.
UserCom.loggerReceives 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.

TypeMethodUsed by
UserComCallbackonResult(error: UserComError?), null on successping, updateContact, logout, sendEvent, trackScreen, sendProductEvent
UserComErrorHandleronError(error: UserComError)UserCom.errorHandler
InAppMessageClickHandleronClick(url: Uri): BooleaninAppMessageClickHandler
InAppFontResolverresolveFont(name: String, size: Float): Typeface?fontResolver
EmailLinkCallbackonResult(target: Uri?)handleEmailLink
UserComLoggerlog(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.

DeprecatedUse 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.setCustomTabsBuildercustomTabsIntent
UserCom.getInstance()UserCom.default. getInstance() throws when the SDK is not initialized.
register(Customer, CustomerUpdateCallback), CustomerupdateContact(contact, fcmToken, callback), Contact
onNotification(Context, RemoteMessage)handleNotification(remoteMessage.data)
handleRouteFromNotification(Intent)handleNotificationClick(intent)
setInAppNotificationClickHandler(ClickHandler)inAppMessageClickHandler
setFontResolver(FontResolver)fontResolver
@ScreenNametrackScreen(name)
@TrackArgumentsNone. Has no effect.