KnowledgeCenter/AmeriCommerce/Driving Sales, Marketing, & SEO

Where should I install the Javascript code for Google Analytics?

Support Agent
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.

 

For Ecommerce tracking you would install the GA tracking script  + a merge code needs to be added to the script. The merge code shown in the script example generates the details Google Analytics needs for ecommerce tracking.

Adding the merge code to your script is all that is needed while installing the script. For clarity, below is a snapshot of what the script would look like and the merge code referenced.

script.png

After the script is installed, ecommerce tracking can be turned on in Google Analtyics. Results show within 24hrs or sooner depending on the processing time at Google. The generation of the order data on our side happens as soon as the script is placed and new orders are placed.

 

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 Head Tags.
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>
 
2013-10-01_0819.png
 

Account Information

Of course for either script replace the text UA-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] > Footer

To use this script add a Custom HTML widget to the page and paste the script into it. Be sure the widget 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']);

 

Google tracking using Universal Analytics:

To begin tracking a website using analytics.js, paste the following JavaScript snippet into your website template page so that it appears before the closing </head>tag. The UA-XXXX-Y, parameter must be replaced with the Web Property ID for the Google Web Property you wish to track.

<!-- 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-XXXX-Y', 'auto');
ga
('send', 'pageview');

</script>
<!-- End Google Analytics -->

When the code runs, it asynchronously loads the Google Analytics Tracking Code onto the page. It then creates a tracker object for the web property you specified in the UA-XXXX-Y parameter. Finally, it records a pageview in Google Analytics for the page that the script was run.

 

New Google Conversion Code for 2014+

 

Step 1: Remove the existing conversion code from all the pages of the website.

Step: 2 Please place the below conversion code on the ORDER CONFIRMATION page only. Inside the body of the page .

<!-- Google Code for onlinesale(new) Conversion Page -->
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="https://www.googleadservices.com/pagead/conversion/973770487/?label=9RjrCOmUqwgQ952q0AM&guid=ON&script=0"/>
</div>

 

OLD ADMIN:

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.

For Ecommerce tracking you would install the GA tracking script  + a merge code needs to be added to the script. The merge code shown in the script example generates the details Google Analytics needs for ecommerce tracking.

Adding the merge code to your script is all that is needed while installing the script. For clarity, below is a snapshot of what the script would look like and the merge code referenced.

script.png

After the script is installed, ecommerce tracking can be turned on in Google Analtyics. Results show within 24hrs or sooner depending on the processing time at Google. The generation of the order data on our side happens as soon as the script is placed and new orders are placed.

 

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']);


Google tracking using Universal Analytics:

To begin tracking a website using analytics.js, paste the following JavaScript snippet into your website template page so that it appears before the closing </head>tag. The UA-XXXX-Y, parameter must be replaced with the Web Property ID for the Google Web Property you wish to track.

<!-- 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-XXXX-Y', 'auto');
ga
('send', 'pageview');

</script>
<!-- End Google Analytics -->

When the code runs, it asynchronously loads the Google Analytics Tracking Code onto the page. It then creates a tracker object for the web property you specified in the UA-XXXX-Y parameter. Finally, it records a pageview in Google Analytics for the page that the script was run.

 

Check out these other Articles on Google Analytics:

 

Comments

User photo
Josh Eliseuson

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

November 17, 2012 16:24
User photo
Manjula Higginbotham
AmeriCommerce

I apologize this question got missed. It was just brought to my attention so adding it for anyone else that may need the information. 

 

For Ecommerce tracking you would install the GA tracking script  + a merge code needs to be added to the script. The merge code shown in the script example generates the details Google Analytics needs for ecommerce tracking.

Adding the merge code to your script is all that is needed while installing the script. For clarity, below is a snapshot of what the script would look like and the merge code referenced.

gaconversiontracking.png

After the script is installed, ecommerce tracking can be turned on in Google Analtyics. Results show within 24hrs or sooner depending on the processing time at Google. The generation of the order data on our side happens as soon as the script is placed and new orders are placed.

 

 

 

January 03, 2014 17:41
User photo
Lisa Adams
Bad Wolf Press

This needs to be updated for use with the new Universal Analytics.

February 12, 2014 17:56