Magento Google Analytics Code Has Errors!

Discussion in 'eCommerce' started by jvfconsulting, Apr 26, 2010.

  1. #1
    I installed and deployed a new magento website. To track the visitors I'm using Google Analytics, so I got he code and plugged it into the admin section. When I applied the code, the site is not registering any visitors. When I looked into this here is what I found. The Magento coders totally messed this one up. Whats the best fix for this? I guess adding the script to my footer is the easiest fix.

    Here's the JavaScript they put in:

    <script type="text/javascript">
    //<![CDATA[
        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
        })();
    
        _gaq.push(["_setAccount", "UA-15937204-1"]);
        _gaq.push(["_trackPageview", "/"]);
    //]]>
    </script>
    PHP:
    This is how is should be:

    <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-15937204-1']);
    _gaq.push(['_trackPageview']);
    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
    })();
    </script>
    PHP:
    The Magento coders have it all out of order and forgot the most important line of code that created the “_gaq” object:

    var _gaq = _gaq || [];

    I’m assuming this is broken on all Magento sites??
     
    jvfconsulting, Apr 26, 2010 IP
  2. www.CaseyEquip.com

    www.CaseyEquip.com Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here is detailed tutorial
    inchoo.net/ecommerce/magento/google-analytics-in-magento/

    Hope it helps!
     
    www.CaseyEquip.com, May 2, 2010 IP