How To Install Google Analytics With MyBB

Easily add Google Analytics code to MyBB with a plugin or with one template edit.

Google Analytics is free to use and provides invaluable historical data on visitors. It’s the most popular analytic tool among webmasters for this reason.

Get a Google Analytic account (duh)

Google’s get started with analytics page is the best place to be if you want an account but don’t know how to get one. I won’t waste your time by re-hashing what they say.

Use a plugin

Pick your poison below. Both do the same thing and the only major difference is compatibility.

  1. Google Analytics – This plugin is created by jugentiner and works with MyBB 1.8 (latest version at time of this post)
  2. Google Analytics – This plugin is created by querschlaeger and works with MyBB 1.4 & 1.6

Manually edit templates

For those that love good old edits, find the footer template of the theme you would like to add the GA code to.

If you’re working with the default template it’s here:

Home » Template Sets » Default Templates » Edit Template: footer

Your GA code should look like this:

<script type="text/javascript">
 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAllowLinker', true]);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

Then add the code to the end of your footer template.

Boom. You’re done.

Footer or Header?

Some people are concerned that Google Analytics code is render-blocking. Meaning, it can block the rest of the page from loading before the browser is done loading GA.

For those that have Universal Analytics, you can pretty much place it anywhere on the page. Those that have old, classic, code should load the code at the bottom of the footer like we went over above.

Leave a Reply

Your email address will not be published. Required fields are marked *