Discourse
Add Rybbit analytics to your Discourse forum
Discourse adds site-wide code through theme components. A component has an editable </head> section that Discourse injects into every page and, because Discourse ships a strict Content Security Policy, it stamps the required nonce onto script tags placed there. No server access or plugin is needed.
Get your tracking snippet
In your Rybbit dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Rybbit, app.rybbit.io is the domain of your own instance.
Add the snippet to Discourse
- In the admin sidebar open Appearance → Themes and components (older versions: Admin → Customize → Themes).
- On the Components tab click Install, choose Create new, name it "Rybbit Analytics", make sure the type is Component and click Create.
- Click Edit CSS/HTML, stay on the Common tab and open the
</head>section (not Header, which is the visible page header). - Paste the snippet and click Save.
- Back on the component page, add your active theme under Include component on these themes so the component is enabled.
Discourse is a single-page app: after the first load, topics and categories open without a full page reload. The tracker wraps history.pushState and history.replaceState and listens for popstate, so those navigations are recorded as pageviews.
Verify installation
Open your live site in a new tab and click through a few pages. Within a few seconds the pageviews appear in the Rybbit dashboard.
If nothing shows up:
- View the page source and search for
script.js?siteId=to confirm the snippet is on the page. - Open the browser Network tab and check that
script.jsreturns200and thatPOSTrequests go to/api/track. - Disable ad blockers, or set up a proxy so the script loads from your own domain.
- See the script troubleshooting guide for other common causes.
Troubleshooting
- Component saved but the script is missing from the page source: the component is not attached to the active theme. Add the theme under Include component on these themes, or add the component from the theme's Included components list.
- Script tag present but blocked: check the browser console for a CSP error. Scripts added through the
</head>section receive Discourse's nonce automatically; scripts injected any other way (for example from a plugin's raw HTML) do not. - Only the first pageview is recorded: the SPA Navigation setting is off for the site in your Rybbit dashboard. Turn it on under Site Settings.
Next steps
- Track custom events such as signups, purchases and button clicks.
- Identify users to connect sessions to accounts.
- Proxy the script through your own domain to bypass ad blockers.
- Script attributes let you skip or mask URLs and tag events.