To monitor your WooCommerce sales on Tracknow, an integration is required.
By embedding the pixel image code, every completed purchase will be automatically sent with the relevant sales data to Tracknow, allowing you to track conversions directly on your dashboard.
Locating where the code is added on WooCommerce
- Log into your WordPress dashboard
- On the main menu, select ‘Appearance’ and on the newly opened menu select ‘Theme File Editor’
- Locate the functions.php file in the list of files associated with your active theme and click on it to edit
- The file’s code box will open – this is where you’ll add the code
Find your campaign’s Conversion Tracking URL on Tracknow
- Login as an admin to the Tracknow platform and click ‘Campaigns/Offers’ on the left menu
- Click on the name of the campaign you wish these purchases to be associated with
- On the secondary menu, select ‘Setup/Integration’ and click on ‘IMAGE’
- Copy only the part of the link that is highlighted in the screenshot below
Adding the code
Whenever a purchase is made we would like to send the following details:
- Send the WooCommerce order ID
- Send the order’s amount
- Associate the purchase with campaign ID = 1 (the campaign ID may be different in your case, depending on which campaign on Tracknow you’d like the conversions to be added under)
We’ve prepared a simple template for you to use:
function tracknow_tracking( $order_id ) {
// Ensure the order exists
$order = wc_get_order( $order_id );
if ( ! $order ) {
return; // If the order is not valid, stop execution
}
// Retrieve the `click_id` from cookies if it exists
$click_id = isset($_COOKIE['click_id']) ? $_COOKIE['click_id'] : null;
// Get the order details
$order_total = $order->get_total(); // Get the order total
$order_shipping = $order->get_shipping_total(); // Get the shipping total
$coupons = $order->get_used_coupons(); // Get the array of used coupon codes
$coupon_code = !empty($coupons) ? $coupons[0] : ''; // Get the first coupon code if available
// Build the tracking URL
$tracking_url = "https://example.tracknow.info/success.jpg?";
$tracking_url .= "order_id=" . urlencode( $order_id );
$tracking_url .= "&amount=" . urlencode( $order_total - $order_shipping );
$tracking_url .= "&coupon=" . urlencode( $coupon_code );
$tracking_url .= "&goal="; // The goal may be empty, you can modify this if needed
// Add `click_id` or `campaign_id`
if ( $click_id ) {
$tracking_url .= "&click_id=" . urlencode( $click_id );
} else {
$tracking_url .= "&campaign_id=1"; // Replace 1 with your actual campaign ID if needed
}
// Output the tracking pixel (image)
echo '<img src="' . esc_url( $tracking_url ) . '" width="1" height="1" style="display:none;" alt="" />';
}
// Hook into WooCommerce order completion to trigger the tracking
add_action( 'woocommerce_thankyou', 'tracknow_tracking');
Copy and paste the code into the code box section in the functions.php and click ‘Update File’