Overview
The SDK's WooCommerce integration supports three tracking methods, tried in order:
- Native WC event — listens for wc-blocks_checkout_complete or the legacy woocommerce_checkout_order_processed JS event
- DOM scraping — reads order number, total, and currency from the .woocommerce-order-details table on the thank-you page
- dataLayer push — listens for the purchase event via Google Tag Manager enhanced e-commerce schema
Installation
Add the snippet to your theme's footer.php, or enqueue it via a plugin. The snippet must load on all pages to capture the initial click.
Add to footer.php
Navigate to Appearance → Theme File Editor → footer.php and paste before </body>.
Or: enqueue via functions.php
Use wp_enqueue_script if you prefer not to edit template files directly.
<script src="https://assets.affclix.com/sdk/v3/affclix-sdk.min.js"></script>
<script>
AffclixSDK.init({
trackingDomain: 't.yourdomain.com',
cookieDomain: '.yourdomain.com'
});
// Auto-detects the order-received / thank-you page, listens for the
// wc:order_received DOM event, and polls DataLayer for purchase events.
AffclixSDK.integrations.woocommerce.init({
campaignID: 'YOUR_CAMPAIGN_ID',
autoTrack: true
});
</script> How It Works
Click Capture
On every page load the SDK reads UTM params and utk_click_id from the URL and stores them in a first-party cookie.
Thank-You Page Detection
The SDK detects the is-woocommerce-order-received body class or wc_order_received JS global to identify the confirmation page.
Order Data Extraction
Tries native WC event → DOM scrape → dataLayer, in that order. First successful source wins.
Postback Fired
Normalised order payload is sent to your Affclix endpoint. Duplicate order IDs are suppressed server-side for 24 h.
Manual Tracking
For custom themes where auto-detection fails, output order data directly via PHP and pass it to the SDK.
Tracked Fields
| Field | Source | Description |
|---|---|---|
orderId | get_order_number() | Used for deduplication — never credited twice |
revenue | get_total() | Order total including tax, excluding shipping by default |
currency | get_woocommerce_currency() | Store base currency (ISO 4217) |
coupon | get_coupon_codes() | Comma-separated discount codes applied |
utk_click_id | Cookie / localStorage | Affclix click attribution ID set on landing |
utm_source | Cookie / localStorage | Captured on first touch |
Troubleshooting
Conversion not firing
Enable debug: true in AffclixSDK.init() and open the browser console on the thank-you page. Look for [Affclix] WooCommerce — order detected.
If your store uses the WooCommerce Blocks checkout, the legacy woocommerce_checkout_order_processed JS event is NOT fired. The SDK covers this by detecting the order-received / thank-you page directly and by polling dataLayer for purchase events — ensure you are on SDK v3 or later.
Double conversions
Check that you are not calling AffclixSDK.integrations.woocommerce.init() more than once per page. The SDK guards against duplicate order tracking client-side (per txn_id, 30-day window), but duplicate init calls waste bandwidth.