Installing 1st party tracking (v2) via WooCommerce

To install our 1st party tracking v2 you need to implement our redirect script first. You can find the information on how to set it up here:

Installing-1st-party-tracking

Implementing the checkout script

The checkout script has to be implemented in the WooCommerce administration backend.

You need to add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme.

Lead Script

// Add TC tracking code to the thank-you page
add_action( 'woocommerce_thankyou', 'tc_checkout_lead_script_v2' );
function tc_checkout_lead_script_v2( $order_id ) {
// Manual configuration
$data = array(
'offer_sid' => 'OFFER_SID',
'event_sid' => 'EVENT_SID'
);

// Get order data
$data['id'] = htmlentities( $order->get_order_number(), ENT_QUOTES );
?>
<script>
(function() {
var el = document.createElement('script');
el.setAttribute('src', '//cdn.trackmytarget.com/tracking/s/checkout.min.js');
el.setAttribute('data-type', 'lead');
el.setAttribute('data-offer-sid', <?php echo "'{$data['offer_sid']}'"; ?>);
el.setAttribute('data-event-sid', <?php echo "'{$data['event_sid']}'"; ?>);
el.setAttribute('data-id', <?php echo "'{$data['id']}'"; ?>);
document.body.appendChild(el);
})();
</script>
<?php
}

Sale Script

// Add TC tracking code to the thank-you page
add_action( 'woocommerce_thankyou', 'tc_checkout_sale_script_v2' );
function tc_checkout_sale_script_v2( $order_id ) {
// Manual configuration
$data = array(
'offer_sid' => 'OFFER_SID',
'event_sid' => 'EVENT_SID'
);

// Get order data
$order = wc_get_order( $order_id );
$data['id'] = htmlentities( $order->get_order_number(), ENT_QUOTES );
$data['amount'] = htmlentities( (float) $order->get_subtotal() );
$data['currency'] = $order->get_currency();
// Multiple coupons possible
$data['code'] = implode(',', $order->get_coupon_codes());
?>
<script>
(function() {
var el = document.createElement('script');
el.setAttribute('src', '//cdn.trackmytarget.com/tracking/s/checkout.min.js');
el.setAttribute('data-type', 'sale');
el.setAttribute('data-offer-sid', <?php echo "'{$data['offer_sid']}'"; ?>);
el.setAttribute('data-event-sid', <?php echo "'{$data['event_sid']}'"; ?>);
el.setAttribute('data-id', <?php echo "'{$data['id']}'"; ?>);
el.setAttribute('data-amount', <?php echo "'{$data['amount']}'"; ?>);
el.setAttribute('data-currency', <?php echo "'{$data['currency']}'"; ?>);
el.setAttribute('data-code', <?php echo "'{$data['code']}'"; ?>);
document.body.appendChild(el);
})();
</script>
<?php
}

Parameters

  • OFFER_SID required
    Replace with 6 character sID of the Offer. You can find this value in the Offer list of the marketplace or ask your account manager.

  • EVENT_SID required
    Replace with the 6 character sID of the product group. You can find this value in the tracking tab when creating or editing an Offer or you can ask your account manager.

Boost your affiliate program

Download our free whitepaper for insights into 2020’s top affiliate marketing trend: self-service affiliate programs

© 2020 Target Circle AS | Terms & Privacy | Cookie preferences | Email

Learn the 2020’s Top Affiliate Marketing Trends