Frequently Asked Question

Google Analytics
Last Updated 5 years ago

Google Analytics is a powerful tool for tracking traffic on your
site. Not just how many page views you get, but also where they come
from and how they flow through the site and a lot more.

This article will explain how to add Google Analytics to Cart32. A
few assumptions are made, such as that you already have a Google
Analytics account.
Please make sure that you have flagged it as an E-commerce site.
You will be given some code that looks like (If you have goals
enabled, there will be slight differences, such as an extra line):

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 % 3 C / script % 3E "));
            try {
                var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
                pageTracker._trackPageview();
            } catch (err) {}


A few changes will need to be made to this. First thing you have to
do is add a line that will allow the tracking code to work across
domains. If your cart and site are on the same domain, you can skip
this.

Add pageTracker._setDomainName("none"); below the var pageTracker =
line.

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"));

try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._setDomainName("none");
pageTracker._trackPageview();
} catch(err) {}

This code as is will go in all the pages on your website, near the
tag - this is towards the top of the page.

Each link that goes to the cart will need to be changed as well.

For the "add to cart" buttons and other forms, add

onsubmit="pageTracker._linkByPost(this)"

to each

The final result should be something like

Don't forget to use the address to your actual shopping cart and
your actual client code.

If you have just straight links to your cart as well, such as for
the View Cart feature, add

onclick="pageTracker._link(this.href); return false;"

to the end of the tag.

Next we will add the code to the template files.

The four main ones are:

ItemList.html
SendOrder.html
ReviewOrder.html
ConfirmOrder.html

NoItem.html is also needed, so the tracking is not broken if someone
empties their cart.

There are a few others that you can add the code to. It's mostly any
one that has a tag in it.

Add the following code near that closing body tag.

var gaJsHost = (("https:" == document.location.protocol) ?

"https://ssl." : "http://www.");

document.write(unescape("%3" + "Cscript src='" + gaJsHost +

"google-analytics.com/ga.js'

type='text/javascript'%3"+"E%3"+"C/script%"+"3E"));

try {

var pageTracker=_gat._getTracker("UA-XXXXXXX-X");

pageTracker._setDomainName("none");

pageTracker._setAllowLinker(true);

}catch(err){}

This code is slightly different from the normal code that Google
provides, but it is functionally the same. Cart32 looks for certain
string of characters due to some issues sometimes caused with
Frontpage. The slight modification is to alter the unescape() function
call to avoid that specific string.

Save your template files after adding this code.

The final step is to login to the cart, go to the Cart Settings ->
Google tab and check the box that says to use Google Analytics and
enter your UA number without the UA.

This will add e-commerce tracking to the GA code. Click save and you
are done

Please Wait!

Please wait... it will take a second!