weaverse/shopify-hydrogen-skills/hydrogen-analytics-tracking
Claude Code and agent skill by weaverse/shopify-hydrogen-skills
- community
Checking that the SKILL.md file is still in the repository.
End-to-end analytics & conversion tracking on Shopify Hydrogen — GTM, GA4 (browser + Measurement Protocol), Meta Pixel + CAPI, Google Ads, consent mode, CSP, Oxygen full-page cache. Real-world patterns from production deployments.
Install
npx vskill@latest install weaverse/shopify-hydrogen-skills/hydrogen-analytics-trackingSKILL.md
The same SKILL.md was published earlier as weaverse/shopify-hydrogen-skills/hydrogen-analytics-tracking.
Hydrogen Analytics & Tracking — Agent Skill
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.
When to use this skill
You need this if you're:
- Implementing GA4 / Meta / Google Ads / TikTok tracking on Hydrogen and the default Hydrogen Analytics components aren't enough.
- Adding server-side tracking (Measurement Protocol, Conversions API) for resilience against ad-blockers and ITP.
- Debugging "event X is in GTM Preview but not in GA4 / Meta".
- Wiring up conversion deduplication between browser pixel and server CAPI.
- Setting up tracking on a Hydrogen storefront with Weaverse as the CMS layer.
- Investigating why Oxygen full-page cache is being disabled despite a correct
Oxygen-Cache-Controlheader.
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; see `architecture.md` for what replaces them. To migrate a classic storefront first, use thehydrogen-upgradesskill.
The mental model
Three layers of tracking
| 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).
Dual-send + event_id dedup
The cornerstone pattern. Every trackable event:
- Generates a UUID `event_id` once on the client.
- Pushes to `dataLayer` with that
event_id→ GTM → browser pixels send the hit withevent_idas the dedup key. - POSTs to `/api/track` via
navigator.sendBeaconwith the sameevent_id→ server forwards to GA4 MP / Meta CAPI / Google Ads with the same key. - Each vendor's backend dedupes on
(event_name, event_id)→ exactly one count, not two.
Why sendBeacon, why not fetch?
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.
Why event_id can't come from the server
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.
Experiment exposure (A/B tests)
A/B tests on a Weaverse storefront use `@weaverse/experiments` — deterministic, project-level variant assignment. Exposure rides the same pipeline as every other event:
- Segment downstream events by variant. Pass the resolved assignments as bus config:
<ShopifyScripts analytics={{ channel, customData: { experiments: { '<id>': '<variant>' } } }} />. The bus copiescustomDatainto its cart events (cart_updated,product_added_to_cart,product_removed_from_cart) but not into events you publish, so your destination reads it withgetConfig().customData(from thesetupcontext) and attaches it to everydataLayerpush /trackEvent()payload. That tagsadd_to_cart/purchasewith 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. - Fire an impression event. The bus accepts only its own event names (it warns and drops anything else), so don't publish
custom_experiment_viewedto it. From the experimentsonExposecallback, gated on your consent check (canTrack()), push it straight todataLayeror calltrackEvent({ event_name: 'experiment_viewed', custom_data: { experimentId, variantId } }). - Dedup. Exposure is an impression, not a conversion, so the
event_iddual-send is usually unnecessary. If you forward it to/api/track, reuse the storefronttrackEvent()helper.
Server-side getExperiments() wiring lives in the weaverse-hydrogen skill (Multi-Project Architecture → A/B Testing).
Reference files
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. |
Five things every Hydrogen tracking implementation gets wrong
- 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: fireadd_to_cartdirectly from the button onClick handler viasendBeacon(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-basedstrict-dynamicCSP. Post-hydration injection hides GTM from the scan, and an injected script carries no nonce. Fix: loadgtm.jsas a regular<script async>in<head>(addnonce={nonce}in nonce mode), with the inlinegtm.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_VIEWEDnever mounts andview_itemdoesn't fire. Fix: mount unconditionally and fall back toselectedOrFirstAvailableVariant.
- 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 withdata_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_itemis a click (user clicks a product card in a list) — fire it from the product card'sonClickon the collection/PLP, where you already hold the product + collection + index.view_item_listis a view — push it from theCOLLECTION_VIEWEDsubscription of your bus destination inapp/components/root/custom-analytics.tsx(and make sure the collection route renders a tracker that publishesCOLLECTION_VIEWED). Includeindex(list position) for GA4. Ensure the collection query returnsid,title,handle, andpriceRangeso the values exist to push.
The order to build it
If you're starting fresh on a new Hydrogen storefront:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/hydrogen-analytics-tracking/SKILL.md
Popularity
- Repository stars
- 34
- Repository forks
- 1
- 7-day trend score
- 18
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 4 Jun 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/weaverse/shopify-hydrogen-skills/hydrogen-analytics-tracking)