DiscourseにPlausible AnalyticsまたはFathomトラッキングを追加

Plausible Analytics

  • First, add your domain to your Plausible Analytics instance and grab your tracking code. It should look something like this:
<script async defer data-domain="community.example.com" src="https://plausible.example.com/js/plausible.js"></script>
  • 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!

:information_source: 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.


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

Fathom

Please see the Fathom guide for Discourse.

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”.

「いいね!」 27

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.

https://github.com/plausible/analytics/discussions/213

Would something like this be embeddable into Discourse, or might it require a plugin, or…?

「いいね!」 5

You need a theme-component for that.

「いいね!」 6

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?

「いいね!」 3

Not sure why @justin picked the hash version here, since we use HTML5 History API since forever. Made the OP a wiki, so it’s editable by all.

「いいね!」 1

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.

I have same issue with the hashed version though

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 :slight_smile: 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!

「いいね!」 1

Hi @ukutaht

I switched from plausible.hash.js to plausible.js for one of my two discourse sites and this is what happens when I do that.

The site is opened in another tab and it shows no activity at all

Here is my other site with plausible.hash.js which correctly shows 1 online and generally, correct pages are also shown in the top pages widget.

I’m happy to try out any troubleshooting in case it helps eliminate need for the hashed js

「いいね!」 3

Ah yes I recall seeing the same behavior now that you say this – which is why I went with the hashed script route.

「いいね!」 3

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?

What sort of metrics can you find out from this?

「いいね!」 1

I can (in my plausible dashboard) see which links of my discourse forum are being visited and from which country.

「いいね!」 2

Plausible をアナリティクスとして使用する際に、いくつかのバグがあるということですか?

いいえ、問題なく動作するはずです。コミュニティでしばらく使用していますが、問題は発生していません。

「いいね!」 1

OPを編集して、Fathomの使用方法に関する簡単な説明を追加しました。必要に応じて拡張し、さらにテストしてください。

「いいね!」 2

素晴らしいです :smiley:

「いいね!」 2

こんにちは、ガイドをありがとうございます。

Fathom を Discourse に統合したいのですが、Plausible で行ったように hash.js をコードに追加する必要がありますか?

OPに示されているように、それはscript.jsだと思います(**Fathomのサポートを追加するには**まで読んでください)。

「いいね!」 2

更新: Fathom の担当者が、必要な手順を説明する簡単なドキュメントを作成しました。ぜひご覧ください。

Fathom の注意点: 変更する方法があるかもしれませんが、Discourse はすべてのページに対して rel="canonical" タグをホームページに追加します。そのため、Fathom でのページビューはすべてホームページからの流入として表示されていました。

Fathom に問い合わせたところ、トラッキングスクリプトに canonical="false" を追加するようにとのことでした。以下のように表示されます。

<!-- Fathom - beautiful, simple website analytics -->
<script src="https://cdn.domain.com/script.js" data-spa="auto" data-site="ADHGFREZ" data-canonical="false" defer></script>
<!-- / Fathom -->

これで解決しました。

「いいね!」 3