Skip to Content
How-to guidesAnalytics and consentConnect Shopify admin analytics

Connect Shopify admin analytics

Audience: Developer and Integrator.

Use this guide with the browser integration API.

Shopify admin reports require events at Shopify’s analytics destination. Events sent to GTM, GA4, a custom pixel, or the platform’s realtime service do not automatically populate Shopify visitor reports. Shopify’s current analytics setup  provides its own browser runtime and consent flow for custom storefronts.

Host setup required: The event API can forward page views through a trusted CMS script. Configure Shopify’s browser runtime and first-party session before this source runs. This feature does not supply them. Use the generic browser integration script runner. Keep CodeBanner local scripts isolated. Put the bridge in the integration’s JavaScript field.

Prerequisites

  • Configure consent and a browser integration.
  • Use a published production-like hostname connected to the selected Shopify store.
  • Use access to the selected Shopify store, channel, and SDK setup.
  • Use an account with Shopify admin analytics access for verification.
  • Complete the first-party host setup below. The short CMS bridge alone does not enable Shopify admin analytics.

Required host setup

  1. Select the Shopify store and sales channel for each website domain. For a Hydrogen storefront, use that channel’s Storefront API access and matching storefront ID. The Headless channel has no Hydrogen storefront ID. Do not copy an ID from another store or channel. See Shopify’s shop and channel types .
  2. Add Shopify’s supported first-party request handlers to the storefront server. They include the Storefront API proxy and /__shopify/* routes. Preserve request cookies, Shopify response headers, and cookie updates. Apply Shopify’s cache rules to responses that set cookies. A backend call with a shared API token does not replace visitor session handling. Adapt the request-handler setup  to the platform’s Next.js Pages Router deployment. Keep private tokens on the server.
  3. Render ShopifyScripts once for the current domain’s shop and market. Complete its browser startup before starting the bridge below. The runtime creates window.Shopify.analytics. Use the current Shopify scripts API  for the selected Shopify SDK version.
  4. Connect the platform’s consent dialog through Shopify’s custom-banner mode. Wait for a resolved choice and successful setTrackingConsent before delivery. Update all four Shopify purposes: analytics, marketing, preferences, and sale_of_data. An analytics grant must not grant the other purposes. Subscribe to later choices before you read the saved choice. Forward withdrawal as well. Map purposes from the approved consent policy. Leave an unknown choice pending. See the Customer Privacy API .
  5. Create a trusted JavaScript integration and select it in the target Website-Domains record. In Required consents, select the Consent record with key ANALYTICS_STORAGE. Start it only after the Shopify runtime is initialized. Define public Shopify identifiers as constants in the source. Keep private tokens on the server. Scripts can subscribe to all standard events.

Keep the Shopify consent connection active when the analytics subscription stops. Otherwise, withdrawal can stop application event delivery without updating Shopify’s consent state. The integration must examine the application’s analytics grant. Shopify must apply its own privacy state before it sends events.

Bridge page views for visitor sessions

Enter this source in the trusted integration’s JavaScript field. The host must complete the setup above before it enables this integration.

const shopifyAnalytics = window.Shopify?.analytics; if (!shopifyAnalytics) throw new Error('Initialize Shopify analytics first.'); analytics.subscribe('page_viewed', (event) => { shopifyAnalytics.publish('page_viewed', { url: event.context.document.location.href, customData: { integrationEventId: event.id }, }); });

Shopify accepts an explicit page URL in its page-view payload . Use the captured URL because event delivery can occur after capture. The local URL excludes query parameters and fragments. This example does not add campaign parameters back into the event. Campaign attribution needs a separate review.

Start one bridge for each active integration instance. Do not install a second Shopify route tracker that publishes the same page views. The application bus supplies the initial view and later application route views. Stop the subscription when the integration is disabled, its configuration changes, or its scope ends. Use Shopify session handling for visitor identity. Application event IDs and page-view IDs are not Shopify visitor or session IDs.

This bridge publishes to Shopify’s bus. The application API exposes subscriptions. This version does not support publication of custom application events. It also does not use Shopify’s pixel analytics.subscribe API: that API lets pixels consume events on Shopify-managed surfaces.

For ecommerce payload requirements, use the Shopify mapping reference. Do not assume that matching application and Shopify event names have matching payloads.

Verify Shopify admin results

  1. Use a published production-like hostname connected to the selected store. Examine the channel and token requirements for the selected Shopify SDK version. Confirm the current channel, hostname, and session requirements in the Shopify analytics setup  before enabling Shopify admin reporting.

  2. In a fresh browser session, deny analytics consent. Confirm that the bridge sends no analytics events. Grant analytics consent, open a page, and navigate to another page. Test Shopify runtime delivery, the first-party proxy, and session continuity across reloads. Do not treat an application delivered diagnostic as confirmation that Shopify stored the event.

  3. Open Analytics → Live View in Shopify admin with an account that has analytics access. Confirm visitor activity from the test device. Examine the session reports. Live View defines active visitors through a recent activity period. It does not count open browser connections. Compare against Shopify’s Live View definitions .

  4. After adding ecommerce mappings, test a confirmed cart addition, quantity reduction, cart view, and checkout. Make sure the same Shopify session continues into checkout. Make sure each action appears once. Validate each domain and market separately.

  5. Withdraw analytics consent. Confirm both that the bridge stops and that Shopify receives the updated choice. Test disable and re-enable for duplicate subscriptions. Blockers, consent, and Shopify’s report rules can make its visitor counts differ from the platform’s realtime display.

Complete this end-to-end test before you enable the integration in production. The documentation example alone does not enable Shopify admin analytics.

Last updated on