OnyxMetric
Integration Guides

Discourse

Add OnyxMetric 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. Because Discourse ships a strict Content Security Policy, this is also the way that keeps the script allowed.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Discourse

  1. In the admin sidebar open Appearance → Themes and components. Older versions use Admin → Customize → Themes.
  2. On the Components tab click Install, choose Create new, name it "OnyxMetric Analytics", make sure the type is Component, and click Create.
  3. Click Edit CSS/HTML, stay on the Common tab, and open the </head> section. Do not use Header, which is the visible page header.
  4. Paste the snippet and click Save.
  5. 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, so topics and categories open without a full reload. The tracker follows those URL changes automatically.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Troubleshooting

  • Component saved but script missing from the source: the component is not attached to the active theme. Add the theme under Include component on these themes.
  • Tag present but blocked: check the browser console for a CSP error. Scripts added through the </head> section receive Discourse's nonce automatically, while scripts injected any other way may be blocked.

Next steps

On this page