Analytics API
The Analytics API lets you publish custom events and visitor information to web pixels configured on the store. Use this API to track customer behavior in your extension and send conversion data to third-party analytics services.
Anchor to Use casesUse cases
- Track extension interactions: Publish custom events when customers interact with your extension, such as viewing a product recommendation or clicking a promotion banner.
- Measure conversions: Send conversion events from customer account pages to analytics platforms for attribution and reporting.
- Identify returning visitors: Submit visitor contact information so downstream analytics tools can associate sessions with known customers.
Supported targets
- customer-account.
footer. render-after - customer-account.
order-index. announcement. render - customer-account.
order-index. block. render - customer-account.
order-status. announcement. render - customer-account.
order-status. block. render - customer-account.
order-status. cart-line-item. render-after - customer-account.
order-status. cart-line-list. render-after - customer-account.
order-status. customer-information. render-after - customer-account.
order-status. fulfillment-details. render-after - customer-account.
order-status. payment-details. render-after - customer-account.
order-status. return-details. render-after - customer-account.
order-status. unfulfilled-items. render-after - customer-account.
order. action. menu-item. render - customer-account.
order. action. render - customer-account.
order. page. render - customer-account.
page. render - customer-account.
profile. addresses. render-after - customer-account.
profile. announcement. render - customer-account.
profile. block. render - customer-account.
profile. company-details. render-after - customer-account.
profile. company-location-addresses. render-after - customer-account.
profile. company-location-payment. render-after - customer-account.
profile. company-location-staff. render-after - customer-account.
profile. payment. render-after
Supported targets
- customer-account.
footer. render-after - customer-account.
order-index. announcement. render - customer-account.
order-index. block. render - customer-account.
order-status. announcement. render - customer-account.
order-status. block. render - customer-account.
order-status. cart-line-item. render-after - customer-account.
order-status. cart-line-list. render-after - customer-account.
order-status. customer-information. render-after - customer-account.
order-status. fulfillment-details. render-after - customer-account.
order-status. payment-details. render-after - customer-account.
order-status. return-details. render-after - customer-account.
order-status. unfulfilled-items. render-after - customer-account.
order. action. menu-item. render - customer-account.
order. action. render - customer-account.
order. page. render - customer-account.
page. render - customer-account.
profile. addresses. render-after - customer-account.
profile. announcement. render - customer-account.
profile. block. render - customer-account.
profile. company-details. render-after - customer-account.
profile. company-location-addresses. render-after - customer-account.
profile. company-location-payment. render-after - customer-account.
profile. company-location-staff. render-after - customer-account.
profile. payment. render-after
Anchor to PropertiesProperties
The shopify global object provides the analytics interface for customer account extensions. Access the following properties on shopify to publish custom events and send visitor data to web pixels.
- Anchor to analyticsanalyticsanalyticsAnalyticsAnalyticsrequiredrequired
Tracks custom events and sends visitor information to web pixels. Use
publish()to emit events andvisitor()to submit visitor data.NoteRequires connecting a third-party domain to Shopify for your customer account pages.
Note:Requires connecting a third-party domain to Shopify for your customer account pages.
Note: Requires <a href="https://help.shopify.com/en/manual/domains/add-a-domain/connecting-domains/connect-domain-customer-account">connecting a third-party domain</a> to Shopify for your customer account pages.
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
- Publish events inside
useEffect: Trigger analytics calls after the component mounts so you don't block the initial render. - Handle publish failures gracefully: Always attach a
.catch()handler toshopify.analytics.publish()so undelivered events don't cause uncaught promise rejections. - Use descriptive event names: Choose event names that clearly identify the interaction, such as
loyalty-points-redeemedorsubscription-upgraded, so pixel consumers can filter and act on them. - Avoid sending sensitive data in event payloads: Don't include passwords, full payment details, or other personally identifiable information beyond what's needed for analytics.
Anchor to LimitationsLimitations
- Custom events published through this API are only delivered to web pixels that are configured on the store. If no pixels are active, the publish call resolves but has no downstream effect.
- The
shopify.analytics.visitor()method sends data to the store backend only. Visitor information isn't propagated to web pixels on the page. - Event payloads must be JSON-serializable. Functions, DOM nodes, and circular references can't be included.