while true live

Musings on the fatality of infinite loops and other stuff.

Using Google Universal Analytics With Octopress

When I first set up my Github pages Octopress blog I followed those instructions to set Google Analytics tracking up – and it worked. However, in May Google Analytics somehow decided to move my account to Universal Analytics – maybe I had approved it without really knowing what it meant…

Well, what is Universal Analytics? I have no idea! The important thing to notice is, though, that you need to change your JavaScript tracking code if you make that transition; obviously, I didn’t know that. Otherwise tracking wouldn’t work any longer; would it? As a matter of fact, it somehow did.

It is not only not right, it is not even wrong.

Wolfgang Pauli

Actually, my Analytics dashboard did show some visits and hits, that’s why I didn’t notice the problem for a long time, however, I guess it only mentioned 10% of them! Anyway, after a long debugging session with Google Tag Assistant and Google Analytics Debugger I figured out the necessity to change the code, finally.

Shortly, you just need to change your source/_includes/google_analytics.html to this code:

1
2
3
4
5
6
7
8
9
10
11
{% if site.google_analytics_tracking_id %}
  <script type="text/javascript">
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '{{ site.google_analytics_tracking_id }}', 'auto');
ga('send', 'pageview');
  </script>
{% endif %}

Concerning Github pages, it’s not necessary to include a call to set your domain to github.io any longer. It just works out of the box – what a progress! It is not only right, it is not even wrong now!

Comments