Logo Hydrogen Analytics Tracking

Hydrogen Analytics Tracking

Tổ chức
Weaverse
hydrogen-analytics-tracking

Phân tích và theo dõi chuyển đổi toàn diện trên Shopify Hydrogen — GTM, GA4 (trình duyệt + Measurement Protocol), Meta Pixel + CAPI, Google Ads, chế độ đồng ý, CSP, bộ nhớ đệm toàn trang Oxygen. Các phương pháp đã được áp dụng thực tế trong môi trường production.

Add to TypingMind

Tổng quan

Nhà phát hànhWeaverse
Kho mãshopify-hydrogen-skills
Tên kỹ nănghydrogen-analytics-tracking
Sao
87
Bản fork
26
Tệp đi kèm
7
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 7 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được Weaverse công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Hydrogen Analytics Tracking trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/Weaverse/shopify-hydrogen-skills/tree/main/skills/hydrogen-analytics-tracking
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Weaverse/shopify-hydrogen-skills.git /tmp/shopify-hydrogen-skills
mkdir -p .claude/skills
cp -r /tmp/shopify-hydrogen-skills/skills/hydrogen-analytics-tracking .claude/skills/hydrogen-analytics-tracking
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Hydrogen Analytics Tracking trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Hydrogen Analytics Tracking ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Hydrogen Analytics Tracking với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

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 shared event_id for cross-side deduplication. Covers consent mode v2, CSP strict-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-Control header.

If you just want page_view + Hydrogen's built-in <Analytics.Provider> cart events forwarded to GA4 via GTM, the Shopify docs are enough. Come here when you need the full funnel.


The mental model

Three layers of tracking

LayerWhere it runsStrengthsWeaknesses
Browser (GTM → pixels)dataLayer.push() → GTM tags → GA4, Meta Pixel, Google Ads, TikTokRich user context, fbp/fbc cookies, instant client-side ECommerce eventsITP, ad-blockers, page-navigation race conditions
Server-side (/api/track)Hydrogen worker → GA4 MP, Meta CAPI, Google Ads Enhanced ConversionsSurvives ad-blockers, runs even when client unloads, can be triggered by webhooksLoses some context (no fbp without forwarding), needs IP + UA + match keys
Vendor pipes you don't controlShopify "Google & YouTube" sales channel app, Shopify Customer Events PixelWorks inside Shopify checkout (where merchant GTM can't go), Shopify-blessedLimited 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:

  1. Generates a UUID event_id once on the client.
  2. Pushes to dataLayer with that event_id → GTM → browser pixels send the hit with event_id as the dedup key.
  3. POSTs to /api/track via navigator.sendBeacon with the same event_id → server forwards to GA4 MP / Meta CAPI / Google Ads with the same key.
  4. Each vendor's backend dedupes on (event_name, event_id) → exactly one count, not two.
ts
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;
}

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 to <Analytics.Provider customData={{ experiments: { '<id>': '<variant>' } }}>. customData is merged into every event, so add_to_cart / purchase are already tagged with the variant — this is what measures conversion impact, not just impressions. No need to re-attach the experiment per event.
  • Fire an impression event. Call useAnalytics().publish('custom_experiment_viewed', { experimentId, variantId }) from the experiments onExpose callback, gated on canTrack(). Bridge custom_experiment_viewed → dataLayer/GA4 in your <CustomAnalytics> subscriber like any other custom event (custom_ prefix required; call ready()).
  • Dedup. Exposure is an impression, not a conversion, so the 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).


Reference files

Read these in order if you're implementing from scratch. Skip to the relevant one if you're debugging:

ReferenceRead if you're…
architecture.mdSetting up the whole pipeline. Covers the dual-send pattern, dedup contract, vendor responsibilities, and how the pieces fit together.
gtm-meta-implementation.mdWiring up GTM dataLayer pushes, GA4 Event tags, Meta CAPI forwarder. Real code patterns.
webhook-forwarding-via-builder.mdWeaverse-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.mdBridging the webhook cookie gap: how to get _fbp / _fbc / gclid / affiliate click IDs from the browser into the Shopify orders webhook. Covers the two cart entry paths (POST action AND /cart/<id>:<qty> loader) that both need stash logic.
oxygen-full-page-cache.mdConfiguring FPC, why Set-Cookie disables it, the entry.server.tsx strip trick.
csp-for-tracking.mdCSP directives that allow Google/Meta/Hotjar; nonce vs strict-dynamic; GTM Custom HTML tags and inline-script violations.
gotchas.mdThe bugs that bite every implementation. Read this first if something isn't working.

Five things every Hydrogen tracking implementation gets wrong

  1. Using Hydrogen's PRODUCT_ADD_TO_CART analytics event for add_to_cart. Hydrogen diffs cart state after revalidation and emits the event then. The timing is unreliable — events often miss GA4 DebugView entirely. Fix: fire add_to_cart directly from the button onClick handler via sendBeacon (it survives the form submit / navigation).

  2. Loading GTM after hydration via <Script waitForHydration>. It hides GTM from Tag Assistant standalone scans and blocks the move to nonce-based strict-dynamic CSP. Fix: load gtm.js as a regular <script async nonce={nonce}> in <head>, with the inline gtm.start + Consent Mode v2 default-deny block before it.

  3. 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.

  4. Letting <Analytics.ProductView> gate on selectedVariant. For combined listings or any product where the variant resolves after hydration, the analytics component never mounts and view_item doesn't fire. Fix: mount unconditionally with safe per-variant fallbacks.

  5. 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"].

  6. 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.

  7. 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 subscriber in app/components/root/custom-analytics.tsx. Include index (list position) for GA4. Ensure the collection query returns id, title, handle, and priceRange so the values exist to push.


The order to build it

If you're starting fresh on a new Hydrogen storefront:

  1. Hydrogen <Analytics.Provider> wired at root. Subscribe to its events in a <CustomAnalytics /> component. (See architecture.md)
  2. Inline <head> Consent Mode v2 default-deny block + dataLayer + gtm.start marker.
  3. gtm.js external script with nonce, async, in <head> after the inline block.
  4. trackEvent() helper that pushes dataLayer + sendBeacon('/api/track') with shared event_id.
  5. /api/track server endpoint that validates the payload, hashes PII server-side, fans out to GA4 MP + Meta CAPI + Google Ads forwarders.
  6. Shopify orders/create webhook that maps the order to a purchase event with event_id = "purchase_" + orderId (deterministic for retries).
  7. Shopify "Google & YouTube" sales channel + Customer Events Pixel for checkout-side events (Meta Pixel events, anything that needs to fire inside Shopify checkout where your GTM can't reach).
  8. GTM container with one GA4 Event tag per dataLayer event, plus Meta Pixel + TikTok + Google Ads conversion tags as needed.
  9. CSP updated to allow all vendor domains in script-src, connect-src, img-src. Use strict-dynamic + nonce.
  10. Oxygen full-page cache opted in per route via Oxygen-Cache-Control: public, max-age=N, ... header. Strip Set-Cookie from cacheable responses in entry.server.tsx.

Skill-level conventions

When working on a Hydrogen tracking implementation in this skill's scope:

  • Server code lives under app/.server/tracking/ (forwarders, validators, hash util, audit log).
  • Client helper at app/utils/track-client.ts (exports trackEvent, consent listener, attribution capture).
  • dataLayer bridge at app/components/root/custom-analytics.tsx (subscribes to Hydrogen <Analytics.Provider> events).
  • Inline Consent Mode + GTM bootstrap in app/root.tsx <head>, with nonce.
  • CSP config at app/weaverse/csp.ts (Weaverse projects) or wherever your storefront sets CSP.
  • Per-vendor forwarder modules at 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.


Live 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:

bash
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:

bash
# 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 "analytics provider"

# Weaverse (if using Weaverse CMS)
node ../shopify-hydrogen/scripts/search_weaverse_docs.mjs "csp"

Vendor docs (open in browser, no script):

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Hydrogen Analytics Tracking làm được gì?

Phân tích và theo dõi chuyển đổi toàn diện trên Shopify Hydrogen — GTM, GA4 (trình duyệt + Measurement Protocol), Meta Pixel + CAPI, Google Ads, chế độ đồng ý, CSP, bộ nhớ đệm toàn trang Oxygen. Các phương pháp đã được áp dụng thực tế trong môi trường production.

Vì sao nên dùng Hydrogen Analytics Tracking trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Hydrogen Analytics Tracking là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Hydrogen Analytics Tracking trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/Weaverse/shopify-hydrogen-skills/tree/main/skills/hydrogen-analytics-tracking. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Hydrogen Analytics Tracking?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Hydrogen Analytics Tracking với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Hydrogen Analytics Tracking với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Hydrogen Analytics Tracking có miễn phí không?

Kỹ năng này được Weaverse phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇