Shopify
PennyLens auto-detects Shopify stores — including Shopify Plus, hydrogen-fronted storefronts, and the standard Online Store 2.0 themes. Drop the SDK snippet onto your storefront and cart_add, checkout_started, and purchase start flowing without any further wiring.
This page covers what auto-detect actually does, what to expect on Shopify's hosted checkout, and how to recover when events aren't flowing.
When auto-detect activates
When the SDK loads, it checks three signals. Any single positive enables the Shopify hooks:
window.Shopifyglobal — present on virtually every Shopify storefront, including custom-coded themes and headless setups that ship with the Shopify JS.- A
/cdn/shopifyor/cdn/shopifycloud/script tag — catches Shopify's core scripts even when the global is unavailable (rare CSP setups). - A
template-*body class (e.g.template-product,template-cart,template-checkout) — set by all stock Dawn-derived themes via the standard theme layout.
The check runs cheapest-first, short-circuits on the first positive, and silently no-ops on non-Shopify sites. The auto-detect logic ships in the core 8 KB SDK bundle.
Cart events
PennyLens intercepts the Shopify Ajax Cart API to capture cart_add without any theme modification:
/cart/add.js(and the GraphQL Storefront equivalent on hydrogen sites) — every line item added to the cart emits acart_addevent withproduct_id,variant_id,quantity, and the line total./cart/update.jsand/cart/change.js— quantity edits and removals update the cart-state model used for abandonment analysis, but don't emit duplicatecart_addevents.
Exactly one network-level interceptor is installed per page, shared with any other PennyLens e-commerce integration to avoid stacking patches.
Checkout and purchase
Shopify's checkout runs on Shopify-owned domains (or a checkout.* subdomain on Plus). Cross-domain JavaScript can't follow the user there, so PennyLens uses two anchor pages:
checkout_started— emitted when the customer lands on/checkouton your storefront, or when they click the standard checkout button on/cart. The event includescart_valueanditem_countfrom the captured cart state.purchase— emitted when the order status page (/thank_you//orders/*/authentication) loads. The event includesorder_id,total,currency, andtax. On Shopify Plus stores with custom checkout extensions, an additional Web Pixel app event (checkout_completed) is captured as a backup signal.
For per-customer attribution, install the PennyLens Web Pixel from the Shopify app store. Without it, purchases still capture but customer identity is anonymous beyond the order ID.
Mutual exclusion with WooCommerce
If both Shopify and WooCommerce signals appear on the same page — usually only on agency development sites — Shopify takes precedence and the WooCommerce auto-hook silently no-ops. Manual wiring still works on dual-signal sites.
Zero-event fallback
If 24 hours after install you don't see any events in the PennyLens dashboard, walk through these in order:
- Confirm the SDK is loaded. Open your storefront's browser developer console and run
window.PennyLens. It should be defined. If it isn't, check that the snippet is in your theme'stheme.liquid<head>block — not just on/products/*pages. - Confirm Shopify is detected. In the same console, run
window.Shopify. It should be a non-null object. If it'sundefined, your theme has stripped the standard Shopify JS — fall back to manual wiring. - Check the Web Pixel app (Shopify Plus only). If the dashboard shows
cart_addevents but nopurchaseevents, the order status page redirect may be skipping the standard/thank_youroute. Install the PennyLens Web Pixel from the Shopify app store to capture purchases directly through Shopify's events API. - Headless storefronts. Hydrogen and other custom storefronts that don't render the standard Shopify body classes or load
/cdn/shopifyscripts won't trigger auto-detect. Use the manual snippet in the SDK reference — same API as any custom event.
Confidence indicator
Once at least one cart_add or purchase event has arrived, the dashboard Overview displays a confidence badge above the KPI row:
Shopify detected — 1,247 events captured
The badge is informational — no action required when it appears. If you don't see it after 24 hours, return to the Zero-event fallback above.
Manual wiring
If your storefront falls outside the auto-detect signals — headless hydrogen sites, custom-coded themes that strip Shopify's standard globals, or storefronts behind a CDN that hides Shopify origin scripts — wire the events manually:
pennylens.track("cart_add", {
product_id: 7281928392,
variant_id: 41827382,
qty: 1,
total: 49.0,
currency: "USD",
});
Same API as any custom event. See Event Tracking for the full reference.
Next steps
- WooCommerce auto-detect — the WooCommerce equivalent of this page
- SaaS events — conventions for SaaS site types
- API Reference — full data model