Custom js and newer dhis2

I’m trying to add plausible.io for user/usage analytics (I know dhis2 has a built in analytics but not fitting end user needs)

I noticed that keyCustomJs doesn’t seem injected in the dashboard on newer dhis2.

after several trial (clearing cache,…) I still don’t see the snippet executed.

Do you confirm the new pages/dashboard apps still allow that ?
A quick search doesn’t show usage of it Code search results · GitHub
If it’s no more supported what is the recommended way of doing that kind of things ?
(I’d like to avoid nginx filtering)

Hi @Stephan_Mestach

Thank you for sharing the reference for keyCustomJs - unfortunately the docs need update when it comes to this JavaScript inject setting.

Is this for Dashboard app only? If so then do you think a plugin would work?

If this is global app usage, I think you’re left with these two options (there could be better but these are the ones I could think of):

  • Create a custom app that works like the global shell but you’d insert your script there…
  • Use Nginx which you seem to want to avoid (may I ask why?)

Thanks!

I’m not familiar with the plugins. I read that most of the code is isolated in an iframe so not sure it would allow an analytics script to “listen” to user activity. And Would have thought the plugins are a bit lazily launched, only if a custom component is present in the configuration.

nginx it would endup substituing a bit blindly, my fear would be to match a tag in responses we are not supposed to touch, and breaking Accept-Encoding forward looks bad too.

location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    proxy_set_header Accept-Encoding ""; (prevent tomcat to return gzip content)

    sub_filter '</head>' '<script defer src="https://plausible.io/js/script.js"></script></head>';
    sub_filter_once on;
    sub_filter_types text/html;
}

You’re absolutely right. It would have missed the point.

It’s great that you are cautious and I’d recommend to keep it that way for now until it’s well tested in a development instance. Did you try that configuration with the sub_filter_types? Does plausible also track activity within the apps?

Thanks for sharing!


Aside from the “Usage Analytics app”, this still seems to be an idea being explored:

So I went for the built-in analytics

I would have wanted the number of views per dashboard per week but haven’t found it

  • /api/42/dataStatistics?startDate=2026-04-26&endDate=2026-08-26&interval=WEEK&fields=year,month,week,day,dashboardViews
    • seem to return only high level numbers not dashboard but per week
  • /api/42/dataStatistics/favorites?eventType=DASHBOARD_VIEW&pageSize=50&sortOrder=DESC
    • seem to return dashboard names, but not per week, only since the “beginning”

So I guess I need to do that last query every week and substract from previous week counts ?
or is there another param/endpoint that could help ?

I tried via an sqlView but not sure if it’s ok/futur proof

select
 d.uid as dashboard_uid,
 d.name as dashboard_name,
count(\*) as views
from datastatisticsevent dse
join dashboard d on d.uid = dse.favoriteuid
where dse.eventtype = 'DASHBOARD_VIEW'
and dse.timestamp >= '${startDate}'
and dse.timestamp < '${endDate}'
group by d.uid, d.name
order by views desc;

then accessing

/api/29/sqlViews/athsWWcQ3O4/data?paging=false&var=startDate:2026-04-20&var=endDate:2026-04-27