All questions

Tracking custom events from Hydrogen loaders and actions

Asked by leo_n on

Lleo_n

Auto events are flowing fine on our Hydrogen store. Now I need two custom events for audience conditions: wishlist-add and size-guide-open. Tried this from the wishlist button:

croct.track('wishlistAdded', {productId: product.id});

Rejected, wishlistAdded is not a known event type. What is the right way to send events that dont exist in the built-in list

Was this helpful?

1 answer

Ffionn_d

The track call only accepts the documented event types, so an arbitrary name like wishlistAdded gets rejected. For events outside the built-in list you have two options.

The generic one is eventOccurred, which exists exactly for custom events:

croct.track('eventOccurred', {    name: 'wishlist-add',    details: {productId: product.id},});

Same for size-guide-open. The name is what you reference in audience conditions later.

Before reaching for the generic event though, check the purpose-built ones, because several cover common ecommerce actions with richer semantics: goalCompleted with a goalId, cartModified, and checkoutStarted with a cart payload (currency, total, items). If either of your events is going to be an experiment goal, prefer goalCompleted, since a goal event must already be tracked before you can pick it as an experiment's primary Goal ID. Firing it once from a dev session is enough to make it selectable.

Was this helpful?
Still have questions?