# Adding statcounter code

**URL:** https://meta.discourse.org/t/adding-statcounter-code/137326
**Category:** Support
**Created:** [December 29, 2019, 9:14pm UTC](https://meta.discourse.org/t/adding-statcounter-code/137326 "2019-12-29T21:14:27Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [December 29, 2020, 5:54pm UTC](https://meta.discourse.org/t/adding-statcounter-code/137326/7 "2020-12-29T17:54:44Z")

</div>

> [@absi](#):
>
> Anyone know how I can add it?

You add that code in the `</head>` section of a theme component. You can read more about that [here](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966).

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](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](https://meta.discourse.org/t/theme-modifiers-a-brief-introduction/150605) or in your [site settings](https://meta.discourse.org/t/mitigate-xss-attacks-with-content-security-policy/104243).

---

_[View the full topic](https://meta.discourse.org/t/adding-statcounter-code/137326)._
