1

We've updated to Universal Analytics in Magento 1.9.1.0, but we run multiple store views each with their own currency and all feeding into one Google Analytics profile.

Currently that means Analytics treats the values sent from Magento as all being in the default currency set in Google Analytics (GBP) - ie. an order in GBP may be say £200, but the same product in yen may be Y20000, but analytics thinks its an order for £20000.. which is needless to say is skewing our analytics data.

Looking through the Analytics help pages (https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#multicurrency) I can see there is a field available to specify to Google the currency you are sending the transaction as and then Google will handle the conversion which is grand.

The problem is I dont know how to edit Ga.php in Magento to get the currency code correctly set. At line 176 in Ga.php I can see where ga('ecommerce:addTransaction) is put together but how do I get the correct currency code from Magento at this point?

I would have assumed this would be correctly set by default by Magento but apparently not.

Thanks

1 Answer 1

4

Please try to replace this:

            $result[] = sprintf("ga('ecommerce:addTransaction', {
'id': '%s',
'affiliation': '%s',
'revenue': '%s',
'tax': '%s',
'shipping': '%s'
});",
                $order->getIncrementId(),
                $this->jsQuoteEscape(Mage::app()->getStore()->getFrontendName()),
                $order->getBaseGrandTotal(),
                $order->getBaseTaxAmount(),
                $order->getBaseShippingAmount()
            );

with this:

            $result[] = sprintf("ga('ecommerce:addTransaction', {
'id': '%s',
'affiliation': '%s',
'revenue': '%s',
'tax': '%s',
'shipping': '%s',
'currency': '%s'
});",
                $order->getIncrementId(),
                $this->jsQuoteEscape(Mage::app()->getStore()->getFrontendName()),
                $order->getGrandTotal(),
                $order->getTaxAmount(),
                $order->getShippingAmount(),
                $order->getOrderCurrencyCode()
            );

in app/code/core/Mage/GoogleAnalytics/Block/Ga.php.

1
  • Thats great thanks: "getOrderCurrencyCode" - simple when you know how!
    – Tim
    Dec 18, 2014 at 9:23

Your Answer

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

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