Setup your WooCommerce affiliate program with Affilae




Well done, you’ve created your new affiliate program!

Now you need to setup tracking scripts to check if clicks and sales tracking works fine.

To setup the tracking scripts for your WooCommerce affiliate program, follow these steps:

=> If you are using redirect tracking, go to step 2.


1 – Clicks tracking script


This script must be placed on all pages in the <body> tag.


<script type="text/javascript">
  var _ae = {
    'pid': YOUR_PROGRAM_ID,
    'advertiserFirst': 21600, // 15 days in mins
    'allowSiteUnder': false,
    'allowIframing': false
  (function() {
    var element = document.createElement('script'); element.type = 'text/javascript'; element.async = true;
    element.src = '//';
    var scr = document.getElementsByTagName('script')[0]; scr.parentNode.insertBefore(element, scr);
woocommerce javascript


=> Caution! This script is an example, you must copy-paste the code in your account: “config” menu at the bottom of the page.



2 – Sales conversion tag


When you want to track sales for affiliates in WooCommerce, you need to add a conversion tag to your thank you page that passes through the ORDER ID and SALE AMOUNT tax excluded.

  • First, go to your WordPress admin and access to Appearance and Editor.
  • Then, click the “Theme Functions (functions.php)” file.
  • And paste in the following conversion code at the top of the file, after the <?php line:


add_action( 'woocommerce_thankyou', 'my_custom_tracking' );

function conversion_tracking( $order_id ) {
  $order = new WC_Order( $order_id );
  $total = $order->get_subtotal();
  $id = str_replace('#', '', $order->get_order_number());
  echo '<iframe src="[KEY]&id=' . $id . '&amount=' . $total . '&payment=online&cv={CUSTOM_VAR}" frameborder="0" width="1" height="1"></iframe>';
Woocommerce sales tag


  • To finish, save “functions.php” file. Tracking should be ok for tests.


Now, you can test tracking and check if clicks and conversions work well: Test tracking.


Need help? Contact us!