Add Plausible Analytics or Fathom tracking to Discourse

Is there something I’m doing wrong here? I added the theme component and applied it to the default theme which I’m using and when I view the source on the forum it shows the script there but I’m still “waiting for first pageview” on plausible. I even tried it with the unmodified default plausible script and still nothing shows.

1 Like

Continuing the above discussion: I had the same issue when using the .hash.js script for Plausible.

No page views were recorded, except somehow on a “hard refresh” with Ctrl/Cmd+F5. Subsequent in-app navigations were not recorded.

I removed the .hash part from the script name, reverting back to the standard script, and then all recording seemed to work perfectly! (I tested this by being a Current Visitor and by seeing all the pages I clicked show up in Plausible)

My context:

  • I’m using the Plausible v1.5 image from DockerHub
  • Discourse v3.1.0.beta2 (47abe61994)
  • Note that I also followed the Content Security Policy instructions that were added to the Discourse entry in the Plausible docs 4 months ago (maybe something you missed @JasonH ?)

Could those for whom the .hash.js script was working also report which versions they use? And if it is still working? @itsbhanusharma @justin

There is probably a reason for why there are conflicting reports on this, understanding the versions connected to reports may be a good start to investigate.

1 Like

It seems to work

<script defer async data-domain="yourforum.co" src="https://stats.yourforum.co/js/plausible.hash.outbound-links.js"></script>

Just echoing @th0rgall above: the current documented process in the OP with the script.hash.js script does not seem to work at all, but using the standard script.js link that Plausible provides does seem to work. @JammyDodger @justin would it be possible to comment about the current state of things? Many OSS projects are interested to migrate of GA right now.

Edit: to note that I have added plausible.io to CSP script src

3 Likes

I have zero previous experience with Plausible, but I’ve just signed up for a free trial to test it out and it Just Worked™ by following the onscreen instructions with no additional changes. :partying_face:

If that’s what other people are seeing too then I’m happy to update the instructions. :+1:

Though if there’s anything else I need to be aware of please shout out. :slight_smile:

(also, I didn’t add it to my CSP and I don’t see any errors in the console?)

1 Like

@JammyDodger is the above success with the plain script.js script? If so, that matches my experience. AFAICT things are working since setting up with script.js a few days ago:

1 Like

I have amended the OP. :+1: If anyone notices anything funky please let me know. :slight_smile:

has anyone been able to make use of custom properties feature in plausible? In my case I would like to add topic category and topic tag to plausible as custom properties so that I can segment the clicks of all categories’ and tags’ topics.

Following the instructions above and the Fathom guide

seems to need an update or maybe I am missing something :slight_smile:

Adding https://cdn.usefathom.com/script.js to “Content security policy script src” generates error and won’t save. Odd thing is Fathom seems to work (mostly) without https://cdn.usefathom.com/script.js in place.

Any suggestions?


Adding the Fathom or Plausible Content security policy script src is no longer required due to update Content-Security-Policy now uses 'strict-dynamic'

Ash @ Fathom reports they will be updated their Discourse doc.

Both Fathom and Plausible are work fine with these added Components:

<script src="https://cdn.usefathom.com/script.js" data-spa="auto" data-site="yourcode" data-canonical="false" defer></script>

<script defer data-domain="YOUR-Domain" src="https://plausible.io/js/script.js"></script>

This may seem obvious but… The components with either Plausible or Fathom scripts apparently won’t work unless attached to a theme set as “default”. I have not tried on a site with multiple themes available but I suspect the analytics components won’t be called without a default theme selected. Seems odd given Discourse otherwise works fine, best I can tell, using the default Discourse theme without declaring it as default.

@Falco Maybe forcing a default selection would be useful.

1 Like

Hey all, Ash from Fathom :waving_hand:

Just jumping in to say @philh is absolutely right — our Discourse setup docs were a bit out of date (you no longer need to add our script src to your CSP). Thanks for letting us know @philh!

We’ve now updated the guide to remove that step and hopefully avoid any future confusion. We’ve also added a step-by-step walkthrough for getting Fathom set up on Discourse, based in part on the helpful info shared in this thread — so thanks for that, too!

You can find the updated guide here:

https://usefathom.com/docs/integrations/discourse

If anyone stumbles across this thread and needs a hand getting set up, feel free to reach out to our support team — we’re always happy to help :slightly_smiling_face:

2 Likes

Should the guide tag be added to this topic so that it is clear that this is not a question but a guide?

1 Like

Updated the OP with new Fathom guide url, thanks @FathomAsh

I agree with @NateDhaliwal Maybe someone with tagging privileges can add guide to the OP