- Web templates
- E-commerce Templates
- CMS & Blog Templates
- Facebook Templates
- Website Builders
How to add Google Analytics tracking to my template?
August 24, 2011
This manual will show you where to insert the Google Analytics code into your template.
Google Analytics tracking code allows you to collect visitor data for your website. The tracking code works by the inclusion of a block of JavaScript code on your website pages. When visitors to your website view a page, this JavaScript code executes the tracking operation for Analytics. Data about the page visit is collected and sent to the Analytics server through a list of parameters attached to a single-pixel image request.
You can learn more about the Google Analytics and see more tutorials and documentation from the code.google.com
Usually the Google Analytics code should be inserted before the closing </body> tag. Let’s see where to insert the code for each type of templates.
HTML, Flash, XML Flash, JS Animated
For these templates the code should be inserted into the main index.html file. Use the search tool to find the closing </body> tag and insert the code just before it.
In case you have several html files like index-1.html, index-2.html etc you should insert the code into each file.
E-commerce Templates
For ecommerce templates you can search for additional modules and extensions that may allow you to use the Google Analytics tracking system without inserting the code manually. In case you want to add the code manually use the following directions.
osCommerce
Insert the code into the includes/template_bottom.php file before the </body> closing tag. You don’t need to paste it anywhere else.
Magento
Open the magento\app\design\frontend\default\theme###\template\page directory and insert the code at the very bottom of the footer.phtml file. No need to paste it anywhere else.
In case the footer.phtml file is missing from your theme directory you can copy it from the app\design\frontend\base\default\template\page\html directory and then insert the code.
Prestashop
The code should be inserted into the themes\theme###\footer.tpl file. You can edit the .tpl file using your default HTML editor like Dreamweaver or notepad. Insert the code before the closing </body> tag
ZenCart
Open the includes\templates\theme###\common directory and insert the code before in closing </body> tag in the tpl_main_page.php file.
You can also insert the code at the very bottom of the includes\templates\theme###\common\tpl_footer.php file
VirtueMart
Open the templates/theme### directory and insert the code before the closing </body> tag in the index.php file
CMS and Blog templates
Joomla
Open the templates/theme### directory and insert the code before the closing </body> tag in the index.php file
Drupal
We recommend not to modify the Drupal core code and use the Google Analytics module.
WordPress
The code could be inserted into the wp-content\themes\theme###\footer.php file but it’s more easy to use the Google Analytics for WordPress plugin