Use Matomo
- define which data should be tracked
- configure data portal in esrf matomo
- add javascript tags in data portal
- data privacy/GDPR: do we need to add cookies alert? cf. https://matomo.org/cookie-consent-banners/
track:
-
how many downloads (dataset, files) => Events Download
-
how many access to H5Viewer: number of click on H5Viewer button => Events H5Viewer
-
how many Restore => Events Restore
-
how many access to DOI => Events OpenDOI
-
how often the logbooks get accessed, => Events BeamlineLogbook
andInvestigationLogbook
-
how many individual visits, => number of unique visitors (https://matomo.org/faq/general/faq_43/) -
how many logins, => Events SignIn
withanonymous
,keycloak
,plugin
(but the user can already be connected through keycloak) -
how many anonymous access, => Events SignIn
withanonymous
-
how many accesses to open data (maybe the same as downloads?), -
how many access to sample tracking. => Events Parcel
From Axel, human Organ project:
it was fairly simple, though: https://gitlab.esrf.fr/ui/human-organ-atlas/-/blob/main/public/index.html#L22
gitlab.esrf.fr
public/index.html · main · ui / human-organ-atlas
ESRF's GitLab instance
just need to put the correct setSiteId
note that I removed the pageview call from the snippet provided by Matomo
this is because I found the tracking worked better if I tracked a page view on each unique page: https://gitlab.esrf.fr/ui/human-organ-atlas/-/blob/main/src/Explore/ExplorePage.js#L18
gitlab.esrf.fr
src/Explore/ExplorePage.js · main · ui / human-organ-atlas
ESRF's GitLab instance
https://gitlab.esrf.fr/ui/human-organ-atlas/-/blob/main/src/App/hooks.js#L49
gitlab.esrf.fr
src/App/hooks.js · main · ui / human-organ-atlas
ESRF's GitLab instance
But this may not work for you... Tracking an SPA is complex... You obviously don't want to send a page view on every re-render of a page component, so you have to use useEffect with an empty deps array [].
it becomes complex when you have to track changes to query params or when the same page component is rendered for multiple URL paths/subpaths
Or stuff like that... it really depends on what you want to track.
That's for page views, then you can track links, downloads and events: https://gitlab.esrf.fr/ui/human-organ-atlas/-/blob/main/src/App/helpers.js#L158
gitlab.esrf.fr
src/App/helpers.js · main · ui / human-organ-atlas
ESRF's GitLab instance
For outbound links, Matomo is supposed to track them for you automatically when you enable some setting in your tracking code, but I couldn't make it work, so I think I disabled it and tracked the links myself. For outbound links with target="_blank", it's easy because the page has time to make the tracking request, but for the ones that don't have target, you have to catch the click, make the tracking request, and wait for it to complete before following the link...
The Matomo JS client user guide is pretty comprehensive: https://developer.matomo.org/api-reference/tracking-javascript#user-guide
developer.matomo.org
JavaScript Tracking Client: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v4
Edited by Marjolaine Bodin