Usage Stats on User Macros

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

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.

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

Same here, a solution will be greatly appreciated.

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Tuesday in Uncategorized

Friday fun: how many celebrates Midsummer holiday or is this a Swedish tradition only?

Any other country that celebrates Midsummer holiday (this friday 22 June)?  

44 views 3 1
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you