Add Privatus Analytics to Discourse
Add cookieless analytics to a Discourse forum with the free theme component, or paste one snippet into your theme's Head tab.
You need to be an admin of the forum. Both ways work on hosted and self-hosted Discourse.
The theme component (easiest)#
- Go to Admin → Customize → Themes, open the Components tab and choose Install → From a git repository.
- Paste
https://github.com/Privatus-Analytics/discourse-privatus-analyticsand install it. - Add the component to your active theme.
- Open the component's settings and paste your site ID (
pa_YOURSITEID).
By default it does not count staff, and it skips /admin pages. You can change
both in the settings, and choose which modules to
load.
Paste the snippet instead#
- Go to Admin → Customize → Themes.
- Select your active theme and choose Edit CSS/HTML.
- Open the Head tab and paste the snippet:
<script defer src="https://privatusstats.com/js/pa.js" data-site="pa_YOURSITEID" data-modules="engage,auto,vitals,clicks,ask"></script>
- Save, then reload the forum.
This way counts everyone, staff included.
If the script is blocked#
If the browser console says the script was blocked by the content security
policy, use the theme component above. It loads the script in a way that
current Discourse allows, with no setting to change. On older Discourse
versions you can instead add https://privatusstats.com to the
content security policy script src site setting under Admin → Settings.
Discourse is a single-page app. The tracker follows its history.pushState
navigations automatically, so each topic or list view counts once. See
single-page apps.