简体   繁体   English

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

[英]woocommerce - adding tracking code to order page (commision junction affiliate program

I'm looking to integrate tracking from the affiliate program commission junction. 我正在寻求整合联盟计划委员会联盟的跟踪。

They have provided me with the following sample code to add to my order received page, any help would be appreciated regarding how to place this in /order-received/ endpoint and the modifications its asking for. 他们为我提供了以下示例代码以添加到我的订单接收页面,任何帮助将被理解如何将其放入/ order-received / endpoint及其要求的修改。 I'm absolutely lost, there are plugins for several similar programs. 我绝对输了,有几个类似程序的插件。

(They offer a javascript and asp alternative by the looks of things if that helps) (如果有帮助的话,他们会提供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 -->

Add the following code in your themes functions.php file 在主题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;

    }

Looking at your tracking code, I am having a guess that we may need to fill the src url with correct values. 查看您的跟踪代码,我猜测我们可能需要使用正确的值填充src网址。 But i am not sure. 但我不确定。

You'll need to list out all of the SKUs purchased along with their prices. 您需要列出购买的所有SKU及其价格。 If you want you can use the DISCOUNT parameter to apply a dollar discount to the order, unless you're already deducting discounts in the price you put in the iframe. 如果您愿意,可以使用DISCOUNT参数对订单应用美元折扣,除非您已经扣除了在iframe中放置的价格的折扣。 Coupon code is also a nice-to-have. 优惠券代码也是一个不错的选择。

If you want to do this in JavaScript and assuming your order data is in an array of objects that looks like the dummy data below here's how you'd do that in JavaScript: 如果你想在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]); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM