Confluence analytics, individual space stats & Piwik
Asked by Andrei [errno]:

I would like to colect user access statistics and Piwik (<http://piwik.org>) seems to do it well.

Howevwer - I have a Q on what would be the best approach/setup for tracking individual space stats.

* my url: example.com/confluence/display/TEAMSPACE
* some TEAMs would like to have stats of their own spaces
* i'd like to collect global stats as well

should I go with

* 1 global javascript blob in "custom HTML" - for global stats
* define new sites in Piwik per space and insert their unique javascript blobs into respective spaces (Documentation theme)?
* or rather use "Goals" in Piwik to track visits for urls containing "/confluence/display/MYTEAM"

I am loooking for a combination of a performance/ease of use/flexibility features.

thanks in advance

<br />

related questions:

* [https://answers.atlassian.com/questions/10736/looking-for-user-access-statistics](/questions/10736/looking-for-user-access-statistics)
* [https://answers.atlassian.com/questions/21953/google-analytics-with-evaluation-instance-of-confluence-4-0](/questions/21953/google-analytics-with-evaluation-instance-of-confluence-4-0)

[](https://community.atlassian.com/t5/Confluence-questions/Confluence-analytics-individual-space-stats-Piwik/qaq-p/335497?attachment-id=7291){#link_118dce3f855efd}  
[](/tnckb94959/attachments/tnckb94959/confluence-questions/56695/1/piwik1.PNG){#display_118dce3f855efd_0}


Answers:
author: David at David Simpson Apps
body: Adding custom JavaScript to each space individually sounds like madness. Use the same "blob" throughout (yes, put it in the **Custom HTML** section), but use some kind of custom variables to differentiate the individual spaces.

This means that you can view analytics site-wide, but also just for individual spaces.

Here's how we do things for the [Webtrends](https://plugins.atlassian.com/plugin/details/39438) and [Google Analytics](https://plugins.atlassian.com/plugin/details/16722) plugins:

```
if (typeof AJS.params.spaceKey == 'string'){	// Webtrends 	dcsMultiTrack('DCSext.w_space_key', AJS.params.spaceKey);		// Google Analytics	_gaq.push(['_setCustomVar',		1,                       // This custom var is set to slot #1 of 5		'confluence-space-key',  // The name acts as a kind of category for the activity		AJS.params.spaceKey,     // This value of the custom variable		3                        // Sets the scope to page-level	]);}
```

Once this is set up, you'd need to construct a custom report to filter on the **w_space_key** custom dimension (Webtrends) or **confluence-space-key** custom variable (Google Analytics)

Looking at the [Piwik wiki](http://piwik.org/docs/javascript-tracking/#toc-custom-variables) it seems that the JavaScript is almost directly lifted from the pre-async Google Analytics days:

```
piwikTracker.setCustomVariable(1, 'confluence-space-key', AJS.params.spaceKey, 'page');
```

You just need to build the custom reports :)

-- Hope this helps, David

P.S. I'm also curious why you want to use Piwik over Google Analytics.

P.P.S. If you need further help, [AppFusions](http://www.appfusions.com/) have expertise in integrating Confluence with solutions from various web analytics vendors.

comments: author: Andrei [errno]
body: we run CONF in an enterprise environment and dealing with IT Security department questioning "why do we send data to GOOG" would be too risky, i guess :)


author: David at David Simpson Apps
body: @webwesen: How did this go? Was it helpful? If so, give it an up-vote/mark as correct ;-)


author: Sean King
body: You wouldn't happen to have screenshots on what that filter would look like in Google Analytics would you? I'm having trouble creating the Custom Report.


author: Eric Hammes
body: I had a similar need to track Confluence with Piwik, including custom variables. We inserted the following code into Confluence's head (see [Confluence how to article](https://confluence.atlassian.com/display/CONFKB/How+to+Use+JavaScript+in+Confluence)):

```
&lt;!-- Piwik --&gt;&lt;script type="text/javascript"&gt;	//https://confluence.atlassian.com/display/CONFKB/How+to+Use+JavaScript+in+Confluence	var _paq = _paq || [];	AJS.toInit(function(){   		var u = (("https:" == document.location.protocol) ? "https://&lt;&lt;INSERT YOUR PIWIK URL HERE&gt;&gt;" : "http://&lt;&lt;AND HERE&gt;&gt;");		_paq.push(['setSiteId', &lt;&lt;INSERT YOUR ID HERE&gt;&gt;&gt;]);		_paq.push(['setTrackerUrl', u+'piwik.php']);		_paq.push(['setCustomVariable', 1, "Space", AJS.params.spaceKey, "visit"]);		_paq.push(['setCustomVariable', 2, "NTid", AJS.params.remoteUser, "visit"]);		_paq.push(['setCustomVariable', 3, "User", AJS.params.currentUserFullname, "visit"]);		_paq.push(['enableLinkTracking']);		_paq.push(['trackPageView']);		var d = document, 			g = d.createElement('script'), 			s = d.getElementsByTagName('script')[0];         		g.type = 'text/javascript'; 		g.defer = true; 		g.async = true; 		g.src = u + 'piwik.js';		s.parentNode.insertBefore(g,s); 	})();&lt;/script&gt;&lt;!-- End Piwik Code || Edited 1/9/2015, working with version 5.3.4 of confluence--&gt;
```

comments: author: santhosh Devadiga
body: I added bellow code in my javascript function but unique visitors count of custom variables is showing blank in piwik.!\[piwik1\](<https://cloud.githubusercontent.com/assets/5286315/11184714/24f1520c-8c9f-11e5-8468-2c73928c6ebd.PNG>) var u=(("https:" == document.location.protocol) ? "https" : "http") + "://"+paq_url+"/"; _paq.push(\['setTrackerUrl', u+'piwik.php'\]); _paq.push(\['setSiteId', paq_site_id\]); _paq.push(\['setUserId', userId\]); _paq.push(\['setCustomVariable', '3','Full Text Search User Types',userType,'visit'\]); _paq.push(\['trackPageView'\]); _paq.push(\['trackSiteSearch',keyword,category,searchCount\]);I am using piwik 2.15.0 , Please help me


Tags: analytics

piwik