This discussion provides a guide for integrating Plausible Analytics and Fathom tracking into Discourse. Users share steps to add tracking scripts via theme components, noting that the standard script.js (not hash.js) works better for modern Discourse setups using HTML5 History API. Issues with tracking missing page views are discussed, with resolution found by using the correct script and ensuring the theme is set as default. The guide also addresses Content Security Policy (CSP) concerns, confirming that adding plausible.io or cdn.usefathom.com to CSP is no longer required due to Discourse’s strict-dynamic update. Fathom’s updated guide now reflects these changes, and users confirm the setup works with the recommended scripts. Discourse provides initial instructions, and FathomAsh confirms the updated guide. philh highlights the importance of attaching components to the default theme.
Create a new theme component from Admin > Customize > Themes.
Then paste the tracking code in the </head> section.
Click Save.
Make sure to add this to all available themes so you can track analytics across all users!
That’s it!
If you don’t see data flowing, the script may be blocked by your CSP settings. Check your browser console and if you’re getting errors, add https://plausible.io/js/script.js to your CSP settings.
Updated May 14, 2025 with Fathom’s guide for Discourse
For further info, see Fathom’s guide here:
Note: For both Plausible and Fathom, their scripts work fine in a component attached to your theme(s) and inserted into head of each template you want to track. The new guide from Fathom does not use the “component method”.
According to Plausible’s roadmap on Github it seems that it’s going to be possible sometime in the near future to embed one’s Plausible page into one’s website.
Would something like this be embeddable into Discourse, or might it require a plugin, or…?
Hey @Falco, has anything changed about your frontend routing? I can see you recommend people use the hash version of our script which is provided for hash-based routers. It seems to me like Discourse is using the HTML5 PushState API now, is that correct?
I use plausible and I can confirm that the regular plausible.js does NOT log the urls if a user moves from topic to topic. So if I need accurate representation of my visitors, I have to use the hashed plausible js.
Weird to have these conflicting reports. Theoretically since Discourse uses the HTML5 history API, I would think that our standard script (not the hash script) would be the one that tracks correctly.
Unfortunately I don’t have a discourse instance set up that I could test with.
Probably my lack of knowledge about that I originally went with the hash version due to us being a SPA and having custom tracking for other analytics providers. If plausible.js works, feel free to change it!
Dumb question. Does adding this feature track what’s going on inside your discourse community or does it track outbound traffic to another domain the community is linked to?
Update: The guys at Fathom put together a simple doc to walk you through what you need to do. Enjoy!
Fathom Note: There may be a way to change it, but Discourse adds the rel="canonical" tag for all pages back to the homepage. So all of our page views in Fathom showed as only coming from the homepage.
I talked to Fathom and they said, add this to your tracking script, canonical="false" so it looks as below.