Analytics API
The Analytics API provides methods to interact with Shopify's analytics framework. Use this API to publish custom events that are forwarded to all registered web pixels, or to submit visitor contact details directly to the shop backend.
Events published with publish() are forwarded only to web pixels. They aren't sent to the shop backend. Visitor data submitted with visitor() goes only to the shop backend. It isn't propagated to web pixels on the page.
Anchor to Use casesUse cases
- Publish custom analytics events: Emit events from your extension that web pixels on the page can react to.
- Submit visitor information: Send buyer contact details to the shop backend for attribution and analytics purposes.
- Track extension-specific interactions: Publish events when buyers interact with your extension's UI to measure engagement.
Supported targets
- purchase.
address-autocomplete. format-suggestion - purchase.
address-autocomplete. suggest - purchase.
checkout. actions. render-before - purchase.
checkout. block. render - purchase.
checkout. cart-line-item. render-after - purchase.
checkout. cart-line-list. render-after - purchase.
checkout. chat. render - purchase.
checkout. contact. render-after - purchase.
checkout. delivery-address. render-after - purchase.
checkout. delivery-address. render-before - purchase.
checkout. footer. render-after - purchase.
checkout. header. render-after - purchase.
checkout. payment-method-list. render-after - purchase.
checkout. payment-method-list. render-before - purchase.
checkout. pickup-location-list. render-after - purchase.
checkout. pickup-location-list. render-before - purchase.
checkout. pickup-location-option-item. render-after - purchase.
checkout. pickup-point-list. render-after - purchase.
checkout. pickup-point-list. render-before - purchase.
checkout. reductions. render-after - purchase.
checkout. reductions. render-before - purchase.
checkout. shipping-option-item. details. render - purchase.
checkout. shipping-option-item. render-after - purchase.
checkout. shipping-option-list. render-after - purchase.
checkout. shipping-option-list. render-before - purchase.
thank-you. announcement. render - purchase.
thank-you. block. render - purchase.
thank-you. cart-line-item. render-after - purchase.
thank-you. cart-line-list. render-after - purchase.
thank-you. chat. render - purchase.
thank-you. customer-information. render-after - purchase.
thank-you. footer. render-after - purchase.
thank-you. header. render-after
Supported targets
- purchase.
address-autocomplete. format-suggestion - purchase.
address-autocomplete. suggest - purchase.
checkout. actions. render-before - purchase.
checkout. block. render - purchase.
checkout. cart-line-item. render-after - purchase.
checkout. cart-line-list. render-after - purchase.
checkout. chat. render - purchase.
checkout. contact. render-after - purchase.
checkout. delivery-address. render-after - purchase.
checkout. delivery-address. render-before - purchase.
checkout. footer. render-after - purchase.
checkout. header. render-after - purchase.
checkout. payment-method-list. render-after - purchase.
checkout. payment-method-list. render-before - purchase.
checkout. pickup-location-list. render-after - purchase.
checkout. pickup-location-list. render-before - purchase.
checkout. pickup-location-option-item. render-after - purchase.
checkout. pickup-point-list. render-after - purchase.
checkout. pickup-point-list. render-before - purchase.
checkout. reductions. render-after - purchase.
checkout. reductions. render-before - purchase.
checkout. shipping-option-item. details. render - purchase.
checkout. shipping-option-item. render-after - purchase.
checkout. shipping-option-list. render-after - purchase.
checkout. shipping-option-list. render-before - purchase.
thank-you. announcement. render - purchase.
thank-you. block. render - purchase.
thank-you. cart-line-item. render-after - purchase.
thank-you. cart-line-list. render-after - purchase.
thank-you. chat. render - purchase.
thank-you. customer-information. render-after - purchase.
thank-you. footer. render-after - purchase.
thank-you. header. render-after
Anchor to Properties and methodsProperties and methods
The shopify global object provides analytics capabilities for the current checkout. Access the following properties and methods on shopify to publish custom events and submit visitor data. Available to purchase extension targets.
- Anchor to analyticsanalyticsanalyticsAnalyticsAnalyticsrequiredrequired
Tracks custom events and sends visitor information to Web Pixels. Use
publish()to emit events andvisitor()to submit buyer contact details.
Analytics
Tracks custom events and sends visitor information to [Web Pixels](/docs/apps/marketing). Use `publish()` to emit events and `visitor()` to submit buyer contact details.
- publish
Publishes a custom event to [Web Pixels](/docs/apps/marketing). Returns `true` when the event is successfully dispatched. The Promise resolves to `true` when the event was dispatched. The boolean indicates dispatch confirmation only. It doesn't indicate whether any specific web pixel processed the event.
(name: string, data: Record<string, unknown>) => Promise<boolean> - visitor
Submits buyer contact details for attribution and analytics purposes.
(data: { email?: string; phone?: string; }) => Promise<VisitorResult>
VisitorResult
Represents a visitor result.
VisitorSuccess | VisitorErrorVisitorSuccess
Represents a successful visitor result.
- type
Indicates that the visitor information was validated and submitted.
'success'
VisitorError
Represents an unsuccessful visitor result.
- message
A message that explains the error. This message is useful for debugging. It isn't localized and shouldn't be displayed to the buyer.
string - type
Indicates that the visitor information is invalid and wasn't submitted. Common causes include using the wrong data type or omitting a required property.
'error'
Anchor to Best practicesBest practices
- Respect buyer privacy consent: Before publishing analytics events, check whether analytics processing is allowed using the Customer Privacy API. Read
shopify.customerPrivacy.value.allowedProcessing.analyticsand only publish events when it'strue. - Use descriptive event names: When calling
publish(), use specific event names that clearly describe the interaction (for example,"loyalty_points_redeemed"instead of"click"). This makes it easier for web pixel implementations to filter and process events. - Separate analytics from visitor data: Use
publish()for events that web pixels should process andvisitor()for contact details that should go to the shop backend. Don't usepublish()to send visitor contact information.