Count number of times component has been used | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by somen-sarkar

Hi @zendarkke ,

OOTB you can check the components page (eg:- http://localhost:4502/libs/wcm/core/content/sites/components.html)  . Upon clicking on the required component it can show the list of pages where the component is used. That can give you an idea of the usage of the component. Groovy script or SQL query can be another way to get the exact count.

 

Thanks,

Somen

3 replies

sherinregi-1
Community Advisor
Community Advisor
August 30, 2024

Hi There are couple of ways you can approach using querybuilder or using groovy scripts to find the list of components and occurrences. 

 

If you want to do it using the query tool you will have to start with basic sql2 query as aggregations wont be supported and deduplicate and build your results .

 

SELECT [sling:resourceType] FROM [nt:unstructured]
WHERE ISDESCENDANTNODE([/content/www/XX/XX/test])
AND [sling:resourceType] IS NOT NULL

 

Also keep in mind the performance aspect and adjust the search nodes appropriately

somen-sarkar
Community Advisor
somen-sarkarCommunity AdvisorAccepted solution
Community Advisor
August 30, 2024

Hi @zendarkke ,

OOTB you can check the components page (eg:- http://localhost:4502/libs/wcm/core/content/sites/components.html)  . Upon clicking on the required component it can show the list of pages where the component is used. That can give you an idea of the usage of the component. Groovy script or SQL query can be another way to get the exact count.

 

Thanks,

Somen

arunpatidar
Community Advisor
Community Advisor
August 30, 2024

Just adding what @somen-sarkar and @sherinregi-1 already suggested, if you are using ACS Common then use Component Report Builder

Arun Patidar
Himanshu_Jain
Community Advisor
Community Advisor
August 30, 2024

Hi @zendarkke ,

Try query to get the count from pages.

Example :

SELECT COUNT(*)
FROM [nt:base] AS root
WHERE ISDEEP TRUE AND root.[jcr:primaryType] = 'nt:unstructured'
AND root.[jcr:content/@sling:resourceType] LIKE '/apps/%'

 

Thanks

Himanshu Jain