Adding statcounter code

You add that code in the </head> section of a theme component. You can read more about that here.

Discourse is a single page application. So, the implementation might differ from the documentation that Statcounter provided. Your implementation has to account for that; otherwise, you’ll only get the stats for the initial page view.

Here’s an example of how we send stats on page transitions for Google analytics (this is built-in, and it only starts working as soon as you add your Google analytics credentials in the admin settings).

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/app/initializers/page-tracking.js#L29-L37

You’ll also need to make sure that the scripts from Statcounter are (CSP) allowed either via your theme component or in your site settings.

1 Like