Google Analytics: Inserting Into a Wordpress Template
Google Analytics is a great tool for gathering data about your website. You can track and analyze all kinds of data about your visitors, their navigation paths, and the effectiveness of your content.
To use Google Analytics, you need to place some javascript on your website. A commonly asked question in forums is, “How do I add Google Analytics to my Wordpress template?”
Where the Analytics Code Goes
When you sign up for Google Analytics, Google provides you with a short piece of javascript to place on your site. The code should look like this.
<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"> var pageTracker = _gat._getTracker("UA-2894597-3"); pageTracker._initData(); pageTracker._trackPageview(); </script>
According to Google’s instructions, this needs to be placed at the very end of your site - just before the closing body tag. To do this, we need to find the closing body tag on the Wordpress template.
Look In Footer.php
As we previously discovered, a Wordpress template is made up of a series of files. Three basic files - header.php, sidebar.php, and footer.php - help build the components of the page.
If your Wordpress template follows normal conventions, the closing body tag should be in the footer.php file.
Go to your themes directory of the Wordpress installation, navigate to your current theme, and open footer.php. You should see something like this at the end.
<?php wp_footer(); ?> </body> </html>
Add a blank line before the closing body tag. Simply copy and paste the javascript code that Google provides on that blank line, save the file, and you’re good to go.
Tags: Analytics, Stat Tracking, template, wordpress







Leave a Reply