Amplitude · Web Pixels API replacement · confidence: high
Dies 2026-08-26
// Wave4-Hotel7 (2026-08-20): Amplitude Purchase event + revenue tracking
// replacement. Amplitude is heavily used by DTC brands and B2C SaaS for
// funnel analysis + retention cohorts. The legacy install pastes
// amplitude.getInstance().init(API_KEY) + amplitude.getInstance().logEvent(
// 'Purchase', {...}) + amplitude.getInstance().logRevenueV2(revenue) into
// Shopify Additional Scripts. All three call sites stop executing 2026-08-26.
//
// Two variants: pick ONE.
//
// ============================================================
// VARIANT A -- BROWSER-SIDE (Shopify Web Pixels sandbox).
// Uses Amplitude's Browser SDK v2 loaded from cdn.amplitude.com inside
// the pixel sandbox. AMPLITUDE_API_KEY is a project API key -- documented
// safe to expose to browser per Amplitude docs (project keys are write-
// only to Amplitude's ingestion endpoint, cannot read data back). Uses
// the modern Revenue helper instead of the deprecated logRevenueV2 path.
// ============================================================
(function loadAmplitude() {
if (window.amplitude && window.amplitude.track) return;
const s = document.createElement('script');
s.async = true;
s.src = 'https://cdn.amplitude.com/libs/analytics-browser-2.11.1-min.js.gz';
s.onload = () => window.amplitude.init('AMPLITUDE_API_KEY', { defaultTracking: false });
document.head.appendChild(s);
})();
analytics.subscribe('checkout_completed', (event) => {
const { checkout } = event.data;
if (!checkout || !checkout.email || !window.amplitude) return;
// Identify the user so purchases roll up to the same profile as pre-
// checkout behavioral events fired from theme.liquid / product pages.
window.amplitude.setUserId(
checkout.order ? String(checkout.order.customerId || checkout.order.id) : checkout.email
);
// Revenue helper -- populates Amplitude's built-in Revenue table
// (drives LTV cohort reports). Do this BEFORE the track() call so
// revenue is attached to the same session context.
const revenue = new window.amplitude.Revenue()
.setPrice(Number(checkout.totalPrice.amount))
.setQuantity(1)
.setEventProperties({
order_id: checkout.order ? String(checkout.order.id) : checkout.token,
currency: checkout.totalPrice.currencyCode,
});
window.amplitude.revenue(revenue);
window.amplitude.track('Purchase', {
order_id: checkout.order ? String(checkout.order.id) : checkout.token,
total: Number(checkout.totalPrice.amount),
currency: checkout.totalPrice.currencyCode,
item_count: (checkout.lineItems || []).length,
products: (checkout.lineItems || []).map((li) => ({
product_id: li.variant && li.variant.product ? String(li.variant.product.id) : null,
sku: li.variant ? li.variant.sku : null,
name: li.title,
price: li.variant && li.variant.price ? Number(li.variant.price.amount) : null,
quantity: li.quantity,
})),
});
});
// ============================================================
// VARIANT B -- SERVER-SIDE (Amplitude HTTP V2 API + Shopify webhook).
// Recommended for accurate revenue reporting. Ad-blockers can drop
// browser-side Amplitude calls; server-side is authoritative.
// Docs: https://amplitude.com/docs/apis/analytics/http-v2
// ============================================================
//
// // Shopify webhook: orders/paid
// export async function handleShopifyOrderPaidForAmplitude(order) {
// await fetch('https://api2.amplitude.com/2/httpapi', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({
// api_key: process.env.AMPLITUDE_API_KEY, // same project key, server-side
// events: [{
// user_id: String(order.customer ? order.customer.id : order.id),
// event_type: 'Purchase',
// time: new Date(order.created_at).getTime(),
// insert_id: 'shopify-order-' + order.id, // dedupe key
// event_properties: {
// order_id: String(order.id),
// total: Number(order.total_price),
// currency: order.currency,
// item_count: order.line_items.length,
// },
// revenue: Number(order.total_price),
// price: Number(order.total_price),
// quantity: 1,
// revenueType: 'purchase',
// }],
// }),
// });
// }What this does NOT cover
What this does NOT cover: pre-purchase funnel events (Product Viewed / Product Added / Checkout Started / Payment Info Entered), Amplitude Session Replay setup, Amplitude Experiment flag exposure logging, or Amplitude CDP (formerly mParticle) forwarding. Those all continue to work if pasted in theme.liquid instead of Additional Scripts; only the checkout-completed path is impacted by Aug 26.
Product-analytics + CDP + CRM · HubSpot, Segment, Amplitude, Mixpanel, PostHog — every DTC brand ships at least one of these and all break the same way Aug 26.