Adding Google Analytics to your Zen Cart store


Google Analytics on your Zen Cart storeGoogle Analytics, a free web analytics tool, can provide you with a range of statistics on your website traffic and marketing effectiveness.  One of the more useful features of Google Analytics is the ability to flag certain pages as “goals.” This is specifically beneficial to e-commerce web sites such as your Zen Cart store where you may set the Checkout Success page as a goal so that this can be reported on in Google Analytics.

Information such as number of visitors, the pages they viewed, if they were a repeat visitor, their geographic location, their browser version and more is available through the easy to read reports and graphs.

Google Analytics only tracks pages that contain the Google Analytics tracking code.  There are contributions / addons available to help you add the Google Analytics code to your Zen Cart store.  However, it is a fairly simple process to do this yourself and to help you here is a step-by-step guide:

Locate the Google Analytics Tracking Code

  1. First, sign up to Google Analytics with a Google account.  If required, you can follow the step-by-step guide to Signing Up for Google Analytics.
  2. Log in to your Google Analytics account at http://www.google.com/analytics.
  3. Click the Analytics Settings link.
    image
  4. Click on Edit from your Zen Cart store profile’s Settings column.  Please note that tracking code is profile-specific (if you have more than one site under your Google Analytics account).
  5. At the top right of the Main Website Profile Information box, click Check Status.
    image
  6. Your tracking code is displayed in the box under Paste this code on your site, as shown.  Click inside the box and press Ctrl-A to highlight the code.  Press Ctrl-C to copy the code.
    image
  7. Click Save and Finish.

Installing the Google Analytics Code

The Google Analytics code needs to be added to all pages that you wish to track.  The best way to achieve this easily is to add the code to the main page template.  This way the code is automatically included in each page as it is built by Zen Cart.

  1. Locate your template’s tpl_main_page.php file.
    This will be located in the /includes/templates/custom/common folder, where custom represents your template’s folder name.
  2. Using your FTP client, download this file to your computer.  Make another copy of the file and rename the copy tpl_main_page_backup.php or something similar.
  3. Open the tpl_main_page.php file on your computer with your favourite editor, such as Notepad ++ or Dreamweaver.
  4. Scroll to the end of the file and locate the </body> tag.
  5. Paste the Google Analytics code directly above this tag.
    ?>
    
    <!--eof- banner #6 display –>
    
         <!--enter Google Analytics code here->
    </body>
  6. Save the file and upload to your Zen Cart store.
  7. Go back to the Google Analytics home page and click on Edit next to your Zen Cart store profile.
  8. Click on Check Status.image
  9. Under Tracking Status Information, you will now see that the tracking code has been successfully installed and that the status is Waiting for Data.
    image
  10. Now, it’s a matter of waiting for Google Analytics to display the data it is collecting.  This can sometimes take up to 48 hours.

Google Analytics can provide you with very valuable information about how your visitors interact with your Zen Cart store.  Remember though, it is not real-time data and is only updated at various intervals throughout the day.

     
   
     

,

  1. #1 by mollie on 7 April, 2010 - 12:48 pm

    thank you so much for this tutorial! I’m building my website and I spent so much time trying to figure out where to paste the stupid code to!

  2. #2 by kerrin hardy on 8 April, 2010 - 7:47 am

    Hi Mollie, glad it helped you. Your store and blog look fantastic! Such beautiful jewellery and very interesting too.
    Cheers
    Kerrin

  3. #3 by Fee on 20 July, 2010 - 9:42 pm

    Thanks so much. Ive tried a few other ways, listed in other forums, with no luck. Thanks again!

  4. #4 by kerrin hardy on 24 July, 2010 - 12:53 pm

    Hi Fee
    Thanks for dropping by and letting me know that this worked for you.
    Cheers
    Kerrin

  5. #5 by Troy on 20 April, 2011 - 5:21 am

    I know this thread is old, but it still shows up when you search for zen cart + google analytics so I just wanted to give a little suggestion.

    Instead of putting the script in tpl_main_page I would put the script in html_header.php and place that in your includes/templates/custom/common/ directory

    cheers

  6. #6 by kerrin hardy on 20 April, 2011 - 8:31 am

    Hi Troy

    To avoid the loading of your pages being affected by the tracking code, Google’s recommendation for installation is:
    Copy and paste the tracking code into the bottom of your content, immediately before the /body tag of each page you are planning to track.

    Either way works, but as part of optimizing your store’s performance, I would go with best practice of asynchronous loading of scripts.
    Hope this helps,
    Kerrin

  7. #7 by sid on 15 January, 2012 - 6:59 am

    hi, im new to zencart and i dont seem to find tpl_main.php in the folder you have suggested. however i did manage to find the same named file in \includes\templates\template_default\common . is this mean to be copied in to the initial folder you suggested? cheers.

(will not be published)