How to Implement Audiohook tracking on purchases on Shopify
Shopify has sandboxed their custom events for tracking purchases, making some changes to how the Audiohook tag needs to be added for purchase events
Step 1: Log in to Shopify Admin
- Go to your Shopify store admin.
- From the left menu, navigate to Settings → Customer Events.

Step 2: Create a New Custom Event
- Click Add custom pixel.
- Give it a clear name, such as:
Audiohook Purchase Event

Step 3: Paste in the Code
- Copy the following code block.
- Paste it into the pixel editor:
// Load Audiohook pixel inside Shopify's Customer Events sandbox
(function loadAudiohook(callback) {
const script = document.createElement("script");
script.src = "https://js.audiohook.com/analytics.js?audiohookId=[AUDIOHOOK ID GOES HERE]";
script.async = true;
script.onload = callback;
script.onerror = () => console.warn("Failed to load Audiohook analytics.js");
document.head.appendChild(script);
})(function onAudiohookReady() {
// PURCHASE / REPEAT PURCHASE — routes based on Shopify's isFirstOrder flag
// Guest checkouts (no customer record) default to "purchase"
analytics.subscribe("checkout_completed", (event) => {
if (typeof window.ahTrack !== "function") return;
const checkout = event?.data?.checkout;
if (!checkout) return;
const customer = checkout?.order?.customer;
const isFirstOrder = customer?.isFirstOrder;
const ordersCount = customer?.ordersCount;
// Only explicit returning customers route to repeatpurchase;
// new customers and guests (undefined isFirstOrder) route to purchase
const eventName = isFirstOrder === false ? "repeatpurchase" : "purchase";
window.ahTrack(eventName, {
value: checkout.totalPrice?.amount,
currency: checkout.currencyCode,
order_id: checkout?.order?.id,
email: checkout.email,
customer_orders_count: ordersCount
});
});
// INITIATE CHECKOUT event (all users)
analytics.subscribe("checkout_started", (event) => {
if (typeof window.ahTrack !== "function") return;
const checkout = event?.data?.checkout;
if (!checkout) return;
window.ahTrack("initiate_checkout", {
value: checkout.totalPrice?.amount,
currency: checkout.currencyCode,
email: checkout.email
});
});
});
Step 4: Swap the Audiohook ID
In the code above, replace:
YOUR_AUDIOHOOK_ID
with your unique Audiohook Pixel ID.
Example:
https://js.audiohook.com/analytics.js?audiohookId=a97cc759-0f29-4c24-8287-55a115dca83b
Step 5: Save and Test
- Click Save in the Shopify editor.
- Click Connect to verify the pixel is working.

Did this answer your question?
😞
😐
🤩