Conversion Tracking Tag
This guide will help you understand the purpose of the Audiohook conversion tag, how to easily install it on your website, and how to use the ahTrack function to capture important events.
What is the Audiohook Conversion Tag?
The Audiohook conversion tag is a lightweight and privacy-focused client-side tracking solution designed to help you understand what events and conversions your audio campaigns are driving. Similar to other ad platforms, it allows you to:
- Track Pageviews Automatically: See which pages your users are visiting without any extra setup.
- Understand User Engagement: Gain insights into how users navigate and interact with your site.
- Capture Valuable Data: Automatically collect information like the current URL, referring URL, user agent, and UTM parameters.
- Track Custom Events: Monitor specific user actions beyond pageviews, such as form submissions, product additions to a cart, or purchases.
Essentially, the Audiohook conversion tag provides you with crucial data to optimize your audio campaigns, all while prioritizing user privacy.
If you had previously installed the Audiohook pixel, please update that implementation using the Conversion Tracking Tag.
How to Install the Audiohook Conversion Tag
Installation is straightforward and only requires adding a small snippet of code to your website's <head>
section.
Step 1: Add the Analytics Script
Copy and paste the following code into the <head>
section of every page on your website:
HTML
<script async src="https://js.audiohook.com/analytics.js?audiohookId=YOUR_AUDIOHOOK_ID"></script>
Important: Replace YOUR_AUDIOHOOK_ID
with your unique Audiohook ID which can be found on the Account Details tab in the Audiohook UI. This ID is essential for linking the tracking data to your Audiohook account.
Using the ahTrack
Function for Custom Events
While pageviews are automatically tracked once the script is installed, the ahTrack
function allows you to send specific "events" to Audiohook when a user performs a particular action on your site. This is incredibly useful for understanding engagement beyond simply viewing pages as well as tracking specific conversion events.
The ahTrack function requires two parameters, an event type
which much be a string and an event object
as shown below.
ahTrack(event_type,{event object});
Inside the event object any number of keys and nested objects can be passed. All data that is passed in an object can be fully reported on. There are two keys in the event object that are handled in a special manner which are id
and value
. id
is used as an external reference id to track unique event ids such as an order id as is treated as a string. value
is the only key expected to have a float value and is assumed to represent the value associated with an event such as a purchase. This value is then used to automatically calculate in the platform data like attributed revenue and return on ad spend (ROAS).
Important Privacy Note: When passing data with ahTrack
, be aware that the values associated with the email
and phone
keys whether nested or not, will be hashed using SHA-256 to protect Personally Identifiable Information (PII). This data is hashed client side so the raw PII data never reaches Audiohook servers. Please do not pass any other forms of PII directly.
Here are examples of how to use ahTrack
for common scenarios:
1. Tracking a Form Submission:
When a user successfully submits a form (e.g., a contact form or newsletter signup), you can track this event:
JavaScript
ahTrack('form_submit', {
name: 'Contact Us', // A descriptive name for your form
form_data: {
name: 'bob',
email: 'bob@gmail.com' // Email will be hashed
}
});
This would typically be placed within the success callback of your form submission handling.
2. Tracking an Add to Cart Event:
If you have an e-commerce site, you can track when a user adds an item to their shopping cart:
JavaScript
ahTrack('add_to_cart', {
product_id: '123', // Note that product_id was used as product ids are not unique and will be repeating
product_name: 'Example Product',
value: 29.99,
currency: 'USD'
});
Implement this function call when a user clicks an "Add to Cart" button.
3. Tracking a Purchase:
The most important conversion for e-commerce, tracking a successful purchase:
JavaScript
ahTrack('purchase', {
id: 'ORDER123', // Your unique order ID
value: 99.99, // Total purchase value
currency: 'USD',
items: [ // Details about the purchased items
{
product_id: '123',
product_name: 'Example Product',
price: 29.99,
quantity: 1
}
]
});
This code should be executed on your order confirmation or thank you page after a successful transaction.
Custom Events:
You can also define and track completely custom events by simply providing a string as the first argument to ahTrack
. This allows you to track virtually any user interaction relevant to your business goals.