Custom Events
Custom events record any action specific to your app, with a name and attributes you choose. General rules for names, attributes and results: Sending Events.
Requirements
- A successful
ping()in this installation, see Contacts. - A stable event name and a fixed set of attribute names, see Naming rules.
Setup
Call sendEvent where the action happens:
- Kotlin
- Java
UserCom.default?.sendEvent(
"subscription_started",
mapOf("plan" to "pro", "billing_cycle" to "annual", "price" to 99.99)
) { error ->
if (error != null) Log.w("App", "Event failed: ${error.message}")
}
Map<String, Object> attributes = new HashMap<>();
attributes.put("plan", "pro");
attributes.put("billing_cycle", "annual");
attributes.put("price", 99.99);
UserCom sdk = UserCom.getDefault();
if (sdk != null) {
sdk.sendEvent("subscription_started", attributes, error -> {
if (error != null) Log.w("App", "Event failed: " + error.getMessage());
});
}
Check
The event appears on the contact's timeline with its attributes. It can now be used in segments and automations.
Methods
sendEvent
Queues a custom event for the current contact.
Optional unless marked required
- name
- The event name. Use the same spelling and letter case every time.
- attributes
- Event attributes, see Attribute value types. Default
null. - callback
- Called with the result on the main thread. See Callback thread.
Returns nothing. Without a contact (no successful ping yet), the callback gets NotIdentified and the event is not queued. An invalid name or attribute value ends with InvalidName or InvalidData without a request. See Errors.
UserCom.default?.sendEvent("onboarding_completed")
Common errors
| Symptom | Cause | Fix |
|---|---|---|
Callback reports NotIdentified | No successful ping yet. | Call ping() first. |
| Some attributes are missing on the event | A value type differs from the first value sent for that attribute. | Keep each attribute's type stable. |
The event is missing, and after the retries the callback reports Rejected | The name was used before with different letter case. | Use one exact spelling. |