KnowledgeCenter/AmeriCommerce/Uncategorized

Where should I install the Javascript code for Google Analytics?

Americart Support
posted this on September 05, 2012 18:23

Google Analytics is a free service offered by Google that generates detailed statistics about the visitors to a website. To enable it to track visits to your webpages, you must add the Javascript code provided by Google to your webpages' source.

After adding the code to your website, you will not immediately see results in your Google Analytics statistics, because their reports are only updated every 24 hours.

Google's most recent script is called the Asynchronous Tracking Script. While they still support tracking from the Traditional script, it is not recommended.

 

Where to place Asynchronous Tracking Snippet:

The asynchronous snippet works differently from the traditional script. The asynchronous script is loaded simultaneously with the page content and doesn't need to be placed in the footer. Google recommends that the asynchronous script be placed as the very last script before the </head> tag.

To do this in Americommerce go to Themes > [Current Active Theme] then go to Global Settings.
Place the following script at the very end of the Head Tags box.

 

<script type="text/javascript">
 
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxx-x']);
  _gaq.push(['_trackPageview']);
 
##GOOGLECONVERSIONTRACKINGASYNC##
  (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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
 
</script>
 
 

Account Information

Of course for either script replace the text xxxxxx-x with your Google Analytics account number

 

Where to place the Traditional Google Analytics Conversion Tracking Scripts:

This section of the KB is only for legacy purposes. Google strongly recommends using the newer Asynchronous Script as it is more accurate and faster.

If you still wish to use the Traditional script, it needs to be placed in the footer under Themes > [Active Theme] > Page Footer.

To use this script add a Custom HTML Snap-In to the page and paste the script into it. Be sure the Snap-In is set to HTML mode and not WYSIWYG mode.

Note: this only works with dedicated SSL, not shared SSL.

<script type="text/javascript">

    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

</script>
<script type="text/javascript">

    try{
    var pageTracker = _gat._getTracker("UA-xxxxxx-x");
    pageTracker._trackPageview();
    ##GOOGLECONVERSIONTRACKING##
    } catch(err) {}
 
</script>

Google tracking script line items:

The merge code below will create a line item to post to Google tracking legacy only.

##ADDITEM##

Output sample: pageTracker._addItem( "100075","eProduct3","eProduct3","","0.00","2");

 

The merge code below will create a line item for the Google Asynchronous tracking:

 

##ADDITEMASYNC##

Output sample:

_gaq.push(['_addItem', '100075','eProduct2','eProduct2','','0.00','1']);



 

Comments

User photo
Josh Eliseuson

How do you install the Google Analytics script for eccomerce tracking?

November 17, 2012 16:24