Google has rolled out a new way to send your data to Google Analytics, Adwords and more called gtag.js. This seems to be the new default when adding new properties to Google Analytics. The old guides for how to integrate Turbolinks with Google Analytics no longer work with gtag.js.
In order to get Google Analytics working with Turbolinks however you have to hook into this AJAX load in order to send the page
change to Google Analytics. In the past you used the
ga function to do that but that doesn’t work with the gtag.js API.
What you do instead is put this at the very top of the
head-part of your
application layout file:
GA_TRACKING_ID with your Google Analytics tracking id.
The interesting part is in the
turbolinks:load part which
uses the new gtag api to send page locations when Turbolinks loads a new page.
Now it works just fine!