Contribution Name: Simple Google Analytics
Version Date: v 1.2.5 10/31/2011 Eric Leuenberger (Zen ID: econcepts) http://www.ecommerceamplifier.com
License: under the GPL - See attached License for info.
Designed for: Zen Cart v1.3.6 and higher. Release can be compatable with older versions as well.
Portions copyright Andrew Berezin
Portions copyright Dayne Larsen
Description: This new module version 1.2.5 enables you to integrate the Google Analytics service
with both e-commerce tracking and Conversion Tracking capabilities as described here:
http://www.google.com/analytics/ using the new release of "ga.js" code (replacing the "urchin.js" version)
released by Google in December of '07 and documented here:
http://analytics.##########################/2007/12/announcing-new-graphing-tools-gajs.html
OR by using the Asyncronous tracking code released in December of 2009 by Google documented here:
http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html
Zen Cart Support forum thread here: http://www.zen-cart.com/forum/showthread.php?t=53701
What This Contribution Does
Installs Google Analytics tracking capability on your site using either the legacy (urchin) version, "ga.js", or "asyncronous" tracking Google code version including:
a) E-Commerce Tracking
b) Adwords (pay per click) Conversion Tracking
c) Enables you to customize the tracking code to your liking to add additional elements per Google terms.
d) Allows dynamic tracking of revenue for Conversion and Ecommerce. (Pulls actual order amount from cart and enters in your Google Analytics account.)
e) Enables tracking of new pagetime variable for monitoring load times of your site.
##############################################################################
Installation Instructions (New Installs ONLY and upgrade from oldest 1.0 version)
##############################################################################
NOTE 1: Follow these set of instructions ONLY if you have never had any of the Simple Google Analytics Modules installed.
If you have had any other version (1.0 or 1.1) prior to this, then follow the upgrade instructions for your version.
NOTE 2: Where ever you see the words "your_template" (in either these instructions, or the file folders included with the install)
you should REPLACE that with the directory name that yoru template is running from. So for example, if you are running a
custom template and the directory that you decided to keep those template files in is called "mycustomtemplate" then, where ever
you see the words "your_template", you would change it to "mycustomtemplate".
If you are using the default template provided with zen cart, then you would replace each instance of "your_template" with the
following: "template_default"
HINT: If you don't know what the directory name is you are using, then you can find it out by following these steps:
1) Login to your Zen Cart admin
2) Go to "Tools > Template Selection" from the menu
3) From the screen that shows, look under the column that is titled "Template Directory". The name you find under that column is the
name of the directory that your zen cart site design is running in. This EXACT name is the one that you will use to replace
each instance of "your_template".
######################
STEP 1:
######################
After you have identified the directory that your template is running from and determined where you will be uploading the files to,
upload the included install files and directories to your zen cart site.
##################################################
STEP 2: (FTP files to the internet)
##################################################
Make sure your body tag in /includes/templates/[your_template]/common/tpl_main_page.php
includes this code (if not see trouble shooting below it is not neccassary but an addition
to your template needs to be made):
**** HELPFUL HINT: ****
If you are runnning any of the 1.3.x versions of Zen Cart, this line is already
included with those installs and you can safely skip this step. You may need to check earlier
versions for it though.
<body id="<?php echo $body_id . 'Body'; ?>"<?php if($zv_onload !='') echo ' onload="'.$zv_onload.'"'; ?>>
###################################################################
STEP 3: (Make alterations to tpl_main_page.php file)
###################################################################
PART A:
At the bottom of /includes/templates/[your_template]/common/tpl_main_page.php
Copy and paste the following lines of code (found below) just before the </body> tag:
<?php
if (GOOGLE_ANALYTICS_TRACKING_TYPE == "Asynchronous") {
// Do nothing
} else {
require(DIR_WS_TEMPLATE . 'google_analytics/google_analytics.php');
}
?>
=====================
NOTE: If you were using a previous version (1.2.x) of Google Analytics (prior to 1.2.3) then you'll need to change the code in the previous location
At the bottom of /includes/templates/[your_template]/common/tpl_main_page.php
Find the lines of code that look like this (found below) just before the </body> tag:
<?php
if (GOOGLE_ANALYTICS_TRACKING_TYPE == "Asynchronous") {
require($template->get_template_dir('.php',DIR_WS_TEMPLATE, $current_page_base,'google_analytics') . '/google_analytics.php');
}
?>
CHANGE / replace the lines of code to look like this:
<?php
if (GOOGLE_ANALYTICS_TRACKING_TYPE == "Asynchronous") {
// Do nothing
} else {
require(DIR_WS_TEMPLATE . 'google_analytics/google_analytics.php');
}
?>
############################################
STEP 4: (Apply the SQL Patch)
############################################
If this is a BRAND NEW install, you will need to update your database with the googleanalytics-INSTALL.sql file.
If you are upgrading (from the oldest 1.0 version), you will need to use the upgrade SQL file that is included.
In your site admin go to Tools->Install Sql Patches and apply the googleanalytics.sql patch included.
NOTE to those upgrading from version 1.1
If you are upgrading from the previous 1.1 version, then follow the upgrade instructions included for that version located
in the above section. Do not use these instructions.
NOTE to those upgrading from version 1.0
The new "ga.js" version of tracking does not need one bit of JavaScript that was included in the previous "urchin.js"
versions. You will need to DELETE this line from your code.
includes/modules/pages/checkout_success/on_load_main.js
REMOVE the following line from that file "javascript:__utmSetTrans();"
If that is the ONLY line you see in the file, than it is safe to completely DELETE the file. If this is not the only
line found in that file, then delete only that line, and save the file. Re-upload the new version to your site.
Keeping this line in when using the new ga.js tracking code can cause JavaScript errors to pop up on your site (since
the new code does not refer to this function anymore).
How to use this module
-
Once you have completed a successful install or upgrade, login to your Zen Cart admin and go to configuration->google analytics configuration and set your google
analytics account number and any of the other settings as you see fit.
-
Login to your Google Analytics account and make sure your site is set to "receiving data"
or "waiting for data" (this means you have sucessfully installed the analytics code on your
site.)
-
To take advantage of Google Analytics E-Commerce Tracking, you must login to your Google
Analytics account after installing this contribution and enable e-commerce reporting as follows:
a. Log in to your account.
b. Click "Edit" next to the profile you'd like to enable.
c. On the Profile Settings page, click "edit" next to Main Website Profile Information.
d. Change the E-Commerce Website radio button from No to Yes.
e. Save your changes
Troubleshooting
QUESTION: The "body tag" of my site is different from that which is shown in these instructions and does NOT include the "$zv_onload" code.
What should I do to install Simple Google Analytics?
ANSWER:
If your body tag is different (does not have the $zv_onload code) replace with this code:
<?php
if($page_directory == 'includes/modules/pages/checkout_success')
{
echo '<body onLoad="javascript:__utmSetTrans()">'; ///This should be changed to match your current body code plus the onLoad="javascript:__utmSetTrans()" call
}
else
{
echo '<body>'; ////THE <body> SHOULD BE CHANGED TO WHATEVER YOUR CURRENT BODY CODE IS
} ?>
QUESTION: I installed the module, but now I recieve an error message at the bottom of my page(s) that looks similar to the following:
Warning: main(includes/templates/template_default/google_analytics/google_analytics.php): failed to open stream: No such file or directory in xxx/catalog/includes/templates/custom/common/tpl_main_page.php on line 182
Warning: main(includes/templates/template_default/google_analytics/google_analytics.php): failed to open stream: No such file or directory in xxx/catalog/includes/templates/custom/common/tpl_main_page.php on line 182
Fatal error: main(): Failed opening required 'includes/templates/template_default/google_analytics/google_analytics.php' (include_path='.:/usr/local/lib/php') in xxx/catalog/includes/templates/custom/common/tpl_main_page.php on line 182
What have I done wrong?
ANSWER:
This type of error message means that the files which were uploaded were not put into the proper location. Specifically, the install file found at
/templates/your_template/google_analytics/google_analytics.php
was not uploaded to the correct location. Once that is in the correct location, this error message will go away. Here is further detail on how to put it into
the correct location.
Againg, this error is a direct result of not installing the "google_analytics" directory to the proper location (it contains the file that in included on the page
with the snippet of code you put into your "tpl_main_page.php" file.
The location of the directory should be in the following area:
/includes/templates/[YOUR CUSTOM TEMPLATE HERE]/
So, once you upload, your directory structure will look like this:
/includes/templates/[YOUR CUSTOM TEMPLATE HERE]/google_analytics
If you are using the default template, then obviously the path would look like this:
/includes/templates/template_default/google_analytics
QUESTION: I installed the new code, but now I am getting a JavaScript error on my pages that refers to "__utmSetTrans();". What does this mean
and how do I get rid of it?
ANSWER:
If you are receiving this error message, that means you did not follow step 8 included in these instructions. This included the removal of the line
of code that looks like "__utmSetTrans();" from the following file on your site /includes/modules/pages/checkout_success
Open that file, remove that line (or, if it is the only line shown in that file then you can remove the entire file) and the error should go away.
Zen Cart Commercial Support Resource
If you are still having problems or want to learn how to use Google Analytics to increase sales
from your website, vist the forums at: http://www.EcommerceAmplifier.com/forum/