Knowledgebase

Home » Item #959

How do I set up Google Analytics?

Item: #959
Date: 21 Dec 2006
Applies to
v6

Question

I would like to set up Google Analytics on my CactuShop. How do I do this?

Answer

1. Sign up for Google Analytics:

http://www.google.com/analytics/

Once your account is created, Google gives you some code to insert into your pages:

<script src="http://www.google-analytics.com/urchin.js"
type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXXXX-1";
urchinTracker();
</script>

(where XXXXXXX is your Google Analytics account number)

Google states that this code is to be placed before the closing body tag of your page, so placement in the CactuShop skin template file is the obvious solution. However, the code causes some problems on pages that are run under SSL, so if your site has payment made direct on the site using HTTPS, you will need to follow the next steps.

2. Add xxxGOOGLEANALYTICSxxx as a new custom tag just before the closing body tag in your template.htm file as shown below:
xxxGOOGLEANALYTICSxxx
</body>
</html>

3. Add the following code to the buildpage.asp, somewhere near the top (be sure to change XXXXXXXX to your Google Analytics account number):
strGoogleAnalytics="<script
src=""http://www.google-analytics.com/urchin.js""
type=""text/javascript"">" & vbcrlf

strGoogleAnalytics=strGoogleAnalytics & "</script>" & vbcrlf

strGoogleAnalytics=strGoogleAnalytics & "<script
type=""text/javascript"">" & vbcrlf

strGoogleAnalytics=strGoogleAnalytics & "_uacct = ""UA-XXXXXXX-1"";" &
vbcrlf

strGoogleAnalytics=strGoogleAnalytics & "urchinTracker();" & vbcrlf

strGoogleAnalytics=strGoogleAnalytics & "</script>"

If blnMenuDisabled THEN strGoogleAnalytics=""

Note that some of the lines may wrap in the above example but should not have carriage returns when you copy them to your buildpage.asp file - to identify separate lines, we've left an extra gap between each. Ensure you replace XXXXXXX with your Google Analytics account number.

4. Add the following a few lines up from the bottom of buildpage.asp, where the other replacements (such as the xxxBASKETSUMMARYxxx tag) are done:
strPageBaseText = Replace(strPageBaseText, "xxxGOOGLEANALYTICSxxx",
strGoogleAnalytics & "")

(again, should be a single line but wraps due to the width of this page)

You should now see the Google Analytics code in the source of any front end pages with the exception of ones that can run under SSL (such as the checkout pages).

5. In order not to skew the results, you may wish to exclude your own computers from being tracked by the Google Analytics code. To achieve this, create a new page on your web (e.g. noanalytics.asp) with the following contents:
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<body>
<%

if request.Cookies("NoAnalytics") = "" then
response.Cookies("NoAnalytics") = "Yes"
response.Cookies("NoAnalytics").Expires = Date + 9999
%>
<p>Thank you - a cookie has been defined so that visits from your PC will not be tracked for statistical purposes (provided that cookies are not disabled on this PC)</p>
<%
else
response.Cookies("NoAnalytics").Expires = Date + 9999
%>
<p>Tracking is already disabled on this PC</p>
<%
end if

%>
<p>Please remember to run this script on every browser (e.g. FireFox & Internet Explorer) and any other PCs that you may use to view the website with.</p>
<p>In addition, if you ever delete all cookies on your PC, please remember to run this script again to avoid tracking.</p>
</body>
</html>

Call up the URL of this page from any browser that you want to exclude from Google Analytics; a cookie will then be planted on it. You should receive an on-screen confirmation.

Finally, edit includes/buildpage.asp and change the following line (note that some lines will be wrapped when displayed here):
strPageBaseText = Replace(strPageBaseText, "xxxGOOGLEANALYTICSxxx", strGoogleAnalytics & "")

to:
if request.Cookies("NoAnalytics") = "" then
strPageBaseText = Replace(strPageBaseText, "xxxGOOGLEANALYTICSxxx",strGoogleAnalytics & "")
else
strPageBaseText = Replace(strPageBaseText, "xxxGOOGLEANALYTICSxxx","")
end if

This should then ensure that the code only tracks hits from computers without the new cookie. Remember that if you change computers or browsers, delete cookies or do something else that will remove cookies, you will need to run the script again to exclude your computer from the Google Analytics data.

Credits: thanks to Dave Banas for the basis of this posting and Andre Gibson for the code to exclude certain computers.

Can't find the answer you need? Click here to open a support ticket.

« Back