/weaverse:hydrogen-analytics-trackingfrom weaverse
Builds end-to-end analytics and conversion tracking on Shopify Hydrogen: GTM, GA4 (browser + Measurement Protocol), Meta Pixel + CAPI, Google Ads, consent mode v2, CSP, and Oxygen full-page cache. Covers cross-side deduplication and production gotchas.
Ships in weaverse. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Build a complete tracking pipeline on Shopify Hydrogen: client dataLayer → GTM → browser pixels, AND server
/api/track→ GA4 MP / Meta CAPI / Google Ads, with sharedevent_idfor cross-side deduplication. Covers consent mode v2, CSPstrict-dynamic, Oxygen full-page cache compatibility, and the surprising gotchas that bite every implementation.
This skill encodes hard-won lessons from production tracking work on Hydrogen storefronts. The reference files contain detailed implementations; this top page is the map.
You need this if you're:
Oxygen-Cache-Control header.If you just want page_view + Hydrogen's cart events (<ShopifyScripts> + useCartAnalytics()) forwarded to GA4 via GTM, Shopify's packaged hydrogen-analytics skill (node_modules/@shopify/hydrogen/skills/hydrogen-analytics/; copy it into the project with npx @shopify/hydrogen skills sync) is enough. Come here when you need the full funnel.
Hydrogen 2026.10. This skill targets Hydrogen 2026.10 and
@weaverse/hydrogen6, with Pilotmainas the reference implementation. Classic analytics (Analytics.Provider,<Analytics.*View>,useAnalytics(),getShopAnalytics) andCartForm/context.cartare gone; seearchitecture.mdfor what replaces them. To migrate a classic storefront first, use thehydrogen-upgradesskill.
| Layer | Where it runs | Strengths | Weaknesses |
|---|---|---|---|
| Browser (GTM → pixels) | dataLayer.push() → GTM tags → GA4, Meta Pixel, Google Ads, TikTok | Rich user context, fbp/fbc cookies, instant client-side ECommerce events | ITP, ad-blockers, page-navigation race conditions |
Server-side (/api/track) | Hydrogen worker → GA4 MP, Meta CAPI, Google Ads Enhanced Conversions | Survives ad-blockers, runs even when client unloads, can be triggered by webhooks | Loses some context (no fbp without forwarding), needs IP + UA + match keys |
| Vendor pipes you don't control | Shopify "Google & YouTube" sales channel app, Shopify Customer Events Pixel | Works inside Shopify checkout (where merchant GTM can't go), Shopify-blessed | Limited customization, can DUPLICATE merchant GTM if same vendor set up twice |
The combination matters. A complete pipeline uses all three: GTM for storefront pages, server-side for resilience and dedup, vendor pipes for checkout pages (which Shopify Plus locks down).
The cornerstone pattern. Every trackable event:
event_id once on the client.dataLayer with that event_id → GTM → browser pixels send the hit with event_id as the dedup key./api/track via navigator.sendBeacon with the same event_id → server forwards to GA4 MP / Meta CAPI / Google Ads with the same key.(event_name, event_id) → exactly one count, not two.function trackEvent({ event_name, custom_data, user_data }) {
const event_id = crypto.randomUUID();
// (1) Browser side
window.dataLayer.push({ event: event_name, event_id, ...custom_data });
// (2) Server side, same event_id
const payload = { event_id, event_name, custom_data, user_data, consent };
navigator.sendBeacon("/api/track", new Blob([JSON.stringify(payload)]));
return event_id;
}
Add-to-cart, begin_checkout, "Buy now" — these all trigger page navigation immediately after. A regular fetch() gets cancelled when the page unloads, losing the event. sendBeacon is the browser API designed exactly for this: the request is queued by the browser and guaranteed to be sent even after navigation. Fall back to fetch(..., {keepalive: true}) if sendBeacon isn't available.
If the server generates event_id, the browser already pushed its dataLayer event with a different (or no) id, and there's no way to backfill. Always generate client-side, send both directions with the same value.
A/B tests on a Weaverse storefront use @weaverse/experiments — deterministic, project-level variant assignment. Exposure rides the same pipeline as every other event:
<ShopifyScripts analytics={{ channel, customData: { experiments: { '<id>': '<variant>' } } }} />. The bus copies customData into its cart events (cart_updated, product_added_to_cart, product_removed_from_cart) but not into events you publish, so your destination reads it with getConfig().customData (from the setup context) and attaches it to every dataLayer push / trackEvent() payload. That tags add_to_cart / purchase with the variant — this is what measures conversion impact, not just impressions. Keep the assignments per market or per experiment bucket, never per shopper, or the document stops being cacheable.custom_experiment_viewed to it. From the experiments onExpose callback, gated on your consent check (canTrack()), push it straight to dataLayer or call trackEvent({ event_name: 'experiment_viewed', custom_data: { experimentId, variantId } }).event_id dual-send is usually unnecessary. If you forward it to /api/track, reuse the storefront trackEvent() helper.Server-side getExperiments() wiring lives in the weaverse-hydrogen skill (Multi-Project Architecture → A/B Testing).
Read these in order if you're implementing from scratch. Skip to the relevant one if you're debugging:
| Reference | Read if you're… |
|---|---|
architecture.md | Setting up the whole pipeline. Covers the dual-send pattern, dedup contract, vendor responsibilities, and how the pieces fit together. |
gtm-meta-implementation.md | Wiring up GTM dataLayer pushes, GA4 Event tags, Meta CAPI forwarder. Real code patterns. |
webhook-forwarding-via-builder.md | Weaverse-hosted storefronts: how Shopify webhooks reach your storefront without leaking the multi-tenant app client secret. Uses the builder WebhookForward model + per-store signing secrets. |
cart-attribute-stash.md | Bridging the webhook cookie gap: how to get _fbp / _fbc / gclid / affiliate click IDs from the browser into the Shopify orders webhook. Covers the cart entry paths (POST /api/cart AND the /cart/<id>:<qty> permalink loader) that both need stash logic. |
oxygen-full-page-cache.md | Configuring FPC, why Set-Cookie disables it, keeping documents anonymous on Hydrogen 2026.10. |
csp-for-tracking.md | CSP directives that allow Google/Meta/Hotjar with Hydrogen 2026.10.3's createContentSecurityPolicy; cacheable nonce: false vs nonce + strict-dynamic; GTM Custom HTML tags and inline-script violations. |
gotchas.md | The bugs that bite every implementation. Read this first if something isn't working. |
Using the bus's PRODUCT_ADD_TO_CART event for add_to_cart. useCartAnalytics() publishes it only after the cart store confirms the change with Shopify, so a navigation that follows the click (Buy now, checkout redirect) often drops it — events miss GA4 DebugView entirely. Fix: fire add_to_cart directly from the button onClick handler via sendBeacon (it survives the form submit / navigation).
Loading GTM after hydration (classic Hydrogen's <Script waitForHydration>, or any DOM-injected loader) when Tag Assistant standalone scans matter, or when the store wants a nonce-based strict-dynamic CSP. Post-hydration injection hides GTM from the scan, and an injected script carries no nonce. Fix: load gtm.js as a regular <script async> in <head> (add nonce={nonce} in nonce mode), with the inline gtm.start + Consent Mode v2 default-deny block before it. Pilot deliberately lazy-loads GTM for performance and uses a nonce-free policy, so this is a trade-off, not a bug, there.
Pushing GA4-named events but configuring GTM triggers with legacy snake_case names (or vice versa). After "Custom Event" renaming there's a coverage gap. Fix: match GTM trigger filters to whatever the storefront actually pushes today; do code + GTM in one coordinated change.
Letting the product view tracker gate on selectedVariant. For combined listings or any product where the variant resolves after hydration, the tracker that publishes PRODUCT_VIEWED never mounts and view_item doesn't fire. Fix: mount unconditionally and fall back to selectedOrFirstAvailableVariant.
Treating "consent denied" as "send nothing". Meta CAPI's relaxed pattern (LDU flag + ip/ua/fbp/fbc only, no hashed PII) recovers a large chunk of optimisation signal compliantly. GA4 Consent Mode v2 modeled conversions work the same way. Fix: in the server forwarder, when ad_storage !== "granted" drop hashed PII but still send the event with data_processing_options: ["LDU"].
Pasting a Liquid dataLayer.push snippet into Hydrogen. Merchants often bring an existing theme snippet using Liquid tags ({{ product.id }}, {{ collection.title }}, {{ product.price | money_without_currency }}). These do nothing in Hydrogen — it's React/SSR, there is no Liquid at runtime, so the braces render as literal text or break. Fix: rebuild the same object from Hydrogen data and push it in JS. Liquid → Hydrogen mapping: {{ product.id }} → product.id, {{ product.title }} → product.title, {{ product.price | money_without_currency }} → product.priceRange?.minVariantPrice?.amount (a string, no currency symbol), {{ collection.id/title }} → collection.id/title.
Expecting select_item / view_item_list from a built-in Hydrogen analytics event. GA4 list events don't map to cart events. select_item is a click (user clicks a product card in a list) — fire it from the product card's onClick on the collection/PLP, where you already hold the product + collection + index. view_item_list is a view — push it from the COLLECTION_VIEWED subscription of your bus destination in app/components/root/custom-analytics.tsx (and make sure the collection route renders a tracker that publishes COLLECTION_VIEWED). Include index (list position) for GA4. Ensure the collection query returns id, title, handle, and priceRange so the values exist to push.
If you're starting fresh on a new Hydrogen storefront:
<ShopifyScripts> first in the root <head>, route trackers publishing PAGE_VIEWED / PRODUCT_VIEWED / COLLECTION_VIEWED / SEARCH_VIEWED / CART_VIEWED, and useCartAnalytics() inside CartProvider. Map bus events to dataLayer in a <CustomAnalytics /> component that registers a destination with window.Shopify.analytics.addDestination(). (See architecture.md)<head> Consent Mode v2 default-deny block + dataLayer + gtm.start marker.gtm.js external script, async, in <head> after the inline block (with the nonce in nonce mode).trackEvent() helper that pushes dataLayer + sendBeacon('/api/track') with shared event_id./api/track server endpoint that validates the payload, hashes PII server-side, fans out to GA4 MP + Meta CAPI + Google Ads forwarders.orders/create webhook that maps the order to a purchase event with event_id = "purchase_" + orderId (deterministic for retries).createContentSecurityPolicy() (@shopify/hydrogen 2026.10.3) with every vendor domain in script-src, connect-src, img-src. Pilot's default is nonce: false + 'unsafe-inline' (keeps step 10 possible); nonce + strict-dynamic is stricter but makes documents uncacheable.Oxygen-Cache-Control: public, max-age=N, ... + Vary in entry.server.tsx. Keep cart and customer data out of loaders so the documents carry no Set-Cookie.When working on a Hydrogen tracking implementation in this skill's scope:
app/.server/tracking/ (forwarders, validators, hash util, audit log).app/utils/track-client.ts (exports trackEvent, consent listener, attribution capture).app/components/root/analytics-views.tsx (publish view events to window.Shopify.analytics; useCartAnalytics() for cart events).app/components/root/custom-analytics.tsx (a bus destination registered with addDestination(), so delivery follows Customer Privacy consent).app/root.tsx <head> (nonced in nonce mode).app/weaverse/csp.ts (getCspDirectives(request, checkoutDomain) in Weaverse projects), passed as directives to Hydrogen's createContentSecurityPolicy() in entry.server.tsx. Don't port a local app/utils/csp.ts: 2026.10.3 ships the helper again.app/.server/tracking/forwarders/{ga4,meta-capi,google-ads}.ts — each returns {forwarder, ok, skipped?, reason?} so the audit log can show why an event was dropped.When a question is broader than a single vendor, prefer the reference doc that addresses the architectural layer rather than one vendor's docs.
Run these from this skill's own folder. The helpers ship inside the sibling
shopify-hydrogen skill, so ../shopify-hydrogen/scripts/ exists whenever the
whole pack is installed.
If you installed this skill on its own, that folder is absent and the commands
below fail with MODULE_NOT_FOUND. Add the helpers once:
npx skills add Weaverse/shopify-hydrogen-skills --skill shopify-hydrogen
The references/ files in this skill remain a usable offline fallback if you
would rather not install it.
For up-to-date official sources:
# Shopify Hydrogen / Oxygen
node ../shopify-hydrogen/scripts/search_shopify_docs.mjs "oxygen full-page cache"
node ../shopify-hydrogen/scripts/search_shopify_docs.mjs "consent mode"
node ../shopify-hydrogen/scripts/search_shopify_docs.mjs "ShopifyScripts analytics"
# Weaverse (if using Weaverse CMS)
node ../shopify-hydrogen/scripts/search_weaverse_docs.mjs "csp"
Vendor docs (open in browser, no script):
references/architecture.md (opens in a new tab)references/cart-attribute-stash.md (opens in a new tab)references/csp-for-tracking.md (opens in a new tab)references/gotchas.md (opens in a new tab)references/gtm-meta-implementation.md (opens in a new tab)references/oxygen-full-page-cache.md (opens in a new tab)references/webhook-forwarding-via-builder.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub weaverse/shopify-hydrogen-skills --plugin weaverse14 skills in this plugin
/cloning-websites-to-weaverseUse when recreating a reference website or brand hub in this Hydrogen plus Weaverse repo, especially when deciding whether to reuse sections, add global styles, update theme schema, or resolve conflicts between the live site and project brand guidelines./figma-to-weaverseUse when recreating a Figma design as Hydrogen + Weaverse pages in this repo — turning a Figma file, frame, or flow into reusable Weaverse sections. Triggers on a figma.com URL, "build this design", "implement this Figma", or "create the storefront from the design". The Figma counterpart of cloning-websites-to-weaverse./generating-weaverse-project-jsonUse when generating Weaverse project export JSON for import into the Weaverse editor. Triggers on requests to create, build, or produce a Weaverse project JSON file from a site migration, design spec, page layout description, or existing export. Also use when converting section plans into importable project and pages data./hydrogen-cookbooksStep-by-step implementation guides for building features in a Shopify Hydrogen 2026.10 + Weaverse storefront (Pilot) — bundles, combined listings, customer accounts, 3D models, performance, variant media, and Weaverse integration./hydrogen-markets-localizationImplement or review Shopify Hydrogen market localization — use when adding markets, locale routes, translations, hreflang, RTL, or localized cart, account, and checkout behavior in Hydrogen + Weaverse./hydrogen-upgradesStep-by-step guides for upgrading Shopify Hydrogen between versions — breaking changes, code diffs, and migration steps for each release.Other plugins' skills for the same job