Documentation Index
Fetch the complete documentation index at: https://docs.weaverse.io/llms.txt
Use this file to discover all available pages before exploring further.
Analytics & Conversion Tracking
Setting up analytics and conversion tracking in a headless Hydrogen store requires understanding that your site spans two separate environments — each with different tracking capabilities. This guide covers everything you need to know to get complete, accurate tracking across your entire customer journey.Architecture: Two Environments
When you build with Hydrogen + Weaverse, your store runs on two separate systems:| Hydrogen Storefront | Shopify Checkout + Thank You | |
|---|---|---|
| URL | yourstore.com | checkout.shopify.com or custom checkout domain |
| What it serves | Home, products, collections, cart, blog | Checkout, order confirmation, order status |
| Your code runs? | ✅ Yes — full control | ❌ No — Shopify-hosted |
| GTM loaded? | ✅ Yes (if you added it) | ❌ No — GTM from Hydrogen does NOT carry over |
| Tracking method | Standard GTM/web pixels | Shopify Customer Events (Custom Pixels) |
Part 1: Tracking on the Hydrogen Storefront
Your Hydrogen storefront (home, products, collections, cart, etc.) is a standard web application — you can load any analytics script just like a regular website.Option A: Google Tag Manager (Recommended)
GTM gives you a centralized tag management layer without modifying code for every new tracking pixel.Setup
Add the GTM script to your root layout (app/root.tsx):
GTM-XXXXXXX with your actual GTM container ID.
If you have Content Security Policy enabled, add
www.googletagmanager.com and www.google-analytics.com to your script-src directives.Pushing Page Views and Events
GTM automatically tracks page views if you’ve configured a GA4 tag with the “All Pages” trigger. For custom events, push to the dataLayer from your components:Option B: Direct GA4 Script
If you don’t need GTM, you can load gtag.js directly:G-XXXXXXXXXX with your GA4 Measurement ID.
Part 2: Tracking on Checkout & Thank-You Page
This is where most headless stores have a gap. Since checkout and the thank-you page are hosted by Shopify, you cannot inject GTM or analytics scripts directly.Shopify Custom Pixels
Shopify provides a Customer Events system (also called Custom Pixels) as the only supported way to track events on checkout and post-purchase pages.How Custom Pixels Work
Custom Pixels run in a sandboxed JavaScript environment inside Shopify’s checkout. They receive events from Shopify’s analytics bus and can forward them to external services.Setup: GTM via Custom Pixel
This approach loads GTM inside the Shopify Custom Pixel sandbox and pushes checkout events to the dataLayer — giving you a unified dataLayer across both Hydrogen and checkout.Step 1: Create the Custom Pixel
- Go to Shopify Admin → Settings → Customer Events
- Click Add custom pixel
- Name it (e.g., “GTM Checkout Tracking”)
- Set permissions:
access_consent— needed for cookie consent gating
- Paste the code below and click Save
Step 2: Custom Pixel Code
Step 3: Configure GTM Triggers
In your GTM container, create triggers for the dataLayer events:-
Purchase trigger:
- Trigger type: Custom Event
- Event name:
purchase
-
Begin Checkout trigger:
- Trigger type: Custom Event
- Event name:
begin_checkout
-
GA4 Purchase tag:
- Tag type: GA4 Event
- Event name:
purchase - Event parameters: map from
ecommercedataLayer variables - Trigger: the Purchase trigger above
Setup: Direct GA4 via Custom Pixel (No GTM)
If you prefer to send events directly to GA4 without GTM on checkout:Part 3: Third-Party Conversion Pixels
For third-party ad platforms (Meta Pixel, Traffic Junky, TikTok Pixel, etc.) that need conversion data from the thank-you page, use the same Custom Pixel approach:Cookie Consent & Analytics
Analytics tracking on both environments is gated by cookie consent. If a visitor hasn’t accepted cookies, tracking will be suppressed.- Hydrogen storefront: Your GTM/gtag scripts respect the Cookie Consent Banner state
- Shopify checkout: Custom Pixels have access to
consent.analyticsAllowed— you can check this before firing events
Checkout Cookie Banner
Shopify offers a separate “Show cookie banner in checkout” option (Settings → Checkout → Customer consent). Our recommendation:- Don’t enable it unless you’re legally required to (GDPR/EU, UK PECR, etc.)
- The storefront consent banner already captures the visitor’s cookie preference, and Shopify’s Customer Privacy API propagates that signal to checkout automatically
- Enabling the checkout banner adds friction and reduces conversion rate — Shopify themselves warn about this
- For stores targeting non-EU markets (US, APAC, etc.), the storefront banner alone is sufficient
Avoiding Duplicate Events
If you have the Google & YouTube Shopify channel installed, it already fires GA4 events via its own Web Pixel. Adding a Custom Pixel that also sends GA4 purchase events will cause duplicate transactions in your GA4 reports.How to Check
- Go to Shopify Admin → Settings → Customer Events
- Look for pixels named like “Google Analytics” or created by the Google & YouTube channel
- If a Google pixel exists, you have two options:
Option A: Disable the Google Channel Pixel (Recommended)
Keep your GTM Custom Pixel as the single source of truth:- In Customer Events, find the pixel created by the Google & YouTube channel
- Click the ⋯ menu → Disconnect (this stops the channel’s pixel but keeps the app installed)
Option B: Use Only the Google Channel Pixel
If you don’t need GTM on checkout, let the Google & YouTube channel handle GA4 on checkout and thank-you pages. No Custom Pixel needed — just make sure your GA4 property is connected in the channel settings.Debugging
GA4 DebugView (Recommended)
GA4 DebugView shows events in real-time, which is essential for verifying checkout tracking:- Install the GA Debugger Chrome extension
- Enable the extension
- Open GA4 → Configure → DebugView
- Place a test order — you should see
purchaseevents appear in real-time
GTM Preview Mode
GTM’s Tag Assistant / Preview mode works on your Hydrogen storefront but has limitations:- ✅ Works on: home, products, collections, cart
- ❌ Does not work on: checkout, thank-you page (sandboxed environment)
- ❌ Does not work on: Shopify’s Custom Pixel sandbox
Common Issues
”No purchase events in GA4”
- Check cookie consent — if the visitor didn’t accept cookies, events are suppressed
- Check for ad blockers — they block GA4/GTM requests
- Verify the Custom Pixel is connected (not just saved) in Customer Events
- Use GA4 DebugView to see if events are being sent but not processed
”Duplicate purchase events”
See Avoiding Duplicate Events above.”Custom Pixel shows ‘Disconnected’”
Go to Customer Events → [your pixel] → ⋯ → Connect. Pixels must be explicitly connected after creation.”Events work with cookie consent but not without”
This is expected behavior. Shopify’s analytics bus respects consent settings. See Cookie Consent & Analytics for handling this in your pixel code.Summary
| Tracking Need | Where | Method |
|---|---|---|
| Page views, product views, cart activity | Hydrogen storefront | GTM or gtag.js in root.tsx |
| Checkout events, purchase conversion | Shopify checkout/thank-you | Shopify Custom Pixel |
| Third-party conversion pixels | Shopify thank-you page | Shopify Custom Pixel |
| Cookie consent management | Both environments | Cookie Consent Banner |