Shopify + Web Tracking
Last updated: 2026-05-13
Install DATALYR from the Shopify App Store. The pixel, theme embed, webhooks, and a 30-day historical order backfill all set up automatically — no code changes required for standard themes.
App Store listing: apps.shopify.com/datalyr · Integration reference
Step 1: Install from the Shopify App Store
The Datalyr Shopify app handles install, billing, and webhook registration through Shopify itself — no API keys, no manual webhook paste.
- Go to apps.shopify.com/datalyr and click Install
- Approve the OAuth scopes Shopify requests on your behalf
- Sign in to (or create) your Datalyr account and pick a workspace
- Pick a plan — Starter / Growth / Scale — and approve the Shopify Billing charge
Once approved, you land on Sources with the Shopify integration marked Active. The 30-day historical order backfill begins immediately.
Step 2: What gets installed automatically
You don’t need to add any code to your theme. The Datalyr Shopify app installs everything for you:
- Web Pixel — subscribes to checkout_started, checkout_completed, page_viewed, product_viewed, add_to_cart, cart_viewed, search, payment_info_submitted, collection_viewed
- Theme app embed — loads
dl.jsandcontainer.json every storefront page for first-touch attribution capture (utm_*, fbclid, gclid, ttclid) - Webhook subscriptions — orders/paid, orders/create, orders/fulfilled, orders/cancelled, refunds/create, checkouts/create, checkouts/update, customers/create
- GDPR compliance webhooks — customers/data_request, customers/redact, shop/redact (mandatory per Shopify App Store rules)
- 30-day historical backfill — your last 30 days of orders sync into Datalyr immediately
Step 3: Confirm the theme app embed is enabled
The pixel handles checkout events, but first-touch click IDs (fbclid, gclid, ttclid) and UTMs are captured by the theme app embed on the storefront. If the embed is off, your purchase events will arrive with no attribution data.
- In your Shopify admin: Online Store → Themes → Customize
- Open App Embeds in the left sidebar
- Find Datalyr Analytics and confirm the toggle is ON
- Click Save
Step 4: Headless / Hydrogen — pass visitor_id manually
Standard Shopify themes handle visitor_id propagation automatically. If you run Shopify Hydrogen, a headless storefront, or any custom client that builds carts via the Storefront API, you need to set the Datalyr visitor ID as a cart attribute so the orders/paid webhook can match the purchase back to the original click.
const visitorId = datalyr.getVisitorId();
await fetch('/api/cart/attributes', {
method: 'POST',
body: JSON.stringify({
attributes: [
{ key: '_datalyr_visitor_id', value: visitorId }
]
})
});Datalyr’s orders/paid webhook reads order.note_attributes['_datalyr_visitor_id'] and threads attribution directly. Without this, headless merchants fall back to email matching (70-85% match rate vs 90%+).
Step 5: Connect your ad platforms
Connect your ad platforms so Datalyr can match ad spend to Shopify revenue and forward conversions server-side.
- Meta (Facebook / Instagram)
- Google Ads
- TikTok
- Other: reach out at hello@datalyr.com
Step 6: Set up conversion rules
Configure conversion rules to send the right events back to your ad platforms so they can optimize for actual revenue — not just product views or add-to-carts.
- Go to Conversions → Add Rule
- Pick your trigger event (e.g.
purchase,add_to_cart), choose your ad platform, and set the conversion value - Hit Save — it’s live immediately
Step 7: Verify it's working
- Place a test order in your store (test payment gateway or a real order you immediately refund)
- Open Live in your dashboard — the pixel events appear within ~10 seconds, the orders/paid webhook event arrives within ~60 seconds
- Click the purchase event and confirm attribution fields are populated (utm_source, fbclid, gclid, etc.)
- If the purchase event arrives but attribution is empty, your theme app embed is likely OFF — go back to Step 3
Best practices
- Leave the theme app embed enabled in production. It’s a deferred script and adds essentially zero load time — but disabling it breaks first-touch attribution.
- Don’t track purchase events with the Web SDK (
datalyr.track('purchase', ...)) on your Shopify storefront. The Web Pixel + orders/paid webhook handle revenue — anything client-fired is unreliable (refunds, declines, abandoned carts). - For headless storefronts, set
_datalyr_visitor_idas a cart attribute on every cart create / update. This is the single biggest lever on attribution quality for non-standard storefronts. - Optimize your ad platforms for
purchaseevents, notadd_to_cart. Add-to-cart is a useful funnel signal but it’s not the revenue event.
Why we built it as a Shopify app
Shopify themes are merchant-owned, theme updates rip out custom code, and asking merchants to paste a script tag works for some but not all. The Shopify app model solves this:
- Install / uninstall is one click — no code edits required
- Pixel + theme embed survive theme switches automatically
- Webhook subscriptions are registered on install and removed on uninstall — no leftover state
- Billing happens through Shopify Billing — the merchant manages everything from their Shopify admin, no separate payment method
- GDPR compliance (customers/data_request, customers/redact, shop/redact) is wired in by default