Find pages that use certain macros/plugins
Asked by Stephan Haslinger:

Hi,

does anyone know a nice way to search Confluence for pages that use a given macro?

This would help to see which plugins are widely used or who is using certain plugins.

We could use this information to contact the plugin users directly or to see which plugins are no longer required and could be removed.

Regards,

Stephan


Answers:
author: SarahA
body: For people who don't have access to the database, here's how to do it in Confluence 4.0 and above:

<http://ffeathers.wordpress.com/2011/11/04/how-to-search-confluence-for-usage-of-a-macro/>

In a nutshell: In a nutshell: Enter the following in the Confluence search box, assuming that your macro name is "x":
> macroName: x\*

The above works in out-of-the-box Confluence (no plugins required). If you install a plugin, you can also search for specific parameters and parameter values. See <http://ffeathers.wordpress.com/2012/09/04/how-to-search-for-macros-and-macro-parameters-in-confluence-4/>

I hope this helps!

Cheers, Sarah

comments: author: Andre van der Elst
body: I tried that, but I always get this response: "Did you mean: mucronate:sql\*"

when searching for macroName:sql\* (tried with or without a space after : )


author: SarahA
body: Hallo Andre

Which version of Confluence are you using? The "macroName" search field is available in Confluence 4.0 and later.

In Confluence 3.5 and earlier, you can enter the curly brackets and the macro name surrounded by double quotation marks, like this:
> "{sql"

More details in this post: <http://ffeathers.wordpress.com/2011/11/04/how-to-search-confluence-for-usage-of-a-macro/>

Cheers, Sarah


author: Gavin Fowler
body: I believe it's cace sensative i.e. it has to be "macroName: SearchString\*"


author: Karie Kelly
body: This worked perfectly for us! We had migrated to Confluence 5.0 (we were on OnDemand). The JIRA macro could not be converted correctly. This saved us a ton of time by locating the pages and making the updates manually -- we had started down the path of reviewing every page for the problem until we came across this. Thanks!!!!


author: Brian K
body: yeah, this is great!


author: Jorge
body: Great answer Sarah. What if I can't fined the exact macro name to use in the search? For example we're using the Customware Visibility plugin. But when i search for 'macroName:show-if' the result is 0, and i know that it's used. Any tips?


author: Laura Witty
body: It does show "did you mean.." etc, but it still presents the results for what you asked for.


author: Derek Broughton
body: When I use that search, for either **macroName:sql\*** or**macroName:sql-query** , I get exactly one result, even though I have dozens of pages using this macro. It only seems to find the *outer* macro, and almost all of my **sql-query** macros are wrapped in a **run** query.


author: Bernd Schneider
body: Hm. For me it seems to work sometimes, sometimes not. I can also find macroName: excerpt-include\*. But searching for the "Page properties" macro doesn't work. Can the blank in the macro name be the problem?

I tried:

macroName: page\*  
macroName: page properties  
macroName: "Page properties"  
...

I found pages, but that seems to be not connected to what I search.


author: Bernd Schneider
body: I found out, how to get the macro names. If you want to find it you have to look at the page in storage format (... menu of the page). There you can see the real names by searching (Ctrl-f) for "ac:structured-macro ac:name".

Then you find that the page properties macro has the "intuitive" name "details".

Another successful Atlassian way to impede their users by hiding information. Of course none of them every will read these community issues and improve anything. They just sit and count their money.


author: Jason Hensler
body: I was using the usage macro in the confluence 4.0. it installs and runs but, has always been slow and causes the server to hang up while running. What we have since done is borrowed and tweaked the sql it was running, and run it directly against the sql server. The code will check in pages and blogpost where the content is the current version and not deleted. I will return a contentid, page title, the space id, the creator, and when it was modified. We use the following code:

```
Select CONTENT.CONTENTID, Title, SpaceID, CREATOR, LASTMODDATEfrom CONTENT, BODYCONTENTWHERE PREVVER IS NULL AND (CONTENTTYPE = 'PAGE' OR CONTENTTYPE = 'BLOGPOST') AND CONTENT.CONTENTID = BODYCONTENT.CONTENTID AND CONTENT_STATUS = 'current'AND (BODY like '%{macro%')
```

Opps that code works for un converted macros in confluence 4.

For converted macros replace the last line with

AND (BODY like '%\<ac:macro ac:name="MACRO"\>%')

You can go straight to a page by using this link and replacing CONTENTID with the returned contentid from the sql results https://confluence-install/pages/viewpage.action?pageId=CONTENTID

comments: author: Jason Hensler
body: Change "CONTENTID" to "CONTENT.CONTENTID"


author: Gavin Fowler
body: works perfectly Jason - many thanks for the advice!

```
Select CONTENT.CONTENTID, CONTENT.Title, CONTENT.SpaceID, CREATOR, LASTMODDATEfrom CONTENT, BODYCONTENTWHEREPREVVER IS NULLAND (CONTENT.CONTENTTYPE = 'PAGE' OR CONTENT.CONTENTTYPE = 'BLOGPOST')AND CONTENT.CONTENTID = BODYCONTENT.CONTENTIDAND CONTENT.CONTENT_STATUS = 'current'AND (BODYCONTENT.BODY like '%{cache%')
```


author: Gavin Fowler
body: I'm running confluence 4.2.x and this works for me:

```
Select CONTENT.CONTENTID, CONTENT.Title, CONTENT.SpaceID, CREATOR, LASTMODDATEfrom CONTENT, BODYCONTENTWHEREPREVVER IS NULLAND (CONTENT.CONTENTTYPE = 'PAGE' OR CONTENT.CONTENTTYPE = 'BLOGPOST')AND CONTENT.CONTENTID = BODYCONTENT.CONTENTIDAND CONTENT.CONTENT_STATUS = 'current'AND (BODYCONTENT.BODY like '%{cache%')
```

EDIT: Andre beat me to it :)


author: Andre van der Elst
body: I tried running this (on mysql 5.0.95):

```
Select CONTENTID, Title, SpaceID, CREATOR, LASTMODDATEfrom CONTENT, BODYCONTENTWHEREPREVVER IS NULLAND (CONTENTTYPE = 'PAGE' OR CONTENTTYPE = 'BLOGPOST') AND CONTENT.CONTENTID = BODYCONTENT.CONTENTID AND CONTENT_STATUS = 'current'AND (BODY like '%&lt;ac:macro ac:name="MACRO"&gt;%')
```

but then I get a 'ERROR 1052 (23000): Column 'CONTENTID' in field list is ambiguous' message from mysql.


author: Andre van der Elst
body: FYI, this is on Confluence 4.3


author: John Price
body: Jason's SQL is the method to use when looking for a macro that is not working. For example, Graphviz recently became commercial and our existing pages using it now fail.

```
macroName:flowchart
```

does not work but the SQL method does. We needed it to answer the question: How many pages were using this plugin and should we buy it?


author: GBE
body: On recent version of confluence (5.10+), it seems there is the usage of each macro, grouped by plugin, listed on this admin page:  
https://%confluence%/admin/pluginusage.action

The SQL queries were good, but they also returned some false positive (ex. if the macro name is used as a parameter of another macro, you will get a match on this page).

Gilles

cf. <https://confluence.atlassian.com/confkb/how-to-get-a-list-of-the-most-popular-macros-used-in-confluence-353764197.html>

comments: author: Lorenzo Babbage
body: Very helpful!


author: A
body: best answer for current versions


author: Ed Kershenbaum
body: Thanks! Works great in Cloud Confluence as well!

<https://YourNameGoesHere.atlassian.net/wiki/admin/pluginusage.action>


author: Nilesh Raut
body: Thanks! This is helpful.


author: Omri Peretz
body: This is gold

[https://YourNameGoesHere.atlassian.net/wiki/admin/pluginusage.action](https://yournamegoeshere.atlassian.net/wiki/admin/pluginusage.action)


author: Sugandha Sahay
body: Saved me a ton of time, thanks!


author: Bernd Schneider
body: But for us it is impossible that all have to become admins to see this. We need a possibility to find the used macros as normal users.


author: Sandro Herrmann [Communardo]
body: We wrote a little user macro for this requirement to create an overview page. Please use this macro only for Confluence version 3.5.x and older. Futhermore the performance of that macro iss very bad. Use is with care.

```
## @param macroname:title=Macro Name|type=string #set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))#set($containerManager=$getInstanceMethod.invoke(null,null))#set($containerContext=$containerManager.containerContext)   ## the pageManager gives you access to the pages#set($pageManager =$containerContext.getComponent('pageManager'))  ## the spaceManager gives you access to the spaces#set($spaceManager =$containerContext.getComponent('spaceManager')) #set($macroNameSplit = $parammacroname.split(",") ) #foreach( $space in $spaceManager.getAllSpaces() )        <ul>    #foreach( $page in $pageManager.getPages( $space, true) )           #foreach( $macroName in $macroNameSplit )               #if( $page.content.contains("{$macroName" ) )               <li><a href="$req.contextPath$page.urlPath">$space.key:$page.title  &rarr; $macroName</a></li>            #end        #end    #end    </ul>#end
```


author: hsuhailah
body: If you're using Confluence 3.5.x and earlier, you can try out [Usage Stats Macro](https://marketplace.atlassian.com/plugins/com.comalatech.macrostats)

comments: author: Stephan Haslinger
body: Hanis,

thank you for the fast answer. I am about to upgrade from 3.5.x (right now). I have saved the list :)

Is there any way to do that with Confluence 4.x?

Regards,

Stephan


author: Gavin Fowler
body: I'd also be interested in how to do this in confluence 4.x installation - a number of macros/plug-in I've used in the past have gone commercial and I'm being asked how widely they are being used in order to justify the purchase. Any 4.x suggestions woudl be most welcome.


author: Matthew J. Horn
body: Here's a macro that gets all macros used on all pages in a space. You can modify it to suit your needs (such as replacing the macroNames list with a single macro.

```
## 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<h3>Macro names</h3><hr/>#foreach($name in $macroNames)  $name, #end## 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>
```

comments: author: Nari Man
body: Matthew

How do I use this please?


author: Nari Man
body: I added this Macro to user Macros and then created a page with this macro added in. I still do not get the list of Macros used on the space. Any ideas? I am using COnfluence 5.1.1


author: David Hergert _PAYX_
body: This is nice, but it should be clear, this only is for user macros.


author: Luis Plaza
body: // then name of the app from $macro.getPluginKey()

...

function lookPlugin(pluginkey){  

var html = '';  
var searchURL = '';  
AJS.$('#queryStatus span').text('Buscando plugin: ' + pluginkey);

searchURL = AJS.params.baseUrl + '/rest/plugins/1.0/' + pluginkey + '-key';

var nombrePlugin= 'hola';

AJS.${d}.ajax(  
{  
type: 'GET',  
url: searchURL,  
async: false,  
dataType: "json",  
timeout:60000,  
success: function(data) {  

nombrePlugin=data.name + '(' + data.version+ ')';

},  
error: function (x, y, z) {  
nombrePlugin= 'Other:' +pluginkey;  
}  
}  
);  

return nombrePlugin;  

}


author: Mick Davidson
body: Using:

macroName: Table-of-Contents\*

or any variation of this name/format doesn't find the TOC macro. It works perfectly well on single words, but not at all on multi-worded titles.

We're using 4.3.7. Cheers.

comments: author: Karie Kelly
body: In the latest Confluence upgrades, you can no longer search macroName:JIRA Issues - it only locates those pages that have JIRA Issue

I submitted a support ticket and was told that this wasn't a bug as this was an unintended release of a feature. So, since it was not intended to be released, any issues are not bugs.


author: Mick Davidson
body: I've just tried this again in 5.4.3 Download and it still works in the way I've described above.

So: macroName: Code-Block\* - doesn't find the macro (though it does find other things).

However: macroName: code\* - finds all pages using the Code Block macro.

Cheers.


author: Mick Davidson
body: More info on this.

When I started searching it was from the global search field. However, I've also tried this in specific spaces AND in sets of sub-pages that use the Page Tree Search macro.

This means you can run the search on a very specific set of pages. HTHs.

Cheers.


author: Pat Pigatti
body: Hi,

Any idea when this will be supported again in a latest version of Confluence? Is there a feature request already on this? Thanks. Pat

comments: author: Mick Davidson
body: Pat,

See my comments above, are they helpful?

Cheers.


author: Pat Pigatti
body: Hi Mikc,Kind of helps. Here's our scenario we are looking for a resolution or workaround if you know of one. If someone leaves the company, we'd like to be able to find references to them as used in macros such as the user-profile macro, so we can clean things up on pages. We have a work instruction for doing that, but the work instruction steps don't work anymore: we used to be able to do that with wiki markup but not in the new HTML5 format of Confluence. Any ideas?Thanks,Pat


author: Mick Davidson
body: Well that's not very helpful is it?


author: Daniel Zimmerman
body: Hello,

Most of these searches seem to be for searching the entire confluence wiki for a macro. What I would like is when editing a page, I would like to jump to the next instance of the macro while I am editing the page. Kind of like CTRL+F but instead of searching for text, search for a macro.

I have tried inserting macroName: Note\* into the "Find" field when pressing CTRL+F but it did not seem to work. Any suggestions?


author: Andre van der Elst
body: bingo!

Gavin's query works!

Thanks to all for the help!


Tags: confluence-app

macro

search