Add Plausible Analytics tracking to Discourse

To add support for Plausible Analytics to your Discourse instance

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>

Next, you do need to make a modification for this to work with Discourse’s single-page Ember app.

  • Change plausible.js to plausible.hash.js.

The final result should look like this:

<script async defer data-domain="community.example.com" src="https://plausible.example.com/js/plausible.hash.js"></script>

Finally, create a new theme component from Admin > Customize > Themes. Then paste the modified 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!

16 Likes

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…?

2 Likes

You need a theme-component for that.

3 Likes