I'm using Daniel Yovchev's solution here to implement Universal Analytics:


The Current Code:

protected function _getOrdersTrackingCode()
    $orderIds = $this->getOrderIds();
    if (empty($orderIds) || !is_array($orderIds)) {
    $collection = Mage::getResourceModel('sales/order_collection')
        ->addFieldToFilter('entity_id', array('in' => $orderIds))
    $result = array("
        // Transaction code...
        ga('require', 'ecommerce', 'ecommerce.js');

    foreach ($collection as $order) {
        if ($order->getIsVirtual()) {
            $address = $order->getBillingAddress();
        } else {
            $address = $order->getShippingAddress();

        $result[] = "
            ga('ecommerce:addTransaction', {
                id:          '".$order->getIncrementId()."', // Transaction ID
                affiliation: '".$this->jsQuoteEscape(Mage::app()->getStore()->getFrontendName())."', // Affiliation or store name
                revenue:     '".$order->getBaseGrandTotal()."', // Grand Total
                shipping:    '".$order->getBaseShippingAmount()."', // Shipping cost
                tax:         '".$order->getBaseTaxAmount()."', // Tax


        foreach ($order->getAllVisibleItems() as $item) {

            $result[] = "
            ga('ecommerce:addItem', {

                id:       '".$order->getIncrementId()."', // Transaction ID.
                sku:      '".$this->jsQuoteEscape($item->getSku())."', // SKU/code.
                name:     '".$this->jsQuoteEscape($item->getName())."', // Product name.
                category: '', // Category or variation. there is no 'category' defined for the order item
                price:    '".$item->getBasePrice()."', // Unit price.
                quantity: '".$item->getQtyOrdered()."' // Quantity.


        $result[] = "ga('ecommerce:send');";
    return implode("\n", $result);

The problem I have is that this returns the simple sku, and I need it to return the configurable to be of any benefit to us. How can I modify this:

           sku:      '".$this->jsQuoteEscape($item->getSku())."', // SKU/code.

to serve this purpose?

Thanks ahead of time for the assistance!

1 Answer 1


If it is a configurable product you could do:

foreach($item->getChildrenItems() as $child) {
    sku:      '".$this->jsQuoteEscape($child->getSku())."', // SKU/code. 

Because there is only one child item, this produces one line. But if you have a group or bundle product, there might be more childs!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.