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. I’m absolutely lost, there are plugins for several similar programs.

Read More

(They offer a javascript and asp alternative by the looks of things if that helps)

<!-- 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 -->

Related posts

Leave a Reply

2 comments

  1. Add the following code in your themes functions.php file

    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. But i am not sure.

  2. You’ll need to list out all of the SKUs purchased along with their prices. 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. 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:

    // 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]);