Announcement:Materials and articles for ProductCart 5 can be found at our brand new support center.

Create an account to edit articles | See Formatting Syntax for Wiki syntax | We look forward to your contribution!

Google Analytics: obtaining and adding the tracking code

Does not apply to ProductCart v4.5 and above

The contents of this page do not apply to ProductCart v4.5 and above. Learn more about Google Analytics support in ProductCart v4.5.

Retrieving the Google Analytics tracking code

The first step in using Google Analytics on your Web store is to add a small piece of “code” to your Web pages. There are two versions of the Google Analytics code, as of June 2010 (plus a third one that should no longer be used).

The "asynchronous" snippet

This is the latest tracking code, which allows for faster page loading times according to Google. This is the tracking code that is presented to you by default when you log into your Google Analytics account as of June 2010.

The tracking code is profile-specific. You can only access it from the Profile Settings screen for that profile. Go to Analytics Settings and click ”Edit” next to the profile used for your site. In the Profile Settings page, click the “Check Status” link. You'll see something similar to the code snippet below, where XXXXX-YY indicates the profile ID for your Analytics account.

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

For more information on setting up the asynchronous tracking code, please see: http://www.google.com/support/analytics/bin/answer.py?answer=174090

The "traditional" snippet

This is the tracking code that was used by default before the asynchronous snippet was introduced. The code is presented below, where XXXXX-YY indicates the profile ID for your Analytics account.

<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();
} catch(err) {}
</script>

For more information on setting up the traditional tracking code, please see: http://www.google.com/support/analytics/bin/answer.py?answer=55480

The "legacy" snippet

There used to be an even older version of the tracking code (referred to as the “legacy” code), based on a file called urchin.js. Google recommends that you do not use both the “legacy” and the new tracking code on the same Web site, so we recommend that you update to the new tracking codes mentioned above.

Also, according to our latest review of the Google Analytics Web site, there does not seem to be any documentation anymore on this “legacy” code. While it might still be supported (i.e. traffic might still be getting tracked), we recommend that you switch to the latest code.

ProductCart vs. Non-ProductCart pages

  • If you have static pages (e.g. index.html or about-us.html), or other dynamic pages that are not part of ProductCart, you will have to add the code individually to each of them (or to the template that you use to create and update those pages from a single file, such as an Adobe Dreamweaver template).
  • Your store pages are dynamically created by ProductCart using the same “interface files” for all of them (header.asp and footer.asp, as you know). This means that to track all of your store pages with Google Analytics, you will only need to edit one page. You will also need to upload a few files to your Web server to track e-commerce transactions. See (STEP 3 on this page).

Adding the tracking code

Before you start

Make sure to create back-ups of any file that you need to edit, so that you can quickly restore it in case there is an issue. If you don’t feel comfortable editing your store files as explained in this document, please contact a Web designer or developer. The pages that you will be editing are very important for your ProductCart-powered store. If you are looking for a developer, try contacting a Certified ProductCart Developer. Please note that some of them may not yet be familiar with this functionality (integration with Google Analytics). Still, they will certainly be able to assist you after reviewing this document.

Getting the tracking code

Obtain the tracking code for your profile as mentioned above under “Retrieving the tracking code”. Google recommends using the asynchronous tracking code.

Adding the tracking code

Adding the code to a static page

To add the tracking code to a static page (e.g. about-us.html), copy and paste the code into the body of the page, right before the closing </body> tag. If you are using an HTML editor, make sure to switch to code view before pasting the tracking code onto the page. Save the edited pages and upload them back to your Web site.

Adding the code to your store pages

To add the tracking code to your ProductCart-powered store, follow these directions:

  • You will add the code to the following file, depending on the ProductCart version (both files are located in the “pc” folder):
    • footer.asp” if you are using ProductCart v3
    • inc_footer.asp” if you are using ProductCart v4 or higher
  • The code must be added just before the closing </body> tag.
  • If you are using an HTML editor such as Adobe Dreamweaver, make sure to switch to “code view” to add the tracking code. Do not add the tracking code in “design” view.
  • You will also need to add a line of code that is used for tracking e-commerce transactions using Google Analytics. This is covered in the next session, but for now, please note that the following line of code will need to be added as well, right below the tracking code.
    <!--#include file="inc-GoogleAnalytics.asp"-->

Here is an example of a simple ProductCart footer file after the tracking code has been added to the page (note that the file to be edited is different when using v4.x vs. v3.x).

ProductCart v4.x

The bottom section of inc_footer.asp before adding the Google Analytics tracking code:

<% 
conlayout.Close
Set conlayout=nothing
Set RSlayout = nothing
Set rsIconObj = nothing
%>

… and after:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<!--#include file="inc-GoogleAnalytics.asp"-->
<% 
conlayout.Close
Set conlayout=nothing
Set RSlayout = nothing
Set rsIconObj = nothing
%>
ProductCart v3.x

The bottom section of footer.asp before adding the Google Analytics asynchronous tracking code:

<% 
conlayout.Close
Set conlayout=nothing
Set RSlayout = nothing
Set rsIconObj = nothing
%>
</body>
</html>

… and after:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<!--#include file="inc-GoogleAnalytics.asp"-->
<% 
conlayout.Close
Set conlayout=nothing
Set RSlayout = nothing
Set rsIconObj = nothing
%>
</body>
</html>

Important Notes

The characters “XX-XXXXXX-X” will have to be replaced with your account number. This is not something that you need to worry about. The code that you obtain from your Google Analytics account already has the correct account number for that specific Web site.

Upload the Google Analytics files to your Web store (STEP 3 on this page) at the same time or you will run into an error as the code tries to load a file (inc-GoogleAnalytics.asp), which is not there if you have not uploaded those files.

Checking the tracking code status

Troubleshooting the Tracking Code Installation

No statistics appear in the reports

Wait 24 hours after placing the tracking code on your Web site, and then log into your Google Analytics account: you should see information about page views, visitors, etc. If not, that means that the tracking code was not added correctly. If you cannot figure out why your Web site is not being tracked, please see this article.

Storefront error

If your storefront returns the following errors after adding the tracking code…

Microsoft VBScript compilation  error '800a0411'
Name redefined
pc/inc-GoogleAnalytics.asp, line 16
dim pGetItems, pcGAtransaction, pcGAtransactionItems
----^

… this indicates that you are including the file inc-GoogleAnalytics.asp. Specifically, make sure that you do not include this file in both footer.asp and inc_footer.asp. The file should only be included in inc_footer.asp, as mentioned above.

Next: tracking orders in Google Analytics

The next section focuses on tracking e-commerce transactions.


QR Code
QR Code Google Analytics: obtaining and adding the tracking code (generated for current page)