woocommerce - 向订购页面添加跟踪代码(commision junction affiliate program

时间:2016-05-19 20:20:02

标签: wordpress woocommerce cj

我正在寻求整合联盟计划委员会联盟的跟踪。

他们为我提供了以下示例代码以添加到我的订单接收页面,任何帮助将被理解如何将其放入/ order-received / endpoint以及它要求的修改。我完全迷失了,有几个类似程序的插件。

(如果有帮助的话,他们会提供javascript和asp替代方案)

<!-- BEGIN COMMISSION JUNCTION TRACKING CODE -->

<iframe height="1" width="1" frameborder="0" scrolling="no"         src="https://www.emjcd.com/tags/c?containerTagId=14209&ITEMx=[ItemSku]&AMTx=    [AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT=[Subtotal]&DISCOUNT=[DiscountAmount]&CURRENCY=[CURRENCY]&COUPON=[couponcode]" name="cj_conversion" ></iframe>

<!-- END COMMISSION JUNCTION TRACKING CODE -->

2 个答案:

答案 0 :(得分:0)

在主题functions.php文件中添加以下代码

add_action( 'woocommerce_thankyou', 'my_custom_tracking' );

function my_custom_tracking( $order_id ) {

    global  $woocommerce;

    $order = wc_get_order( $order_id );
    $total = $order->get_total();
    $currency = get_woocommerce_currency();

    $coupons = $order->get_used_coupons();

    $coupon_code = '';

    foreach ($coupons as $coupon){
        $coupon_code = $coupon;
    }

    $discount = $order->get_total_discount();

    $tracking = '<iframe height="1" width="1" frameborder="0" scrolling="no" src="https://www.emjcd.com/tags/c?containerTagId=14209&ITEMx=[ItemSku]&AMTx=[AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT='. $total .'&DISCOUNT='. $discount .'&CURRENCY='. $currency .'&COUPON='. $coupon_code .'" name="cj_conversion" ></iframe>';
    echo $tracking;

    }

查看您的跟踪代码,我猜测我们可能需要使用正确的值填充src网址。但我不确定。

答案 1 :(得分:0)

您需要列出所有购买的SKU及其价格。如果您愿意,可以使用DISCOUNT参数对订单应用美元折扣,除非您已经扣除了在iframe中放置的价格的折扣。优惠券代码也是一个不错的选择。

如果您想在JavaScript中执行此操作并假设您的订单数据位于下面的虚拟数据对象数组中,那么您将如何在JavaScript中执行此操作:

// Some dummy data (populate real data in your code)
var order = {
	id: "AB12345",
	subtotal: "200.00",
	discount: "10.00",
	coupon: "DEAL10",
	items: [
		{ sku: "FOO123", price: "75.00", quantity: 2 },
		{ sku: "BAR234", price: "50.00", quantity: 1 }
	]
};

// The actual code
var cj = {
	tagId: 14209,
	cid: 1529328,
	type: 385769
};
var cjString = "https://www.emjcd.com/tags/c?containerTagId=" + cj.tagId + "&";

for (i=0; i<order.items.length; i++) {
  cjString += "ITEM" + i + "=" order.items[i].sku + "AMT" + i + order.items[i].price + "QTY" + i + order.items[i].quantity + "&";
}

cjString += "CID=" + cj.cid + "&OID=" + order.id + "&TYPE=" + cj.type + "&AMOUNT=" + order.subtotal + ( discount.length ? "&DISCOUNT=" + order.discount : "" ) + "&CURRENCY=USD" + ( coupon.length ? "&COUPON=" + order.coupon : "" );

// Now we put it all together and insert into the page
var frame = document.createElement("iframe");
frame.name = "cj_conversion";
frame.height = 1;
frame.width = 1;
frame.frameBorder = 0;
frame.scrolling = "no";
frame.src = cjString;
document.body.insertBefore(frame, document.body.childNodes[0]);