It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I show statistics on labels used in Confluence?

We are looking at storing system information in Confluence, and the idea is to use labels as a way to "classify" the systems in various ways. Now, we would also like to be able to have some kind of dashboard where we could show statistics on the various labels. Pie/bar charts etc.

Is that something that can be done...? The 'Chart' macro is simply manual, and 'Popular Labels' can only show a tag cloud or list, no graphs. Haven't been able to find anything in the googleverse or Marketplace so far, so any tips, tricks and suggestions are welcome...

2 answers

If you want to create a graph based on the number of content that has a certain label, then the best way to go would be to use the included chart macro and use this user macro to generate the label count:

## @param Label:title=Label|type=string|required=true|desc=Please enter a label to count
#set ( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set ( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set ( $containerManager=$getInstanceMethod.invoke(null,null) )
#set ( $containerContext=$containerManager.containerContext )
#set ( $labelManager = $containerContext.getComponent('labelManager') )
#set ( $requestedLabel = $labelManager.getLabel($paramLabel) )
#if ( $requestedLabel )
$labelManager.getContentCount($requestedLabel)
#else
0
#end

Then just put this macro in the table cell of the chart macro where you would normally put a number.

Thanks! I'll take this for a spin and see what I can get done.

Is it possible to limit the number of labels to one space?

After testing this macro, we were getting higher label counts than expected. It turns out there are three possible states for a content object (Current, Deleted, and Draft). We had a developer of ours update the macro to only include "Current" pages. Here is the updated macro:

 

## @Param Label:title=Label|type=string|required=true|desc=Please enter a label to count
#set ( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set ( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set ( $containerManager=$getInstanceMethod.invoke(null,null) )
#set ( $containerContext=$containerManager.containerContext )
#set ( $labelManager = $containerContext.getComponent('labelManager') )
#set ( $requestedLabel = $labelManager.getLabel($paramLabel) )
#set ($allContent = $labelManager.getAllContentForLabel(0,500,$requestedLabel) )
##Count: $allContent.getCount() <br>

#set ($listContent = $allContent.getList() )

#set ($tmpCount = 0)
#foreach ($theContent in $listContent)
## $tmpCount | $theContent.getDisplayTitle() <br>

#if ($theContent.isCurrent() )
#set ($tmpCount = $tmpCount +1)
#end

#end
$tmpCount

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

3,933 views 15 38
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you