Purchases
Send each order once, when it's placed. Experiments then report revenue, conversion rate and average order value per variation, and recordings show who bought, what they paid, and the moment they did.
// On your order confirmation page, once the order is placed:
window.peekbird = window.peekbird || [];
peekbird.push(['track', 'purchase', {
revenue: 49.90, // the order total, as a number
currency: 'USD', // the three-letter currency code
orderId: 'ORDER-123' // your order number
}]);// Peekbird: orders from Shopify's checkout, where the snippet can't run.
const SITE_ID = 'YOUR_SITE_ID';
const COLLECT_URL = 'https://collect.peekbird.com/collect';
analytics.subscribe('checkout_completed', async (event) => {
// The visitor as the snippet on your store's pages knows them.
const visitorId = await browser.cookie.get('_peekbird_uid');
if (!visitorId) return;
const sessionId = (await browser.cookie.get('_peekbird_sid')) || `checkout-${Date.now()}`;
const checkout = event.data.checkout;
const url = event.context.document.location.href;
const events = [{
type: 'event',
ts: Date.now(),
url,
name: 'purchase',
revenue: Number(checkout.totalPrice?.amount ?? 0),
currency: checkout.currencyCode,
orderId: String(checkout.order?.id ?? checkout.token).split('/').pop(),
}];
// To also tell Peekbird who bought (see "Who the visitor is"), remove the // below:
// events.push({ type: 'identify', ts: Date.now(), url, email: checkout.email });
fetch(COLLECT_URL, {
method: 'POST',
keepalive: true,
headers: { 'Content-Type': 'text/plain' },
body: JSON.stringify({ siteId: SITE_ID, visitorId, sessionId, sdk: 'shopify-pixel@1', events }),
});
});// WooCommerce, in your theme's functions.php (or a code snippets plugin):
add_action('woocommerce_thankyou', function ($order_id) {
$order = wc_get_order($order_id);
if (!$order) return;
printf(
"<script>window.peekbird = window.peekbird || []; peekbird.push(['track', 'purchase', %s]);</script>",
wp_json_encode([
'revenue' => (float) $order->get_total(),
'currency' => $order->get_currency(),
'orderId' => (string) $order->get_order_number(),
], JSON_HEX_TAG | JSON_HEX_AMP)
);
});<script>
window.peekbird = window.peekbird || [];
peekbird.push(['track', 'purchase', {
revenue: Number({{DLV - ecommerce.value}}),
currency: {{DLV - ecommerce.currency}},
orderId: {{DLV - ecommerce.transaction_id}}
}]);
</script>The fields
revenue- The order total, as a number (49.90, not "$49.90"). Required: without it, the order is an event, not revenue.
currency- The three-letter code, like USD or EUR. Send the one the order was paid in.
orderId- Your order number. An order counts once even if the confirmation page is reloaded, and recordings can be searched by it.
anything else- Text, numbers or true/false, kept with the order (coupon, shipping method, …).
Shopify
Shopify runs no store scripts on its checkout, so orders come from a checkout pixel (the Shopify tab above):
- In Shopify admin, go to Settings → Customer events and click Add custom pixel. Name it Peekbird.
- Under Customer privacy, choose Analytics: it then runs for customers who allow analytics.
- Paste the code, then Save and Connect. Install & data in your dashboard has it with your site's ID filled in.
It links each order to the visitor the snippet saw on your store, so it counts for their experiments and recording. It sends the order total, with tax and shipping; for the subtotal instead, use checkout.subtotalPrice.
Google Tag Manager
- Variables → New → Data Layer Variable, three times:
ecommerce.value,ecommerce.currencyandecommerce.transaction_id, named as in the code. These are the names of GA4's purchase event; if your data layer uses others, use those. - Tags → New → Custom HTML with the code, fired by a Custom Event trigger named
purchase.
Good to know
- Send it from the confirmation page, not the checkout button: only placed orders should count.
- It's sent at once, so it arrives even if the visitor closes the page right after.
- The standard purchase goals (revenue, orders, order value) count it; add them to an experiment from your site's Goals.
- With analytics off for a site, orders arrive only from visitors in an experiment. Leave it on (the default) to see everyone's orders in recordings.