Skip to content
Snippets Groups Projects
Commit 61230906 authored by Mark HOEBEKE's avatar Mark HOEBEKE
Browse files

Merge branch 'evolution--add-matomo-tracking' into 'develop'

Added configurable Matomo tracking code & config.

See merge request !3
parents 23f20713 504cd28c
No related branches found
No related tags found
3 merge requests!6Re-sync main with latest from develop before new release.,!4Sync main with latest from develop before tagging new release.,!3Added configurable Matomo tracking code & config.
......@@ -6,4 +6,4 @@ RUN pip install -r /app/requirements.txt
WORKDIR /app
COPY ./src /app/src
WORKDIR /app/src
CMD ["gunicorn","dash_unicorn:server","-b","0.0.0:8050" ]
CMD ["gunicorn","dash_unicorn:server","-b","0.0.0.0:8050" ]
......@@ -20,3 +20,7 @@ url_base_pathname='/phytobsdash/'
debug=true
host='0.0.0.0'
use_reloader=false
[matomo]
tracker_url='https://matomo.yourdomain.com/'
site_id='123'
window.addEventListener("load", (event) => {
let tracker_url = document.querySelector('meta[property="matomo-tracker-url"]').content;
let site_id = document.querySelector('meta[property="matomo-site-id"]').content;
if (tracker_url != null && tracker_url != "" && site_id != null && site_id != "") {
let _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
let u=tracker_url;
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', site_id]);
let d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
}
});
......@@ -24,11 +24,25 @@ def build_app(config):
"""
LOGGER.debug("Starting build_app")
matomo_tracker_url = ''
matomo_site_id = ''
if 'matomo' in config and 'tracker_url' in config['matomo'] and 'site_id' in config['matomo']:
LOGGER.debug(
f"Initializing Matomo collector with tracker url {config['matomo']['tracker_url']} and site id {config['matomo']['site_id']}")
matomo_tracker_url = config['matomo']['tracker_url']
matomo_site_id = config['matomo']['site_id']
else:
LOGGER.debug(f"Matomo configuration missing or incomplete. Skipping.")
app = Dash('phytobsdash',
title="PHYTOBS SNO Data Viewer",
external_stylesheets=[dbc.themes.YETI, dbc.icons.BOOTSTRAP],
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1"},
{"property": "matomo-tracker-url", "content": matomo_tracker_url},
{"property": "matomo-site-id", "content": matomo_site_id},
],
use_pages=True,
**config['webapp']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment