core-geonetwork icon indicating copy to clipboard operation
core-geonetwork copied to clipboard

Analytics services integration

Open josegar74 opened this issue 1 year ago • 3 comments

This change allows to configure JS snippets to integrate with Matomo or Google Analytics. By default, no analytics service is configured.

An example configuration with Matomo:

analytics-settings

Also adds a service to track the links access, currently only implemented for Matomo using Events (https://developer.matomo.org/api-reference/tracking-javascript). Catalogue events are created based on link protocols and allows to track actions on links.

image

Example of configuration for matomo

# Analytics service: (empty value: no analytics),matomo,google
analytics.web.service=matomo
# Analytics javascript code to integrate with the analytics service (lines must be ended with \n\)
analytics.web.jscode=var _paq = _paq || [];_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);(function() {var u="//localhost/";_paq.push(['setTrackerUrl', u+'piwik.php']);_paq.push(['setSiteId', '1']);var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);})();var currentUrl = location.href; \
window.addEventListener('hashchange', function() {_paq.push(['setReferrerUrl', currentUrl]);currentUrl = window.location.hash.substr(1);_paq.push(['setCustomUrl', currentUrl]);_paq.push(['setDocumentTitle', currentUrl]);_paq.push(['deleteCustomVariables', 'page']);_paq.push(['trackPageView']);var content = document.getElementsByTagName('body')[0];_paq.push(['MediaAnalytics::scanForMedia', content]);_paq.push(['FormAnalytics::scanForForms', content]);_paq.push(['trackContentImpressionsWithinNode', content]);_paq.push(['enableLinkTracking']);});

josegar74 avatar Sep 04 '23 12:09 josegar74

Just a comment while passing by: writing JS code in a textarea and having it rendered on the client seems like a potential security vulnerability; I would rather define the custom snippet in the "backend" configuration of the app (e.g. web.xml), which is harder to access.

jahow avatar Sep 04 '23 13:09 jahow

@jahow thanks for the review, we'll check if can be moved to web.xml or config.properties.

josegar74 avatar Sep 04 '23 14:09 josegar74

Configuration moved to config.properties file.

josegar74 avatar Sep 06 '23 07:09 josegar74