Is there a macro which highlights on which pages a user macro is in use in Confluence?
Asked by Rumceisz:

Hi All,

I would like to get a list which display on which pages a user macro is in use in Confluence. Is there a such macro or feature?

Thanks for your help!

Rumi


Answers:
author: HuseinA
body: There are two plugins you could use for to achieve what you're after:

* [Macro Usage](https://marketplace.atlassian.com/plugins/com.atlassian.confluence.plugins.macro-usage) plugin
* [Macro usage stats](https://marketplace.atlassian.com/plugins/com.comalatech.macrostats) plugin

Please note that none of the above plugins are compatible with Confluence 4.x.

comments: author: Rumceisz
body: Thank you!

Is there a user macro maybe, too?


author: Stephen Deutsch
body: Hi Rumi,

if it is a specific user macro you are searching for, you can find it by its name. Simply search for:

macroName: \<macroname\>\*

and replace \<macroname\> with the name of the macro you are searching for. Note that the capitalization, space after the colon, and the star at the end are all necessary.

More information can be found here: <http://ffeathers.wordpress.com/2011/11/04/how-to-search-confluence-for-usage-of-a-macro/>


author: Matthew J. Horn
body: Here's a macro to do it:

```
## 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("demo") )#set ( $allPagesInSpace = $pageManager.getPages($targetSpace, true) )## List all macro names&lt;h3&gt;Macro names&lt;/h3&gt;&lt;hr/&gt;#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&lt;h3&gt;Macro Usage&lt;/h3&gt;&lt;hr/&gt;&lt;table&gt;  &lt;tr&gt;&lt;th&gt;Macro&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;th&gt;Page (isValid) (parameters)&lt;/th&gt;&lt;/tr&gt;  #foreach ($name in $macroNames)     &lt;tr&gt;      &lt;td&gt;$macroMetadataManager.getMacroMetadataByName($name).getTitle().getKey() ($name)&lt;/td&gt;      &lt;td&gt;$macroMetadataManager.getMacroMetadataByName($name).getDescription().getKey()&lt;/td&gt;      &lt;td&gt;      #foreach ($page in $allPagesInSpace)  ## $page is of type Page        #if ($eHelper.getMacroDefinition($page, $name))          &lt;a href="$page.getUrlPath()"&gt;$page.getTitle()&lt;/a&gt; ($eHelper.getMacroDefinition($page, $name).isValid()) ($eHelper.getMacroDefinition($page, $name).getParameters())&lt;br/&gt;                  #end      #end      &lt;/td&gt;    &lt;/tr&gt;  #end&lt;/table&gt;
```

comments: author: Rumceisz
body: Hi Matthew,

thank you very much!

We tried and the Page column is empty. We set 'no macro body' - is it correct?

Rumi


author: Matthew J. Horn
body: The page column will be empty if there are no macros of that type in any of the pages. You're currently using "user macros" in the space that you're searching?


Tags: macro