Developer

Goals and purchases

Track goal events and order revenue from a hybrid app. Send each purchase once per order with a stable order ID, and understand how Apex attributes revenue to tests.

Call track() once at each goal action. Call trackPurchase() once per order at order confirmation.

Track a goal

ts
await Apex.track('signup_completed');
await Apex.track('add_to_cart', { product_id: 'sku-123', screen: 'product' });
  • Use the event name of the goal you measure in Apex.
  • Event names are non-empty strings of up to 256 characters.
  • Properties are optional. They must be a JSON object with finite numbers.
  • A string screen property sets the screen for this event. Otherwise the SDK uses your screen option.

A track event carries no test or variation fields. Only purchases carry per-test copies. See Attribution.

Track a purchase

ts
await Apex.trackPurchase(order.id, order.total, order.currency, { screen: 'checkout' });
ArgumentRule
orderIdA stable, non-empty string of up to 1,024 characters. Use your own order ID.
revenueA finite, non-negative number in currency units, for example 42.5.
currencyA three-letter ISO 4217 code, for example EUR. The SDK trims and uppercases it.
propertiesOptional. The same rules as track.

Call trackPurchase() once per order. If the same order ID reaches Apex more than once, results still count the order once. Always send the same order ID for the same order.

The SDK removes order, revenue and currency fields from your properties before it adds the explicit arguments. Your properties cannot override them. Other properties stay.

Attribution

Apex attributes purchase revenue to every test the user is assigned to. trackPurchase() sends one base row without test fields. It also sends one copy for each current assignment, with that test's experiment and variation IDs. All rows share one event ID, so retries cannot double count them.

The SDK keeps all rows of one purchase together. It queues them together and sends them in one request.

Blocked properties

The SDK drops an event that contains any of these property keys: email, phone, password, ssn, credit_card or card_number. The check ignores case and accents. Do not send personal data in event properties.

The SDK also drops an event with an invalid revenue property. A valid value is a finite number, or a decimal string such as "42" or "42,5".

What the promise means

track() and trackPurchase() resolve when the event is in the device queue. They do not wait for delivery to Apex. They never reject. Invalid input is logged and dropped. See Troubleshooting for the log lines.