DEV Community

loading...

Make Fathom Analytics work with Turbolinks / Turbo in your Rails project

rinas
Generalist β€’ Software writer β€’ Ruby enthusiast
・1 min read

If you have Turbolinks or Turbo in your Rails project, only the first page view would be counted and tracked by Fathom Analytics. Here is how you can make use of load event to track the page views.

For turbolinks:

document.addEventListener("turbolinks:load", function() {
  if (window.fathom) {
    window.fathom.trackPageview()
  }
})
Enter fullscreen mode Exit fullscreen mode

For turbo:

document.addEventListener("turbo:load", function() {
  if (window.fathom) {
    window.fathom.trackPageview()
  }
})
Enter fullscreen mode Exit fullscreen mode

I had recently confirmed the same with Fathom team:


and looks like this is the way to go:

Discussion (0)