GTM Copy & Paste Examples for Audiohook Tracking

These examples show how to implement window.ahTrack for common event types in GTM. Replace placeholder values with your GTM variables where needed.


1. Tracking a Form Submission

Use Case: When a user successfully submits a form (e.g., contact form, newsletter signup).

<script>
window.ahTrack('Contact Us', {
  form_data: {
    name: '{{Name}}',   // Replace with GTM variable for Name
    email: '{{Email}}'  // Replace with GTM variable for Email (will be hashed)
  }
});
</script>

  • Trigger: Form Submission or Click trigger
  • Notes: Place this tag in GTM where the form success event occurs (or success callback in JavaScript).

2. Tracking an Add to Cart Event

Use Case: When a user adds an item to their shopping cart on an e-commerce site.

<script>
window.ahTrack('add_to_cart', {
  product_id: '{{Product ID}}',       // GTM variable for product ID
  product_name: '{{Product Name}}',   // GTM variable for product name
  value: '{{Product Price}}',         // GTM variable for product price
  currency: 'USD'
});
</script>

  • Trigger: Click trigger on "Add to Cart" buttons
  • Notes: Ensure your GTM variables are correctly capturing product details.

3. Tracking a Purchase

Use Case: When a user completes a purchase.

<script>
window.ahTrack('purchase', {
  id: '{{Order ID}}',           // GTM variable for unique order ID
  value: '{{Order Total}}',     // GTM variable for total order value
  currency: 'USD',
  items: [                      // Array of purchased items
    {
      product_id: '{{Product ID}}',        // GTM variable for product ID
      product_name: '{{Product Name}}',    // GTM variable for product name
      price: '{{Product Price}}',          // GTM variable for price
      quantity: '{{Product Quantity}}'     // GTM variable for quantity
    }
  ]
});
</script>

  • Trigger: Page View trigger on the order confirmation / thank you page
  • Notes: All placeholders should be replaced with GTM variables that pull data from your e-commerce platform.

4. Tracking a Custom Event

Use Case: Track any custom user interaction relevant to your business goals.

<script>
window.ahTrack('Custom Event Name', {
  custom_param_1: '{{GTM Variable 1}}',
  custom_param_2: '{{GTM Variable 2}}'
});
</script>

  • Trigger: Depends on the interaction (clicks, form submissions, video plays, etc.)
  • Notes: Use descriptive event names and parameters to keep reporting clear.

βœ… Tips for GTM Users:

  • Always test in Preview Mode before publishing.
  • Replace all placeholders ({{Variable Name}}) with your GTM variables.
  • Use window.ahTrack format to ensure GTM can access the global tracking function.
  • For forms, dynamically capturing inputs avoids hardcoding user data.
  • Keep triggers specific to prevent duplicate or misfired events.
Did this answer your question?
😞
😐
🀩