analytics
Built-in middleware that calls the host-supplied emit on every mutation:
cart.mutation.success on resolve and cart.mutation.error on reject.
The emit call is fire-and-forget — a thrown emit handler will surface
because emit is invoked synchronously inside the async chain.
Signature
function analytics(opts: { emit: AnalyticsEmit }): CartMiddleware;Parameters
| Name | Type | Description |
|---|---|---|
opts | { emit: AnalyticsEmit } |
Returns
A that observes mutation outcomes.
Example
const kernel = createCart({
adapter,
middleware: [analytics({ emit: (event, attrs) => tracker.track(event, attrs) })],
});Related
RunCartAdapterContractOpts runCartAdapterContract CartCapabilityUnsupportedError CartError CartNotFoundError CartProviderError CartUserError CartAdapter
AnalyticsEmit
Callback injected into the middleware to forward mutation outcome events to the host's analytics pipeline. Receives an event name and a structured attribute bag
BuyerIdentity
Optional contact details attached to an active cart to identify the buyer. Pass to createCart or via the updatebuyeridentity mutation when the consumer logs in