Analytics & attribution

Events

The Kelp event taxonomy - every named event kind, its tracker method, and the full event field reference.

Kelp defines a closed set of named ecommerce event kinds. Each client-emitted kind has a matching method on the createAnalytics tracker that composes the event with its kind and auto-fills ambient fields.

Event taxonomy

Session

MethodEvent kindWhen to emit
startSession(input?)session_startedA new session began. Captures landing context and emits at most once per session.
trackSessionStarted(input?)session_startedEmit session_started directly - no capture and no dedupe.
analytics.startSession({ collection: 'products' });

startSession is safe to call on every page load. It requires an attribution store on createAnalytics; without one it is a no-op. Prefer it over trackSessionStarted unless you need to emit without capture or dedupe.

Search and browse

MethodEvent kindWhen to emit
trackSearch(input)searchA search or browse query runs and results are returned.
analytics.trackSearch({
  collection: 'products',
  q: 'running shoe',
  found: res.found,
  page: res.page,
  queryId: res.queryId,
  filters: [{ field: 'status', op: '=', values: ['ACTIVE'] }],
});

filters is serialized into the filterBy string automatically using defaultSerializeFilterBy, e.g. status:=[ACTIVE]. Override the format by passing serializeFilterBy to createAnalytics.

Product events

MethodEvent kindWhen to emit
trackProductClicked(input)product_clickedA visitor clicks a product result or suggestion. Pass queryId to attribute the click to the originating search.
trackProductViewed(input)product_viewedA product detail page (PDP) is viewed.
trackProductWishlisted(input)product_wishlistedA product is saved to a wishlist or favourites.
trackProductAddedToCart(input)product_added_to_cartA product is added to the cart. Pass queryId to attribute to the originating search.
analytics.trackProductClicked({
  collection: 'products',
  objectId: '9149995942110',
  queryId: res.queryId,
});

analytics.trackProductViewed({ collection: 'products', objectId: '9149995942110' });

analytics.trackProductWishlisted({ collection: 'products', objectId: '9149995942110' });

analytics.trackProductAddedToCart({
  collection: 'products',
  objectId: '9149995942110',
  queryId: res.queryId,
});

objectId is the product's id in your collection (Shopify product id on view, click, wishlist, cart, and purchase line items). Collection views use the collection id or handle.

Collection events

MethodEvent kindWhen to emit
trackCollectionViewed(input)collection_viewedA collection or category page is viewed.
analytics.trackCollectionViewed({
  collection: 'products',
  objectId: 'summer-sale', // the collection handle (e.g. 'mens-shoes', 'all'), not a product id
  queryId: res.queryId,
});

Purchase

MethodEvent kindWhen to emit
trackPurchase(input)purchaseAn order is completed.
analytics.trackPurchase({
  collection: 'products',
  orderId: 'order-1001',
  value: 129.99,
  currency: 'USD',
  items: [
    { objectId: '9149995942110', quantity: 1, price: 129.99 },
    { objectId: '9149995942111', quantity: 2, price: 49.99 },
  ],
  // queryId is intentionally omitted on purchase in most integrations.
  // See note below.
});

items[].objectId is the product numeric id (the GID tail: String(gid).split('/').pop()), not the variant id or handle.

Purchase value, currency, orderId, and items are first-class persisted fields - send them on the event, not inside metadata.

queryId on purchase events: queryId is optional and typically omitted for purchase events on multi-page storefronts. A real-world cart often contains items added after different searches - attaching any single queryId would misattribute the conversion. Purchase attribution to a search session works via sessionId and userId instead, which are stable across the session. See Attribution for details.

In Shopify Hydrogen, the purchase event is sent by a custom pixel (not the storefront SDK) because the storefront JavaScript does not run during checkout. The pixel reads sessionId and userId from cart attributes stamped server-side before the checkout redirect. queryId is stamped as a cart attribute but deliberately not forwarded by the pixel.

Email events

Email events are emitted by createKelpEmail - you do not call these on the analytics tracker. See Email capture.

Event kindEmitted byWhen
email_subscribedemail.subscribe(...)Contact opted in.
email_unsubscribedemail.unsubscribe(...)Contact opted out.
email_openedreservedAn email was opened. Not emitted by the client yet.
email_clickedreservedA link in an email was clicked. Not emitted by the client yet.

Email kinds carry a nested Email object (see field reference below). There is no flat root email / source / listId shape.

track()

Use track() only for a named kind that has no helper. kind must be one of the kinds above. The SDK does not accept custom strings. Ambient fields (occurredAt, sessionId, userId) are still auto-filled.

Low-level: trackEvents

kelp.trackEvents(events) is the raw transport. You supply fully-formed events - no auto-filling. kind must be a named KelpEventKind. Use this only when createAnalytics is not suitable (e.g. server-side ingestion from your own backend).

await kelp.trackEvents([
  {
    kind: 'search',
    occurredAt: '2026-08-03T12:00:00Z',
    collection: 'products',
    sessionId: 'sess-1',
    userId: 'anon_1a3b',
    q: 'shoes',
    found: 12,
    page: 1,
    queryId: '019f7571-998f-7bb5-abdd-0945c5be7a4a',
  },
]);

The SDK still wraps the array in the batch envelope { id, tenantCode?, events } before posting.

Event field reference

All fields on KelpAnalyticsEvent:

FieldRequiredTypeNotes
kindyesKelpEventKindNamed event type - see the taxonomy above. Closed set of 12 kinds.
occurredAtyesISO 8601 stringEvent-root only. Auto-filled by createAnalytics. Not on Attribution.
sessionIdyesstringAuto-filled by createAnalytics from identity.getSessionId().
userIdnostringKelp visitor id - identified user, or anon_<stable-id> for anonymous visitors. Not a Shopify customer id.
collectionnostringCollection name. Required for search, product, and collection events; optional for email events.
qnostringQuery string (search events).
filterBynostringSerialized filter expression, e.g. brand:=[globex] && price:>0. Set by trackSearch from the filters array.
foundnonumberResult count (search events).
pagenonumberPage number (search events).
queryIdnostringTies a click or conversion event back to a search response. See Attribution (queryId chaining). Separate from the UTM Attribution object below.
objectIdnostringSubject document id: product id for product events, collection handle/id for collection_viewed.
emailnoEmailNested Email DTO (optional on every kind). See below.
attributionnoAttributionNested Attribution DTO (optional on every kind). See below.
valuenonumberOrder total (purchase). First-class persisted.
currencynostringISO 4217 currency code, e.g. 'USD' (purchase). First-class persisted.
orderIdnostringOrder id (purchase). First-class persisted.
itemsno{ objectId, quantity?, price? }[]Line items (purchase). First-class persisted (flexible JSON).
metadatanoobjectOptional event-level JSON (KEL-52). Stored as jsonb. An empty object is stored as null. Only objects are valid. Separate from email.meta and attribution.meta.

Email object

Optional nested object on any event kind. When present, email (the address) is required. source is optional on the Email object (capture point, e.g. 'footer-form'). It is separate from Attribution source, which remains required when Attribution is present.

FieldRequiredTypeNotes
emailyes (when object present)stringContact address.
sourcenostringCapture point, e.g. 'footer-form'. Optional; only on object form.
listIdnostringTarget list id.
campaignIdnostringCampaign id (e.g. reserved open/click kinds).
detailsnoEmailDetailsPerson fields: name, firstName, lastName, phone.
metanoRecord<string, unknown>Email-scoped overflow JSON. Not event metadata.

Helpers that accept a flat string address map it to { email } only. source is optional when using the object form.

// Nested Email on subscribe (via createKelpEmail)
email.subscribe({
  email: 'shopper@example.com',
  source: 'footer-form',
  listId: 'list_newsletter',
  details: { firstName: 'Sam', lastName: 'Shopper' },
  meta: { formId: 'footer-v2' },
});

Attribution object

Optional nested object on any event kind (UTM / traffic source). When present, source is required; medium and the rest are optional. occurredAt is not on this object (occurredAt lives on the event root only).

FieldRequiredTypeNotes
sourceyes (when object present)stringTraffic source, e.g. 'google'.
mediumnostringe.g. 'organic', 'cpc'.
campaignnostringCampaign name.
contentnostringCreative / content.
termnostringPaid keyword.
campaignRefnostringExternal campaign reference.
clickIdnostringClick id value.
clickIdParamnostringParam name that held the click id.
referrernostringDocument referrer.
landingPagenostringLanding path.
metanoRecord<string, unknown>Attribution-scoped overflow JSON. Not event metadata.
{
  kind: 'session_started',
  occurredAt: '2026-09-17T12:04:30.000Z',
  sessionId: 'sess_01HZY',
  userId: 'anon_01HZY',
  attribution: {
    source: 'google',
    medium: 'organic',
    referrer: 'https://www.google.com/',
    landingPage: '/',
    meta: { gclid: 'example' },
  },
}

Search-to-conversion chaining with queryId is documented separately in Attribution. That guide is about threading queryId, not this UTM Attribution object.

Purchase scalars (value, currency, orderId, items) and typed email / attribution are first-class persisted fields (KEL-57). Do not dump them into event metadata. Use metadata for other open JSON; use email.meta / attribution.meta for overflow scoped to those objects.

On this page