The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Usage Stats on User Macros

Binaya
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 3, 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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
September 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
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
November 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>

0 votes
Julio Mugabe
Contributor
March 10, 2013

Same here, a solution will be greatly appreciated.

0 votes
Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
June 13, 2012

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events