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)
| Method | Type | Default | Description |
|---|---|---|---|
trackAllActivities(boolean) | boolean | false | Automatically 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) | boolean | true | Open 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.
| Method | Field | Type |
|---|---|---|
.id(String) | user_id | String |
.firstName(String) | first_name | String |
.lastName(String) | last_name | String |
.email(String) | email | String |
.attr(String, String) | custom attribute | String |
.attr(String, Boolean) | custom attribute | Boolean |
.attr(String, Int) | custom attribute | Int |
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:
| Method | Type | Description |
|---|---|---|
getId() | String | Notification ID |
getType() | int | Notification type constant |
getTitle() | String | Notification title |
getMessage() | String | Notification body |
getLink() | String? | Action URL, if present |
getRawData() | Map<String, String> | Full raw payload |
getDate() | Date | Time the object was created |
ProductEventType
| Value | Description |
|---|---|
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.
| Method | When called |
|---|---|
onSdkInitialized(Customer) | SDK finished registering the initial contact |
onUserRegistrationFailed() | Initial registration failed (e.g. no network) |
CustomerUpdateCallback
Callback for register().
| Method | When called |
|---|---|
onSuccess(RegisterResponse) | Contact registered successfully |
onFailure(Throwable) | Registration failed |
RegisterResponse.getKey() returns the Positive User internal contact key (user_key).