core-geonetwork
core-geonetwork copied to clipboard
Analytics services integration
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:
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.
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']);});
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 thanks for the review, we'll check if can be moved to web.xml
or config.properties
.
Configuration moved to config.properties
file.