useAnalytics
A hook that provides access to the analytics provider context. Must be a descendent of Analytics.Provider.
Anchor to returnsReturns
- Anchor to canTrackcanTrackcanTrack() => boolean() => boolean
A function to tell you the current state of if the user can be tracked by analytics. Defaults to Customer Privacy API's
.- Anchor to cartcartcartUserCart | DefaultCartUserCart | DefaultCart
The current cart state. You can overwrite the type by passing a generic
- Anchor to customDatacustomDatacustomDataRecord<string, unknown>Record<string, unknown>
The custom data passed in from the
.- Anchor to prevCartprevCartprevCartUserCart | DefaultCartUserCart | DefaultCart
The previous cart state. You can overwrite the type by passing a generic
- Anchor to publishpublishpublishAnalyticsContextPublishForDocAnalyticsContextPublishForDoc
A function to publish an analytics event.
- Anchor to registerregisterregister(key: string) => { ready: () => void; }(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
readyfunction. See example register usage.- Anchor to shopshopshopPromise<ShopAnalytics | null> | ShopAnalytics | nullPromise<ShopAnalytics | null> | ShopAnalytics | null
The shop configuration required to publish events to Shopify.
- Anchor to subscribesubscribesubscribeAnalyticsContextSubscribeForDocAnalyticsContextSubscribeForDoc
A function to subscribe to analytics events.
DefaultCart
Promise<CartReturn | null> | CartReturn | nullCartReturn
Cart & {
errors?: StorefrontApiErrors;
}Cart
- attributes
The cart's attributes.
{ __typename?: "Attribute"; key?: string; value?: string; }[] - buyerIdentity
The cart's buyer identity.
CartType['buyerIdentity'] - checkoutUrl
The checkout URL for the cart, if the cart has been created in the Storefront API.
string - cost
The cost for the cart, including the subtotal, total, taxes, and duties.
CartType['cost'] - discountCodes
The discount codes applied to the cart.
{ __typename?: "CartDiscountCode"; applicable?: boolean; code?: string; }[] - id
The cart's ID if it has been created through the Storefront API.
string - lines
The cart lines.
Array<CartLine | ComponentizableCartLine> - note
The cart's note.
string - totalQuantity
The total number of items in the cart, across all lines. If there are no lines, then the value is 0.
number
StorefrontApiErrors
JsonGraphQLError[] | undefinedJsonGraphQLError
- extensions
Reserved for implementors to extend the protocol however they see fit, and hence there are no additional restrictions on its contents.
{ [key: string]: unknown; } - locations
If an error can be associated to a particular point in the requested GraphQL document, it should contain a list of locations.
{ line: number; column: number; }[] - message
string - name
string - path
If an error can be associated to a particular field in the GraphQL result, it _must_ contain an entry with the key `path` that details the path of the response field which experienced the error. This allows clients to identify whether a null result is intentional or caused by a runtime error.
(string | number)[] - stack
string
AnalyticsContextPublishForDoc
PublishPageView | PublishProductView | PublishCollectionView | PublishCartView | PublishSearchView | PublishCartUpdated | PublishProductAddedToCart | PublishProductRemovedFromCart | PublishCustomEventPublishPageView
- event
"page_viewed" - payload
PageViewPayload
voidPageViewPayload
UrlPayload & BasePayloadUrlPayload
- url
The url location of when this event is collected.
string
BasePayload
- customData
The custom data passed in from the `AnalyticsProvider`.
Record<string, unknown> - shop
The shop data passed in from the `AnalyticsProvider`.
ShopAnalytics | null
ShopAnalytics
- acceptedLanguage
The language code that is being displayed to user.
LanguageCode - currency
The currency code that is being displayed to user.
CurrencyCode - hydrogenSubchannelId
The Hydrogen subchannel ID generated by Oxygen in the environment variable.
string | '0' - shopId
The shop ID.
string
CurrencyCode
Supports CurrencyCode from both Storefront API and Customer Account API. The APIs may have different CurrencyCode enums (e.g., Customer Account API added USDC in 2025-10, but Storefront API doesn't support USDC in 2025-10). This union type ensures useMoney works with data from either API.
StorefrontApiCurrencyCode | CustomerAccountApiCurrencyCodePublishProductView
- event
"product_viewed" - payload
ProductViewPayload
voidProductViewPayload
ProductsPayload & UrlPayload & BasePayloadProductsPayload
- products
The products associated with this event.
Array<ProductPayload & OtherData>
ProductPayload
- id
The product id.
string - price
The displaying variant price.
string - productType
The product type.
string - quantity
The quantity of product.
number - sku
The product sku.
string - title
The product title.
string - variantId
The displaying variant id.
string - variantTitle
The displaying variant title.
string - vendor
The product vendor.
string
OtherData
PublishCollectionView
- event
"collection_viewed" - payload
CollectionViewPayload
voidCollectionViewPayload
CollectionPayload & UrlPayload & BasePayloadCollectionPayload
- collection
CollectionPayloadDetails
CollectionPayloadDetails
- handle
The collection handle.
string - id
The collection id.
string
PublishCartView
- event
"cart_viewed" - payload
CartViewPayload
voidCartViewPayload
CartPayload & UrlPayload & BasePayloadCartPayload
- cart
The current cart state.
CartReturn | null - prevCart
The previous cart state.
CartReturn | null
PublishSearchView
- event
"search_viewed" - payload
SearchViewPayload
voidSearchViewPayload
SearchPayload & UrlPayload & BasePayloadSearchPayload
- searchResults
The search results
any - searchTerm
The search term used for the search results page
string
PublishCartUpdated
- event
"cart_updated" - payload
CartUpdatePayload
voidCartUpdatePayload
CartPayload & BasePayload & OtherDataPublishProductAddedToCart
- event
"product_added_to_cart" - payload
CartLineUpdatePayload
voidCartLineUpdatePayload
CartLinePayload & CartPayload & BasePayload & OtherDataCartLinePayload
- currentLine
The current state of the cart line that got updated.
CartLine | ComponentizableCartLine - prevLine
The previous state of the cart line that got updated.
CartLine | ComponentizableCartLine
PublishProductRemovedFromCart
- event
"product_removed_from_cart" - payload
CartLineUpdatePayload
voidPublishCustomEvent
- event
`custom_${string}` - payload
OtherData
voidAnalyticsContextSubscribeForDoc
SubscribePageView | SubscribeProductView | SubscribeCollectionView | SubscribeCartView | SubscribeSearchView | SubscribeCartUpdated | SubscribeProductAddedToCart | SubscribeProductRemovedFromCart | SubscribeCustomEventSubscribePageView
- event
"page_viewed" - callback
(payload: PageViewPayload) => void
voidSubscribeProductView
- event
"product_viewed" - callback
(payload: ProductViewPayload) => void
voidSubscribeCollectionView
- event
"collection_viewed" - callback
(payload: CollectionViewPayload) => void
voidSubscribeCartView
- event
"cart_viewed" - callback
(payload: CartViewPayload) => void
voidSubscribeSearchView
- event
"search_viewed" - callback
(payload: SearchViewPayload) => void
voidSubscribeCartUpdated
- event
"cart_updated" - callback
(payload: CartUpdatePayload) => void
voidSubscribeProductAddedToCart
- event
"product_added_to_cart" - callback
(payload: CartLineUpdatePayload) => void
voidSubscribeProductRemovedFromCart
- event
"product_removed_from_cart" - callback
(payload: CartLineUpdatePayload) => void
voidSubscribeCustomEvent
- event
`custom_${string}` - callback
(payload: OtherData) => void
void