Aucune catégorie trouvée.

WooCommerce custom integration

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.    

Track clicks from your partners

  This script must be placed on all pages in the<body> tag. This script is an example. You may modify the ‘PROGRAM_ID’ with in the script.

<script type="text/javascript">
var _ae = {
'pid': 'PROGRAM_ID',
'advertiserFirst': 43200,
'host': 'https://lb.affilae.com',
'forceReferrer': false,
'skipMouse': false,
'fp': true,
'firstParty': true
};
(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>

  Retrieve your PROGRAM_ID  in the Configuration menu, then Tracking tab and Integration via an Affilae plugin part. You will find the Program_ID directly in the Integration via an Affilae plugin section.   program ID Affilae    

Track sales

  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', '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>';
}

  You only need to replace the value YOUR.KEY with the key of the conversion code found in your Affilae account. You’ll find the KEY in the Configuration menu, then Tracking tab and Integration via an Affilae plugin part.  

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

 

Warning:

  • The programme must be in Parameter.

 

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