Adding the Fathom script to your Discourse Site
This guide walks you through adding your Fathom script to your Discourse site so you can start seeing privacy-first analytics for your community.
Step 1: Get your Fathom Script
Log in to your Fathom account
Go to Settings → Sites, then choose your site or create one if you haven’t already
Click on the Install tab, then copy the script
It’ll look something like this:
Note: If you’re copying the below example script (or any of the other example scripts on this page), make sure to replace the dummy Site ID with your own Site ID. It can be found in your site settings.
<script src="https://cdn.usefathom.com/script.js" data-site="YOUR-SITE-ID" defer></script>
Step 2: Ignore canonicals
Because Discourse comes with a canonical link to your homepage, baked into the default/core setup, you’ve got to tell your Fathom script to ignore canonicals by adding data-canonical="false" to your script.
Here’s an example script with that added:
<script src="https://cdn.usefathom.com/script.js" data-site="YOUR-SITE-ID" data-canonical="false" defer></script>
This will then show unique URLs within your Discourse site, not just your homepage.
Step 3: Enable SPA tracking
Discourse is a single-page app (SPA), which means it dynamically loads new content without reloading the page. To handle that, you have to enable SPA mode via your Fathom script by adding data-spa="auto", like so:
<script src="https://cdn.usefathom.com/script.js" data-site="YOUR-SITE-ID" data-canonical="false" data-spa="auto" defer></script>
Step 4: Add the Fathom Script to your Discourse theme
You’ll be embedding the Fathom script into your site’s
by editing your Discourse theme. Here’s the easiest and cleanest method:
- Go to your Discourse Admin Panel
- Navigate to Customize → Themes
- Choose the theme you’re using
- Click Edit CSS/HTML
- Switch to the
<head> tab
- Paste your Fathom script at the bottom
- Click Save
Step 5: Test your setup
- Open your Discourse forum in another window
- Visit your Fathom dashboard
- You should start seeing real-time page views
Note: If you’re not seeing any data appear in your dashboard, ensure that you have any ad-blockers or VPN’s you’re using temporarily disabled, as they may be blocking the Fathom script.
Further customization
To learn about all the options we offer, read our advanced documentation here.