diff --git a/README.md b/README.md index 66ec9eed037341522588916fdaa46bd411f1ae98..19b10191173cc5bf869b46561d4ddb9a2e5aef54 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 bc8dea9ec0811b83eb85dafa8074cf77cb597858..9c6ba27837703bb2b625c3bd1cce885ca8e6f952 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 9ca9f663eb19823be1e89bd5a9df04ad2fed40c2..b907f9fe76ae3fd5978cfe7226e3722f5393eb3e 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 fdc7cbe465311eb0508c71e8c0f79fb684fec1ee..57b96682a79878fe39313a1f15a757ae1364642f 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 %}