Hi!
You're right — the ods-aggregation
widget doesn't support distinct counts natively. However, you can achieve exactly what you're looking for using the ods-adv-analysis
widget instead.
This widget offers more advanced aggregation options, including the ability to perform distinct counts on a specific field, such as user_ip_addr
.
You’ll find the documentation and examples here:
https://help.opendatasoft.com/widgets/#/api/ods-widgets.directive:odsAdvAnalysis
Let us know if you'd like help with the full HTML snippet — happy to assist!
Thomas
Thanks for this Thomas, This has worked to get the number in the cards for registered users.
Is there a secure way to share this number openly? I know I can add an API key to the dataset context, but is there a way to do this without exposing that key in the HTML code?
If that API key was exposed what would someone be able to access from the analytics with it?
Hi Matthew,
Apologies for the delay in getting back to you!
To answer your question: you're absolutely right to be cautious about exposing an API key in client-side HTML — even read-only keys can potentially give access to more data than intended if not scoped properly.
One alternative approach you could consider is creating a dedicated dataset from the ods-api-monitoring
dataset. In this new dataset, you would keep only the fields and records relevant for computing your KPIs (such as the distinct user_ip_addr
count for the last month). This would allow you to safely share and display the KPI on your portal’s homepage without needing to expose any API key — the KPI value would be pre-calculated and stored in the dataset itself.
Let me know if you’d like help setting this up!
Best regards,
Thomas