Confluence with Google Analytics shows way to many users?
Asked by Timothy Harris:

I have set up google analytics on Confluence. Pasted the script at the end of head in custom html.

The instance only has about 160 users. It is showing 9000 plus users. This is first time I set up google analytics.

Has anyone else done this and would you have an idea as to why the user count is so wrong?


Answers:
author: David Simpson v4.0
body: Hi Timothy

I'd recommend the approach described in this blogpost:  
[Tracking Atlassian Confluence usage with Google Analytics](https://davidsimpson.me/2009/03/18/tracking-atlassian-confluence-usage-with-google-analytics/#update2014-08-14)

How have you recorded 9000 users? Is it from within the Google Analytics interface?

Is the Confluence instance publicly available? If that's the case, you may be suffering from a problem with bots and spiders. This is easily fixed. Here's a good description of the problem and how to prevent it: [Understanding Bot and Spider Filtering from Google Analytics](http://www.lunametrics.com/blog/2014/08/07/bot-spider-filtering-google-analytics/).

If you need further help, [get in touch](https://davidsimpson.me/contact-me/) :wink:

Best wishes, David.

*** ** * ** ***

**Aside:** The [Google Analytics for Confluence](https://www.appfusions.com/display/GANLC/Home) add-on helps with the setup, displays analytics in context \& also automatically removes traffic from bots \& spiders.

*** ** * ** ***

**Update:**

If you only want to track logged in users, you can check to see if they are logged in using javascript and only then add the Google Analytics tracking code. e.g.

```
&lt;script&gt;  // Standard Google Universal Analytics code  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');    AJS.toInit(function(){    // check for a logged in user    if (AJS.params.remoteUser !== '') {      ga('create', 'UA-XXXX-Y', 'auto'); // add your GA tracking code here       // Add a page-level custom variable to record the space-key      if (typeof AJS.params.spaceKey === 'string') {        ga('set', 'dimension1', AJS.params.spaceKey); // Set a `spaceKey` dimension at page level      }      ga('send', 'pageview');    }  });?&lt;/acript&gt;
```

Don't mess with the Google Analytics base url. Keep to the root URL e.g. <https://confluence.my.com/>

comments: author: Timothy Harris
body: Yes the data is from the google analytic interface and it is also a public instance.I really only want to track data for logged in users. Whenever a user enters the base url in his browser he is redirected to a login page or a dashboard if he is already logged in. I only want to track from the dashboard. Can I just create a view with the dashboard as base url like <https://myconfluence.my.com/dashboard.action>?Will this only track hits on this page or will it then track users as they browse to the other content on the confluence site? Pretty new to google analytics if you haven't guessed :-)


author: David Simpson v4.0
body: See the update above.