Skip to main content

Sending Events

The SDK records what contacts do in your app as events on their timeline, which you can use in segments and automations. How events are stored and which names and attributes work well: Events.


Requirements​

  • The SDK installed and initialized, see Installation.
  • A successful ping() in this installation. Events need the contact key that the first ping returns. See Contacts.

Event types​

TypeMethodWhen to use
Custom eventssendEvent(name, attributes, callback)Anything specific to your app: a feature used, a form submitted, a purchase step
Screen eventstrackScreen(name, callback)A screen the contact opened
Product eventssendProductEvent(productId, eventType, attributes, callback)Commerce actions on a product: view, add to cart, purchase, refund and more

attributes and callback are optional in every method.


Setup​

  1. Make sure ping() runs at app launch, before the first event.
  2. Pick stable event names and a fixed set of attribute names. See Naming rules.
  3. Send events with the method for the event type.
UserCom.default?.sendEvent("subscription_started", mapOf("plan" to "pro")) { error ->
if (error != null) Log.w("App", "Event failed: ${error.message}")
}
Check

The event appears on the contact's timeline in the panel, and the callback gets null.


Handling​

Results​

Every event method accepts an optional UserComCallback. It gets null on success and a UserComError on failure:

ResultMeaning
nullThe backend accepted the event.
NotIdentifiedNo contact yet. The event was not queued. Call ping() first.
InvalidName or InvalidDataThe name or an attribute value cannot be sent. Nothing was sent.
RejectedThe backend rejected the event: a 4xx at once, a 5xx or 429 after all retries.
NetworkThe connection failed on every attempt. See Delivery and Retries.

The callback is not called for requests that are still waiting in the queue when the app process ends. They are sent after the next launch.

Callback thread​

Every callback runs on the main thread, and never before the call returns. This includes errors the SDK detects before any request. You can update the UI directly in the callback.

Invalid input never throws. Every problem ends with a UserComError in the callback and in UserCom.errorHandler, and the SDK never crashes your app because of the data you pass.

Errors​

Every failure is a UserComError, a sealed class with these subclasses:

ErrorcodeMeaningRequest sent
NotIdentified1No contact yet, call ping() first.No
InvalidName2The event name, screen name or product ID is not accepted.No
InvalidData3An attribute value JSON cannot hold, or an empty attribute name.No
Rejected4The server refused the request. statusCode holds the HTTP status.Yes
Network5The connection failed on every attempt.Yes or no
NotCollectingData6A ping was answered without a contact key: the app does not collect data. Check the panel.Yes
InvalidConfiguration7The SDK is not configured: an empty API key, or a base URL that is not a URL.No
LoggedOut8The request was dropped because the user logged out before it was sent.No

UserCom.errorHandler receives every error on the main thread, after the callback of the call. It also receives errors from calls without a callback, from push and in-app message reports, and a click from an email link that could not be reported. Use it to log SDK errors in one place:

UserCom.errorHandler = UserComErrorHandler { error ->
FirebaseCrashlytics.getInstance().recordException(error)
}

In Java:

UserCom.setErrorHandler(error -> {
if (error instanceof UserComError.Rejected) {
int status = ((UserComError.Rejected) error).getStatusCode();
}
});

A request waiting offline in the queue is not an error: its result comes when it is sent or finally dropped.

Naming rules​

  • Use the same spelling and letter case for an event name every time. Purchase and purchase are treated as the same name, and the second spelling is rejected by the backend.
  • An event name must not be empty, longer than 255 characters or contain HTML. A screen name is at most 128 characters. The SDK checks this and reports InvalidName without a request.
  • Use a fixed set of attribute names with stable value types. Every new attribute name creates a new event attribute, and its first value sets its type for good.
  • Do not send empty attribute names. null values are skipped.

Attribute value types​

Attribute values must be JSON values:

TypeExample
String"checkout"
Int, Long3
Double, Float49.99
Booleantrue
List or arraylistOf("red", "blue")
MapmapOf("size" to "42")
Date as ISO 8601 string"2026-09-28T12:51:33Z"

Any other value, for example a Date, a Uri or a Double that is NaN, ends with InvalidData and nothing is sent. Send dates as ISO 8601 strings.

The SDK adds the contact key and the time of the event to every request. Events created offline keep the time they were created.


Common errors​

SymptomCauseFix
Callback reports NotIdentifiedThe event was sent before the first successful ping.Call ping() at launch and send events after it succeeds.
Callback reports InvalidName or InvalidDataThe name breaks the naming rules, or a value is not a JSON value.Fix the name or the value.
Callback reports InvalidConfigurationThe base URL passed to initialize has no https://, or the API key is empty.Pass the full workspace address.
Events are not on the contact you expectThe device is tied to a different contact than the one you look at.Compare UserCom.default?.userKey with the contact key in the panel. See Troubleshooting.
The event is recorded, but some attributes are missingThe attribute value has a different type than the first value ever sent for it, or the name is invalid.Keep attribute types stable.
An event name never appears in the panelThe same name was used before with different letter case.Use one exact spelling.
No screen events at allScreens are not tracked automatically.Call trackScreen(name).