# 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)

1. Go to **Admin → Customize → Themes**, open the **Components** tab and choose
   **Install → From a git repository**.
2. Paste `https://github.com/Privatus-Analytics/discourse-privatus-analytics`
   and install it.
3. Add the component to your active theme.
4. 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](/docs/tracker/attributes) to
load.

## Paste the snippet instead

1. Go to **Admin → Customize → Themes**.
2. Select your active theme and choose **Edit CSS/HTML**.
3. Open the **Head** tab and paste the snippet:

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

4. 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](/docs/tracker/spa).
