Skip to main content

Product Events

Product events record commerce actions on a product, such as views, add to cart and purchases, and keep product attributes up to date. General rules for events: Sending Events.


Requirements​

  • A successful ping() in this installation, see Contacts.
  • A stable product ID for each product, the same one you use on your website or in your product feed.

Setup​

Call sendProductEvent when the action happens:

UserCom.default?.sendProductEvent(
"SKU-1234",
ProductEventType.ADD_TO_CART,
mapOf(
"name" to "Running Shoes",
"product_url" to "https://www.example.com/shoes/1234",
"price" to 89.99,
"currency" to "USD",
"size" to "42"
)
) { error ->
if (error != null) Log.w("App", "Product event failed: ${error.message}")
}

ProductEventType is in the package com.user.sdk.events.

Check

The product event appears on the contact's timeline, and the product in the panel has the attributes you sent (price, currency, size).


Handling​

Attributes are product attributes​

Each key in attributes is stored as a separate attribute of the product, next to the product ID. Pass the product name as name and the product page URL as product_url. A new value replaces the previous value of that product attribute. Every new key creates a new product attribute, so use a fixed set of keys with stable value types. If a key in attributes is custom_id, the product ID wins.

Values must be JSON values, see Attribute value types. Any other value, for example a Date, a Uri or a Double that is NaN, ends with InvalidData and nothing is sent.

Events in quick succession​

The event time is sent with one second precision. Two events with the same product, the same event type and the same second are recorded as one event.


Methods​

sendProductEvent​

Queues a product event for the current contact.

Optional unless marked required

productIdStringrequired
Your product ID. Must not be empty.
eventTypeProductEventTyperequired
The action, see the table below.
attributesMap<String, Any>?
Product attributes, for example name, product_url, price. Default null.
callbackUserComCallback?
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 empty product ID ends with InvalidName without a request.

UserCom.default?.sendProductEvent("SKU-1234", ProductEventType.VIEW)

ProductEventType values and how they appear in the panel:

ValuePanel
ADD_TO_CARTadd to cart
PURCHASEpurchase
LIKINGliking
ADD_TO_OBSERVATIONadd to observation
ORDERorder
RESERVATIONreservation
RETURNreturn
VIEWview
CLICKclick
DETAILdetail
ADDadd
REMOVEremove
CHECKOUTcheckout
CHECKOUT_OPTIONcheckout option
REFUNDrefund
PROMO_CLICKpromo click

Common errors​

SymptomCauseFix
Callback reports NotIdentifiedNo successful ping yet.Call ping() first.
Callback reports InvalidNameThe product ID is empty.Pass your product ID.
The panel shows many similar product attributesAttributes use changing keys, for example with IDs or dates in the key.Use a fixed set of keys. Put changing data in values.
Two quick events count as oneSame product, type and second.Expected. Send distinct actions with distinct event types.