Magento – orders not tracked in GA

google analytics

I have followed the below link and added the code in success.phtml but my orders are not tracked in Google Analytics. In Chrome, the below error comes

https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce

success.phtml

<script type="text/javascript">
    ga('create', '<?php echo Mage::getStoreConfig('google/analytics/account') ?>');
    ga('require', 'ec');
    <?php
        foreach ($items as &$item) {
            echo $block->getItemJs($trans['id'], $item);
        }
        echo $block->getTransactionJs($trans);

    ?>
    ga('send', 'pageview');
</script>

Uncaught ReferenceError: ga is not defined

Can anyone help me,?

Best Answer

I think you will need to call analytics.js also

As per description here it should be like below

<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
Related Topic