Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics services integration #7313

Merged
merged 8 commits into from
Jun 6, 2024
Merged

Conversation

josegar74
Copy link
Member

@josegar74 josegar74 commented Sep 4, 2023

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 josegar74 added this to the 4.4.0 milestone Sep 4, 2023
@josegar74 josegar74 marked this pull request as draft September 4, 2023 12:49
@jahow
Copy link
Contributor

jahow commented Sep 4, 2023

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.

@josegar74
Copy link
Member Author

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

@josegar74
Copy link
Member Author

Configuration moved to config.properties file.

josegar74 and others added 2 commits September 6, 2023 09:57
* Analytics services integration / Send events by protocol

* Analytics services integration / Add example config for matomo.
fxprunayre added a commit to eea/geonetwork-eea that referenced this pull request Sep 6, 2023
@fxprunayre fxprunayre modified the milestones: 4.4.0, 4.4.1 Sep 25, 2023
@fxprunayre fxprunayre modified the milestones: 4.4.1, 4.4.2 Nov 22, 2023
@fxprunayre fxprunayre marked this pull request as ready for review January 3, 2024 08:30
josegar74 and others added 3 commits January 5, 2024 12:52
Failing test were:

```
15:47:17,320 [INFO] Results:
15:47:17,320 [INFO] 
Error: 7,320 [ERROR] Failures: 
Error: 7,320 [ERROR]   AlternateLogoForPdfExportTest.whenGeneratingPdfWithPropertyNotSetSiteLogoIsUsed:114 Status expected:<200> but was:<400>
Error: 7,321 [ERROR]   AlternateLogoForPdfExportTest.whenGeneratingPdfWithPropertySetPdfLogoIsUsed:74 Status expected:<200> but was:<400>
Error: 7,321 [ERROR]   AlternateLogoForPdfExportTest.whenNotGeneratingPdfWithPropertySetSiteLogoIsUsed:93 Status expected:<200> but was:<400>
Error: 7,321 [ERROR] Errors: 
Error: 7,321 [ERROR]   FormatterApiIntegrationTest.testExec:97 » XPath Exception in extension functio.
```
@fxprunayre fxprunayre modified the milestones: 4.4.2, 4.4.3 Jan 23, 2024
@fxprunayre fxprunayre modified the milestones: 4.4.3, 4.4.4 Mar 13, 2024
@fxprunayre fxprunayre modified the milestones: 4.4.4, 4.4.5 Apr 16, 2024
@fxprunayre fxprunayre merged commit 0dec1ad into geonetwork:main Jun 6, 2024
6 checks passed
fxprunayre added a commit to SPW-DIG/metawal-core-geonetwork that referenced this pull request Jul 18, 2024
* Analytics services integration

* Analytics services integration - add settings help

* Analytics services integration - move configuration to config.properties

* Analytics services integration - better name for web analytics service

* Analytics improvements (#84)

* Analytics services integration / Send events by protocol

* Analytics services integration / Add example config for matomo.

* Update web/src/main/webResources/WEB-INF/config.properties

Co-authored-by: François Prunayre <[email protected]>

* Test / Fix bean initialization

Failing test were:

```
15:47:17,320 [INFO] Results:
15:47:17,320 [INFO] 
Error: 7,320 [ERROR] Failures: 
Error: 7,320 [ERROR]   AlternateLogoForPdfExportTest.whenGeneratingPdfWithPropertyNotSetSiteLogoIsUsed:114 Status expected:<200> but was:<400>
Error: 7,321 [ERROR]   AlternateLogoForPdfExportTest.whenGeneratingPdfWithPropertySetPdfLogoIsUsed:74 Status expected:<200> but was:<400>
Error: 7,321 [ERROR]   AlternateLogoForPdfExportTest.whenNotGeneratingPdfWithPropertySetSiteLogoIsUsed:93 Status expected:<200> but was:<400>
Error: 7,321 [ERROR] Errors: 
Error: 7,321 [ERROR]   FormatterApiIntegrationTest.testExec:97 » XPath Exception in extension functio.
```

---------

Co-authored-by: François Prunayre <[email protected]>
Co-authored-by: Juan Luis Rodríguez Ponce <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants