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

  1. Go to your Shopify store admin.
  1. From the left menu, navigate to Settings β†’ Customer Events.
Notion image

Step 2: Create a New Custom Event

  1. Click Add custom pixel.
  1. Give it a clear name, such as:
    1. Audiohook Purchase Event

Notion image

Step 3: Paste in the Code

  1. Copy the following code block.
  1. 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=YOUR_AUDIOHOOK_ID";
  script.onload = callback;
  script.onerror = () => console.warn("Failed to load Audiohook analytics.js");
  document.head.appendChild(script);
})(function onAudiohookReady() {
  // PURCHASE event
  analytics.subscribe("checkout_completed", (event) => {
    if (typeof window.ahTrack === "function") {
      const checkout = event.data.checkout;

      window.ahTrack("purchase", {
        value: checkout.totalPrice.amount,
        currency: checkout.currencyCode,
        order_id: checkout.order.id,
        email: checkout.email
      });
    }
  });

  // INITIATE CHECKOUT
  analytics.subscribe("checkout_started", (event) => {
    if (typeof window.ahTrack === "function") {
      const checkout = event.data.checkout;

      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

  1. Click Save in the Shopify editor.
  1. Click Connect to verify the pixel is working.
Notion image
Did this answer your question?
😞
😐
🀩