# 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:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![absi](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@absi](https://meta.discourse.org/u/absi)
#### Post date: [December 29, 2019, 9:14pm UTC](https://meta.discourse.org/t/adding-statcounter-code/137326/1 "2019-12-29T21:14:27Z")

</div>

I added my statcounter code but it appears to not work. Anyone know how to solve this?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 30, 2019, 11:30am UTC](https://meta.discourse.org/t/adding-statcounter-code/137326/2 "2019-12-30T11:30:45Z")

</div>

No. No one can possibly help answer that question.

If you world like to answer a question that has an answer it should include the following: What did you do? What code did you add. Where did you add it? What happens when you try to run it? What do you do to try to run it? What did you expect to happen?

---

<div class="post-metadata">

### Author: ![absi](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@absi](https://meta.discourse.org/u/absi)
#### Post date: [December 30, 2019, 4:17pm UTC](https://meta.discourse.org/t/adding-statcounter-code/137326/3 "2019-12-30T16:17:51Z")

</div>

Let me rephrase: Has anyone got statcounter code working and tracking visitors on their discourse community?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [December 30, 2019, 7:46pm UTC](https://meta.discourse.org/t/adding-statcounter-code/137326/4 "2019-12-30T19:46:51Z")

</div>

Discourse comes out of the box with a dashboard and reports for various statistics. I believe many also have Google stats.

---

<div class="post-metadata">

### Author: ![absi](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@absi](https://meta.discourse.org/u/absi)
#### Post date: [December 30, 2019, 8:13pm UTC](https://meta.discourse.org/t/adding-statcounter-code/137326/5 "2019-12-30T20:13:27Z")

</div>

I see that. But not what I am looking for.

---

<div class="post-metadata">

### Author: ![absi](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@absi](https://meta.discourse.org/u/absi)
#### Post date: [December 29, 2020, 4:47pm UTC](https://meta.discourse.org/t/adding-statcounter-code/137326/6 "2020-12-29T16:47:28Z")

</div>

Still trying to get this to work.

This is the code:

 ![image](https://global.discourse-cdn.com/meta/original/3X/f/9/f997f3f7062dceaca4a8247976bdd7eb6bbefcd1.png)

Anyone know how I can add it?

---

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