Last active
February 20, 2024 15:31
-
-
Save tankbar/894b80e6ddf3a8dfd5415f8f4686b7b5 to your computer and use it in GitHub Desktop.
Adtraction affiliate tracking on Thank you page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Adtraction conversion tracking implementation | |
add_action( 'woocommerce_thankyou', 'adtraction_tracking', 60 ); | |
function adtraction_tracking( $order_id ) { | |
$order = new WC_Order( $order_id ); | |
$order_nr = $order->get_order_number(); | |
$order_total_shipping = $order->get_total_shipping(); | |
$order_total_ex_vat = $order->get_total() - $order->get_total_tax(); | |
$order_total = $order_total_ex_vat - $order_total_shipping; | |
$order_email = get_user_meta( $order->user_id, 'billing_email', true ); | |
$source_address = $order_email; | |
$processed_address = strtolower($source_address); //convert address to lower case | |
$processed_address = trim($processed_address); //trimming leading and trailing spaces | |
$processed_address = mb_convert_encoding($processed_address, "UTF-8", "ISO-8859-1"); //conversion from ISO-8859-1 to UTF-8 (replace "ISO-8859-1" with the source encoding of your string) | |
$processed_address = md5($processed_address); //hash address with MD5 algorithm | |
?> | |
<!-- Adtraction conversion tracking --> | |
<script type="text/javascript" src="https://track.adtraction.com/t/t?t=XX&tk=XXX&am=<?php echo $order_total; ?>&c=SEK&ti=<?php echo $order_nr; ?>&tp=XXXXXX&trt=X&cpn=&xd=<?php echo $processed_address; ?>&ap=XXXXXXXX" charset="ISO-8859-1"></script> | |
<?php | |
$cookieName = "source"; // Name of your deduplication cookie | |
if (isset($_COOKIE[$cookieName])) { | |
$channel = $_COOKIE[$cookieName]; | |
} else { | |
$channel = "na"; // No affiliate network detected as source | |
} | |
// replace with actual transaction data | |
$orderAmount = $order_total; // order value | |
$currency = "SEK"; // currency | |
$orderId = $order_nr; // order ID | |
$couponCode = ""; // coupon code used in transaction, if any | |
$md5Email = $processed_address; // MD5 hash of user email | |
if($channel === "na") { | |
$orderId = "fb_" . $orderId; | |
} | |
// Insert your Adtraction tracking pixel | |
$adtractionPixel = "https://track.adtraction.com/t/t?t=X&tk=X&am=" . $orderAmount . "&c=" . $currency . "&ti=" . $orderId . "&tp=XXXXXXXX&trt=XXX&ap=XXXXXXXX&cpn=" . $couponCode . "&xd=" . $md5Email; | |
// Insert your TradeDoubler tracking pixel | |
$tradedoublerPixel = "https://tbs.tradedoubler.com/report?orderValue=" . $orderAmount . "¤cy=" . $currency . "&orderNumber=" . $orderId . "&voucher=" . $couponCode; | |
// Insert your Zanox tracking pixel | |
$zanoxPixel = "//ad.zanox.com/pps/TotalPrice=" . $orderAmount . "&CurrencySymbol=" . $currency . "&OrderID=" . $orderId; | |
if($channel === "na") { | |
?> | |
<img border="0" height="0" width="0" src="<?php echo $adtractionPixel; ?>" style="display: none;"> | |
<img border="0" height="0" width="0" src="<?php echo $tradedoublerPixel; ?>" style="display: none;"> | |
<img border="0" height="0" width="0" src="<?php echo $zanoxPixel; ?>" style="display: none;"> | |
<?php } if($channel == "adtraction") { ?><img border="0" height="0" width="0" src="<?php echo $adtractionPixel; ?>" style="display: none;"> | |
<?php } if($channel == "tradedoubler") { ?><img border="0" height="0" width="0" src="<?php echo $tradedoublerPixel; ?>" style="display: none;"> | |
<?php } if($channel == "zanox") { ?><img border="0" height="0" width="0" src="<?php echo $zanoxPixel; ?>" style="display: none;"> | |
<?php } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment