Skip to main content
Level 4
Oct 23, 2026 9:02 AM UTC
Solved

Can we get the basic statistic from a page on AEM 6.5 using a custom code?

Hi,

We have a requirement to fetch the basic statistics from a page on AEM 6.5 (On Prem)

We have a page (on AEM publisher) where we display some forms (XDP ones) and onclick renders the PDF version.

On this page, we need to get the statistics like when the user clicks on the form , we need to capture how many times a form is being clicked. Unfortunately we cannot use Adobe Analytics, and we need to write a custom code for it, is this something feasible using custom code, if yes, can you suggest a good approach for this. Thank you.

 

shrutid56001193
shrutid56001193Accepted solution
User Group Leader
Oct 26, 2026 7:38 AM UTC

hi ​@SmrithiGo 

Yes, this is definitely doable. One thing to avoid is writing a click counter into the JCR on publish. With several publishers you end up with separate counts per instance.

Here are three ways I would approach it, from simplest to most complete:

  1. Use your access logs. If each form opens its PDF through its own URL, every click is already in your Apache/dispatcher access logs, even for cached responses. I would count those per form with whatever log tooling you have (ELK, Splunk, etc). No AEM code is needed at all.

  2. Small tracking endpoint on publish. If the PDF URL doesn't tell you which form was clicked, I would add a bit of JavaScript that sends a lightweight notification with the form ID to a simple servlet. The servlet writes it to a dedicated log file or somewhere you prefer. Remember to allow the path in the dispatcher filters, keep it out of the cache, and validate the input.

  3. Self-hosted analytics. If you can run something on-prem, I would look at Matomo or a similar open-source tool. Click events are built in, and you get dashboards and exports for free. If "just count clicks" is likely to grow into real reporting later, this is the one I would pick.

Whichever you choose, I would check with your GDPR team if you plan to store anything beyond the form ID and a timestamp.

Hope this helps!

https://www.shrutidamle.com/

5 replies

shrutid56001193
User Group Leader
shrutid56001193User Group LeaderAccepted solution
User Group Leader
Oct 26, 2026 7:38 AM UTC

hi ​@SmrithiGo 

Yes, this is definitely doable. One thing to avoid is writing a click counter into the JCR on publish. With several publishers you end up with separate counts per instance.

Here are three ways I would approach it, from simplest to most complete:

  1. Use your access logs. If each form opens its PDF through its own URL, every click is already in your Apache/dispatcher access logs, even for cached responses. I would count those per form with whatever log tooling you have (ELK, Splunk, etc). No AEM code is needed at all.

  2. Small tracking endpoint on publish. If the PDF URL doesn't tell you which form was clicked, I would add a bit of JavaScript that sends a lightweight notification with the form ID to a simple servlet. The servlet writes it to a dedicated log file or somewhere you prefer. Remember to allow the path in the dispatcher filters, keep it out of the cache, and validate the input.

  3. Self-hosted analytics. If you can run something on-prem, I would look at Matomo or a similar open-source tool. Click events are built in, and you get dashboards and exports for free. If "just count clicks" is likely to grow into real reporting later, this is the one I would pick.

Whichever you choose, I would check with your GDPR team if you plan to store anything beyond the form ID and a timestamp.

Hope this helps!

Translate
https://www.shrutidamle.com/
SmrithiGoAuthor
Level 4
Oct 26, 2026 8:26 AM UTC

Thank you ​@shrutid56001193 , for the detailed response.

We are thinking of both Matomo and custom code approaches. 

Due to certain issue, i think we will not be able to proceed with Matomo, so the only possible option is a custom code. I believe your option 1 is  something that I can try out. Just wondering without any log tooling is it feasible to capture this statistics from the logs. Thank you . 

Translate
shrutid56001193
User Group Leader
User Group Leader
Oct 26, 2026 8:46 AM UTC

​@SmrithiGo Yes, it's feasible without any log tooling. Access logs are plain text files, so you can count from them directly.

  • Find the pattern first: Open the dispatcher/Apache access log, click a form, and look at the line it creates. You need a part of the URL that identifies the form, such as the form name in the path or a query parameter.
  • Count with standard command-line tools: On Linux, cmds such as grep, awk, sort etc can filter the lines for the PDF render URL and count them per form. On Windows, PowerShell can do the same, or you can import the log into Excel and filter.
  • Only count real clicks: keep successful GET requests (status 200) and filter out bots and crawlers by user agent. Otherwise the numbers get inflated quickly.
  • log rotation: your sysadmins might have log rotation rules set, so remember to include the older files too.
  • Combine all dispatchers: If you have more than one web server, collect the logs from each before counting.
  • Automate it: Once you figure it out, it can be put in a small script that runs daily via cron job. 

Hope this helps!

Translate
https://www.shrutidamle.com/
SmrithiGoAuthor
Level 4
Oct 26, 2026 8:47 AM UTC

thanks a lot ​@shrutid56001193 :)

Translate
shrutid56001193
User Group Leader
User Group Leader
Oct 26, 2026 8:56 AM UTC

you are welcome! if you think my answer was useful, you can mark it as “solved” so it will be other user, having similar question.

Translate
https://www.shrutidamle.com/