- b2evolution CMS User Manual
- Advanced Topics
- How to...
- How to set up Google Analytics
How to set up Google Analytics
In addition to b2evolution’s built-in Server Side Analytics, you may want to set up Google Analytics which may give you additional graphs regarding human visitors through the web.
Google Analytics cannot see robots, spiders, RSS readers, AJAX queries and service requests. Google Analytics also won’t let you see or identify spammers. Use b2evolution’s built-in Server Side Analytics to have a complete picture of hits on your website.
Google Analytics may be desirable if your b2evolution website, blog or forum are part of a vaster web presence which is globally tracked with Google Analytics.
Generate your tracking code snippet
The Google Analytics documentation about how to generate your tracking code snippet can be found here:
http://support.google.com/analytics/bin/answer.py?hl=en&answer=1008080
The code snippet will look something like this: (Note: the code provided by Google is frequently updated/optimized. So don’t worry if the one Google suggest is a bit different).
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XABCX-Y']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Insert your your tracking code snippet into b2evolution
Once you have your own snippet, you can simply insert it into the Advanced Collection Settings screen in the field named "Custom meta tag/css section (before </head>):".
Should I put the Analytics code before </head>
or before </body>
?
With older versions of the tracking code, it was recommended to put the code at the end of the page (that would have been in the field "Custom javascript section (before </body>
):") because the original method Google provided for loading ga.js
was blocking.
But with the latest versions of the analytics code (since 2009 – see code above), the snippet can safely be put in the head section with minimal blockage; so it is now perfectly fine and optimized to put it just before </head>
.
Putting it before </head>
will still add a very little amount of latency, whereas putting it before </body>
will reduce the number of pageviews recorded at some small margin (e-g: if someone clicks on a link before your page is fully loaded). It’s a tradeoff.
The script ga.js
is heavily cached by users and present on a large percentage of sites across the web, so its often served from the cache, reducing latency to almost nil. Therefore we recommend placing the snippet before </head>
.
You can find a detailed explanation of how the code works here: https://developers.google.com/analytics/devguides/collection/gajs/
More
The above is the standard set up that most people use.
For reference, be advised there are more advanced features that you might want to set up if you feel comfortable with manipulating javascript:
- Event Tracking: see:
- Goals:
- Custom variables:
- Site Speed tracking: