Skip to main content

SDK Methods

Complete reference for the Positive User Android SDK public API.


Initialization​

UserCom.Builder​

new UserCom.Builder(Application, String sdkKey, String apiKey, String domain)
MethodTypeDefaultDescription
trackAllActivities(boolean)booleanfalseAutomatically track all Activity and Fragment lifecycle events
setDefaultCustomer(Customer)Customer-Start with an identified contact instead of an anonymous one
setOnSdkInitializedListener(OnSdkInitializedListener)OnSdkInitializedListener-Callback fired when the SDK finishes initial contact registration
openLinksInChromeCustomTabs(boolean)booleantrueOpen in-app message links in Chrome Custom Tabs
setCustomTabsBuilder(CustomTabsIntent.Builder)CustomTabsIntent.Builder-Customize Chrome Custom Tabs appearance
build()void-Builds the SDK

UserCom.getInstance()​

Returns the initialized SDK instance. Throws AssertionError if called before build().


Contact​

register(Customer, CustomerUpdateCallback)​

Identifies the current contact. Retrieves the FCM token and sends it along with customer data.

UserCom.getInstance().register(customer, callback)

logout()​

Clears all contact data, detaches the FCM token, and starts a new anonymous session.

UserCom.getInstance().logout()

Events​

sendEvent(String, Map<String, Object>?)​

Sends a custom event.

UserCom.getInstance().sendEvent("button_tapped", mapOf("screen" to "home"))

sendProductEvent(String, ProductEventType, Map<String, Object>?)​

Sends an e-commerce product event.

UserCom.getInstance().sendProductEvent("SKU-1234", ProductEventType.PURCHASE, params)

trackScreen(String)​

Records a screen view.

UserCom.getInstance().trackScreen("Checkout")

Notifications​

onNotification(Context, RemoteMessage)​

Passes an incoming FCM message to the SDK. Returns true if handled.

val handled = UserCom.getInstance().onNotification(applicationContext, remoteMessage)

handleRouteFromNotification(Intent)​

Records a notification click when the app opens from a notification. Returns true if the intent contained a Positive User notification. Call from your launcher Activity's onCreate().

UserCom.getInstance().handleRouteFromNotification(intent)

In-app messages​

setFontResolver(FontResolver)​

Provides a custom Typeface for named fonts used in in-app message templates.

UserCom.getInstance().setFontResolver { name ->
Typeface.createFromAsset(assets, "fonts/$name.ttf")
}

FontResolver interface:

public interface FontResolver {
Typeface resolve(String name);
}

setInAppNotificationClickHandler(ClickHandler?)​

Intercepts button clicks in in-app messages. Pass null to restore the default Chrome Custom Tabs behavior.

UserCom.getInstance().setInAppNotificationClickHandler { url ->
// handle url
}

ClickHandler interface:

public interface ClickHandler {
void onClicked(String url);
}

Customer​

Fluent builder for contact identity and attributes.

MethodFieldType
.id(String)user_idString
.firstName(String)first_nameString
.lastName(String)last_nameString
.email(String)emailString
.attr(String, String)custom attributeString
.attr(String, Boolean)custom attributeBoolean
.attr(String, Int)custom attributeInt

UserComNotification​

Parses a Positive User notification payload from either a Bundle (Activity intent extras) or a Map<String, String> (FCM remote message data).

create(Map<String, String>)​

@Nullable
public static UserComNotification create(Map<String, String> body)

create(Bundle?)​

@Nullable
public static UserComNotification create(@Nullable Bundle bundle)

Returns null if the data doesn't contain the user_com_notification key.

Getters:

MethodTypeDescription
getId()StringNotification ID
getType()intNotification type constant
getTitle()StringNotification title
getMessage()StringNotification body
getLink()String?Action URL, if present
getRawData()Map<String, String>Full raw payload
getDate()DateTime the object was created

ProductEventType​

ValueDescription
ADD_TO_CART
PURCHASE
LIKING
ADD_TO_OBSERVATION
ORDER
RESERVATION
RETURN
VIEW
CLICK
DETAIL
ADD
REMOVE
CHECKOUT
CHECKOUT_OPTION
REFUND
PROMO_CLICK

OnSdkInitializedListener​

Callback for SDK initialization result.

MethodWhen called
onSdkInitialized(Customer)SDK finished registering the initial contact
onUserRegistrationFailed()Initial registration failed (e.g. no network)

CustomerUpdateCallback​

Callback for register().

MethodWhen called
onSuccess(RegisterResponse)Contact registered successfully
onFailure(Throwable)Registration failed

RegisterResponse.getKey() returns the Positive User internal contact key (user_key).