Question

Which file do I need to add custom e-commerce tracking code to in Magento?

Knowing that will give me a good start because Magento is huge and do not know where to start.

Once I know the correct file I need to add javascript into the checkout completed page, the javascript will be interjected with some values

  • items bought
  • total cost
  • cost / item
  • etc

The javascript I have and can handle just fine, its the Magento bit I am struggling with;

  1. Where should I add this javascript?
  2. Once I find this file can I easily output the transactions details the javascript tracker requires.

Note that the javascript is for https://www.gosquared.com/

Was it helpful?

Solution

I think you have to add this script in success.phtml from checkout/success.phtml in this file you got $order object and you get all information from this object like your transaction id,product information just like ex.

 $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$transactionid=$this->getOrderId()



foreach ($order->getItemsCollection() as $item) 
    {
        $item->getData();
        $proidcol[]=$item->getData('product_id');
        $pronamecol[]=$item->getData('name');
        $proqtycol[]=$item->getData('qty_ordered');
        $productpricecol[]=$item->getPrice();
    }

in this $pronamecol you can get all product name array from order and then implement this in java-script code using for loop ,,I think you can easily do that

OTHER TIPS

1 To add the javascript to the success page, you can use this in your layout local.xml file:

<checkout_onepage_success>
    <reference name="head">
        <action method="addItem"><type>skin_js</type><name>js/path/to/file.js</name></action>
    </reference>
<checkout_onepage_success>

Instead of head, you could also use before_body_end (so the javascript gets added at the bottom of the page).

2 Can't tell for you at the moment, what information does your javascript need? Do you need to add information to it manually?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top