Article

C2S – WooCommerce – Manual

Note:

The URL format of your program must be set as a parameter. You can change the URL format by going to your program settings and editing the general parameters.

Track partner clicks
Where to install the code?

On all pages of your website (inside the <body> tag).

Via the theme:
  • WordPress Admin ➜ Appearance ➜ Theme Editor
  • Select: header.php or theme.php
  • Add the code inside the <body> tag.
Code to install:
<script type="text/javascript">
var _ae = {
"pid":"PROGRAM_ID",
};
(function() {
var element = document.createElement('script'); element.type = 'text/javascript'; element.async = true;
element.src = '//static.affilae.com/ae-v3.5.js';
var scr = document.getElementsByTagName('script')[0]; scr.parentNode.insertBefore(element, scr);
})();
</script>

Where to find your Program ID? Affilae Admin ➜ Configuration ➜ Tracking ➜ Integration with an Affilae module

Track sales
Where to install the code?

In the functions.php file of your WordPress theme.

Steps:
  • WordPress Admin ➜ Appearance ➜ Theme Editor
  • Click: Theme Functions (functions.php)
  • Add the code at the very top, after the <?php line.
Code to install:
add_action('woocommerce_thankyou', 'Affilae_conversion_tracking');
function Affilae_conversion_tracking($order_id)
{
$order = wc_get_order($order_id);
$order_total = (float) $order->get_total() - $order->get_total_tax() - $order->get_total_shipping(); // Total before shipping cost and discount
$discount_total = $order->get_discount_total();
$total = $order_total - $discount_total;
$order_num = str_replace('#', '', $order->get_order_number());
// Get coupons code if any
$coupons_code = "";
$count = 0;
foreach ($order->get_used_coupons() as $coupon) { // since WC 3.7
$count ;
if ($count > 1) {
$coupons_code .= ';';
}
$coupons_code .= $coupon;
}

$items = $order->get_items();

$product_id = '';
$items = $order->get_items();
$productsIdArray = array();

foreach ($items as $item) {
$productsIdArray[] = $item['product_id'];
}

if (count($productsIdArray) > 0) {
$product_id = implode(';', $productsIdArray);
}

echo '<iframe src="https://lb.affilae.com/?key=YOUR.KEY&id=' . $order_num . '&amount=' . $total . '&payment=online&cv={CUSTOM_VAR}&voucher=' . $coupons_code . '&product=' . $product_id . '" frameborder="0" width="1" height="1"></iframe>';
}
Variable to update:

Replace YOUR_KEY with your conversion key.

Where to find your key? Affilae Admin ➜ Configuration ➜ Tracking ➜ Integration via an Affilae module

What the conversion code does
Data automatically tracked:

➜ Unique order number.
➜ Net amount (excluding taxes and shipping fees).
➜ Promo codes used.
➜ IDs of purchased products.
➜ Applied discounts.

➜ Final amount = Total price – Taxes – Shipping fees – Discounts
➜ Multiple products = list separated by “;”
➜ Multiple promo codes = list separated by “;”

Installation checklist
Installation:
  • Tracking code added to all pages
  • Conversion code added in functions.php
  • Variables replaced with actual values
Test:
  • Click and conversion tests performed
  • Verified in the Affilae dashboard
  • Test documentation followed
Help
Tracking code not working?
  • Check that the Program ID is correct
  • Make sure the code is present on all pages
Conversions not showing up?
  • Verify that the conversion key is correct
  • Check that the code is in functions.php
  • Test with a real order
  • Make sure WooCommerce is up to date
Need help?
  • Follow the Affilae test documentation
  • Contact support with details of your configuration

Need help?

Stay up to date with the latest trends in affiliate marketing and never miss any of our articles.

Contact Us