Skip to main content

useAnalytics

A hook that provides access to the analytics provider context. Must be a descendent of Analytics.Provider.

Anchor to canTrack
canTrack
() => boolean

A function to tell you the current state of if the user can be tracked by analytics. Defaults to Customer Privacy API's window.Shopify.customerPrivacy.analyticsProcessingAllowed().

UserCart |

The current cart state. You can overwrite the type by passing a generic

Anchor to customData
customData
Record<string, unknown>

The custom data passed in from the AnalyticsProvider.

Anchor to prevCart
prevCart
UserCart |

The previous cart state. You can overwrite the type by passing a generic

Anchor to publish
publish

A function to publish an analytics event.

Anchor to register
register
(key: string) => { ready: () => void; }

A function to register with the analytics provider. It holds the first browser load events until all registered key has executed the supplied ready function. See example register usage.

Promise< | null> | | null

The shop configuration required to publish events to Shopify.

Anchor to subscribe
subscribe

A function to subscribe to analytics events.


Was this page helpful?