Docs
De docs doorbladeren

Add Privatus Analytics to Turbo and Hotwire

Add cookieless analytics to an app that uses Turbo Drive, Hotwire or Turbolinks with one script tag in the head that counts each visit once.

Als Markdown bekijken

Add the snippet to your layout's <head>, not the body:

html
<script defer src="https://privatusstats.com/js/pa.js" data-site="pa_YOURSITEID" data-modules="engage,auto,vitals,clicks,ask"></script>

Turbo Drive checks the <head> of each new page for scripts that are not on the current page and appends only those. The tracker is already there, so it loads once and keeps running across visits.

Turbo Drive changes pages with history.pushState, and the tracker follows that by default (data-spa="auto"). Each visit counts as one page view and you don't need a turbo:load listener. Counting from both would give double views, so don't also send pageviews yourself. See single-page apps.

Notes#

  • Don't add data-turbo-track to this tag. That attribute is for your own bundles, to force a reload when a new build ships.
  • Turbolinks, the older library, also uses pushState, and the same tag works.
  • For Rails, see the Rails page. Frames and streams that change part of a page are not page views.