WooCommerce Revenue Tracking

Track cart and checkout events in WooCommerce for revenue attribution.

This example shows how to implement Alhena AI revenue tracking in WooCommerce, enabling you to see which AI conversations influence purchases.

What You'll Learn

  • Add the tracking snippet to your WooCommerce site

  • Track add-to-cart events

  • Track checkout completions on the thank-you page

Use Case

When customers interact with your Alhena AI assistant before making a purchase, you want to attribute that revenue to the AI. This implementation captures:

  1. Items added to cart (with product details)

  2. Completed orders (with full line item data)

This data flows to your Alhena dashboard under Analytics > Revenue Impact.

Prerequisites

  • Alhena SDK installed on your WooCommerce site

  • Access to your theme's functions.php or a custom plugin

  • WooCommerce 3.0 or later

Code Example

Add this code to your theme's functions.php or a custom plugin:

1. Add tracking snippet to header

2. Track add-to-cart events

3. Track checkout on thank-you page

How It Works

  1. Tracking snippet: Initializes the event queue so tracking calls work even before the full SDK loads

  2. Add-to-cart: Listens for WooCommerce's added_to_cart jQuery event and captures product details from the button's data attributes

  3. Thank-you page: Hooks into woocommerce_thankyou to fire a checkout event with the complete order data

The events are matched to any AI conversations the customer had within the attribution window (24 hours by default).

Customization

Track cart removal

Add custom product data

If your add-to-cart buttons don't have data-product_name or data-price attributes, you can extend the tracking:

Last updated