From 0149f68f7c606147ba0b3935be586b429b63d40f Mon Sep 17 00:00:00 2001 From: Thorge Petersen <petersen@rz.uni-kiel.de> Date: Fri, 17 Jan 2025 09:26:34 +0100 Subject: [PATCH] feat: readded matomo support --- README.md | 3 +++ ckanext/odsh/helpers.py | 9 +++++++++ ckanext/odsh/plugin.py | 3 +++ ckanext/odsh/templates/base.html | 26 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/README.md b/README.md index 66ec9eed..19b10191 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,9 @@ Parameter | Type | Default | Description `ckanext.odsh.lenient_with` | `string` | Empty string | Comma seperated list of organization IDs for which certain validations should be more lenient, e.g., `09871195-cd0a-4767-9396-276404c940d9,6389d8d9-4eed-472f-9220-4cc2dd82fb90`. `ckanext.odsh.testuser` | `string` | `None` | Name of user for testing. `ckanext.odsh.testuserpass` | `string` | `None` | Password of user for testing. +`ckanext.odsh.matomo_enabled` | `boolean` | `False` | Enable Matomo tracking. +`ckanext.odsh.matomo_base_uri` | `string` | `None` | Matomo tracker base URI. +`ckanext.odsh.matomo_site_id` | `string` | `None` | Matomo site id. Additionaly you might want to set the following configuration parameters: diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index bc8dea9e..9c6ba278 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -848,3 +848,12 @@ def extract_email(text): # If there are matches, return the first email address found, else return None return matches[0] if matches else None + +def odsh_matomo_enabled(): + return config.get('ckanext.odsh.matomo_enabled', False) == 'True' + +def odsh_matomo_base_uri(): + return config.get('ckanext.odsh.matomo_base_uri', None) + +def odsh_matomo_site_id(): + return config.get('ckanext.odsh.matomo_site_id', None) \ No newline at end of file diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 9ca9f663..b907f9fe 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -359,6 +359,9 @@ class OdshPlugin(p.SingletonPlugin, DefaultTranslation, tk.DefaultDatasetForm): 'odsh_load_mdk_sample_dataset': helpers_odsh.odsh_load_mdk_sample_dataset, 'odsh_load_raw_mdk_sample_dataset': helpers_odsh.odsh_load_raw_mdk_sample_dataset, 'format_resource_format': helpers_odsh.format_resource_format, + 'odsh_matomo_enabled': helpers_odsh.odsh_show_testbanner, + 'odsh_matomo_base_uri': helpers_odsh.odsh_matomo_base_uri, + 'odsh_matomo_site_id': helpers_odsh.odsh_matomo_site_id, } diff --git a/ckanext/odsh/templates/base.html b/ckanext/odsh/templates/base.html index fdc7cbe4..57b96682 100644 --- a/ckanext/odsh/templates/base.html +++ b/ckanext/odsh/templates/base.html @@ -10,6 +10,32 @@ {% block head_extras %} {{ super() }} + {% if h.odsh_matomo_enabled() %} + <!-- Matomo --> + <script> + var _paq = window._paq = window._paq || []; + /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ + _paq.push(["disableCookies"]); + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function() { + var u="{{ h.odsh_matomo_base_uri() | escape }}"; + _paq.push(['setTrackerUrl', u + 'matomo.php']); + _paq.push(['setSiteId', '{{ h.odsh_matomo_site_id() | escape }}']); + var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; + g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s); + })(); + </script> + <noscript> + <p> + <img referrerpolicy="no-referrer-when-downgrade" + src="{{ h.odsh_matomo_base_uri() | escape }}matomo.php?idsite={{ h.odsh_matomo_site_id() | escape }}&rec=1" + style="border:0;" + alt="" /> + </p> + </noscript> + <!-- End Matomo Code --> + {% endif %} {% endblock %} {% block bodytag %} data-site-root="{{ h.odsh_public_url() }}" data-locale-root="{{ h.odsh_public_url() }}" {% endblock %} -- GitLab