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

Usage Stats on User Macros

Binaya May 03, 2012

I am looking to see what "user" written macros have been utilized in the last year to potentially delete user macros that were created but never utilized in confluence. Is there a way to do that?

We have a "Macro Stats" plugin that lists the usage for all the plugins...I am looking to see if a similar one exists for User Macros.

Thanks.

4 answers

1 accepted

0 votes
Answer accepted
Steve Goldberg Sep 17, 2013

One thing you could do is do a search for the user macros to see how many pages they have been used in. This quite simple, see http://ffeathers.wordpress.com/2011/11/04/how-to-search-confluence-for-usage-of-a-macro/ for information.

It's manual work, alas.

0 votes
Adolfo Casari Jun 13, 2012

I have the same requirement, if someone knows an approach please share it.

0 votes
Julio Mugabe Mar 10, 2013

Same here, a solution will be greatly appreciated.

0 votes
Matthew J. Horn Nov 11, 2013

I wrote a macro to iterate over a space's pages and detect macro usage in each space. It works on Confluence 4.2.x. I have not tested it on 3.x or 5.x.

## Macro title: Macro Usage Report
## Developed by: Matthew J. Horn
## Date created: 11/12/13
## This macro takes no parameters
## @noparams

## Get a list of User Macros
#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($macroManager = $containerContext.getComponent('userMacroLibrary'))
#set($macroMetadataManager = $containerContext.getComponent('macroMetadataManager'))
#set($macroNames = $macroManager.getMacroNames())

## Get the ExcerptHelper (probably not supposed to be used for getting all macros, but it works)
#set($eHelper = $containerContext.getComponent('excerptHelper'))

## Get a list of pages in the space
#set ( $targetSpace = $spaceManager.getSpace("admin") )
#set ( $allPagesInSpace = $pageManager.getPages($targetSpace, true) )

## List all macro names
<h3>Macro names</h3>
<hr/>
#foreach($name in $macroNames)
  $name, 
#end

#set($isValid = false)

## Iterate over each page and check if each of the macros in macroNames is used on that page
<h3>Macro Usage</h3>
<hr/>
<table>
  <tr><th>Macro</th><th>Description</th><th>Page (isValid) (parameters)</th></tr>
  #foreach ($name in $macroNames) 
    <tr>
      <td>$macroMetadataManager.getMacroMetadataByName($name).getTitle().getKey() ($name)</td>
      <td>$macroMetadataManager.getMacroMetadataByName($name).getDescription().getKey()</td>
      <td>
      #foreach ($page in $allPagesInSpace)  ## $page is of type Page
        #if ($eHelper.getMacroDefinition($page, $name))
          <a href="$page.getUrlPath()">$page.getTitle()</a> ($eHelper.getMacroDefinition($page, $name).isValid()) ($eHelper.getMacroDefinition($page, $name).getParameters())<br/>          
        #end
      #end
      </td>
    </tr>
  #end
</table>

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Statuspage

⭐️Would you recommend Statuspage? Leave a (honest!) review. ⭐️

Hi Community friends, We're working on sourcing more reviews on Capterra – a popular software review site –  to help teams like yours make more informed decisions when choosing an inc...

63 views 3 5
Join discussion

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