Turbolinks and Google Analytics

27 Nov 2015

Google Analytics tracking code doesn’t play well
with Rails apps using Turbolinks.
For a long time, we were using
Turbolinks compatibilty script,
but then I noticed that our bounce rate was suspiciously low.

A bounce rate of under 50% would be considered quite good,
but ours was hovering under the 5% mark.
On looking at the requests,
the script was sending in two pageview requests on each page.

The script was using the old Analytics code,
so we decided to switch to the new analytics.js from Google,
and make it work with Turbolinks.
We’re now using a much simpler method, based on
this stackoverflow thread.

Hi, I’m Nithin Bekal.
I work at Shopify in Ottawa, Canada.
Previously, co-founder of
CrowdStudio.in and
WowMakers.
Ruby is my preferred programming language,
and the topic of most of my articles here,
but I'm also a big fan of Elixir.
Tweet to me at @nithinbekal.