From f98d2262b5a3b43f74cabcae862dbc33f9380494 Mon Sep 17 00:00:00 2001 From: Alexander CherryTea Date: Wed, 29 Nov 2023 17:40:18 +0100 Subject: [PATCH 1/3] add matomo metrics in base template --- .../core/base_templates/project_base.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/django_project/core/base_templates/project_base.html b/django_project/core/base_templates/project_base.html index dda92702b..582e48273 100644 --- a/django_project/core/base_templates/project_base.html +++ b/django_project/core/base_templates/project_base.html @@ -21,7 +21,21 @@ - + + + From 7c1e596e228f2106a63a4f404376d90ec22d96f8 Mon Sep 17 00:00:00 2001 From: Alexander CherryTea Date: Thu, 30 Nov 2023 14:41:09 +0100 Subject: [PATCH 2/3] Use template variables in matomo code --- .../core/base_templates/project_base.html | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/django_project/core/base_templates/project_base.html b/django_project/core/base_templates/project_base.html index 582e48273..cb3c12279 100644 --- a/django_project/core/base_templates/project_base.html +++ b/django_project/core/base_templates/project_base.html @@ -21,22 +21,25 @@ - - - + {% if matomo_url and matomo_site_id %} + + + + {% endif %} + From 046c16cf86c3db5e2ef3dd7d60745a93b1751e43 Mon Sep 17 00:00:00 2001 From: Alexander CherryTea Date: Thu, 30 Nov 2023 14:54:45 +0100 Subject: [PATCH 3/3] matomo variables in the private config --- README.md | 7 +++++++ django_project/core/context_processors.py | 21 +++++++++++++++++++++ django_project/core/settings/base.py | 1 + 3 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 47f9985df..1efbcf67d 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,13 @@ If you wish to make use of [intercom.io](https://www.intercom.io), include a `private.py` file in `core.settings` with your `INTERCOM_APP_ID` as a string. The necessary code snippet is already included in `project_base.html`. +**matomo.org** + +If you wish to make use of [matomo.org](https://www.matomo.org), include a +`private.py` file in `core.settings` with your `MATOMO_SITE_ID` and `MATOMO_URL` as a string. +The necessary code snippet is already included in `project_base.html`. + + **google authentication** In social auth to use the google authentication you need to go to: diff --git a/django_project/core/context_processors.py b/django_project/core/context_processors.py index ec2c2cd4c..6a0127324 100644 --- a/django_project/core/context_processors.py +++ b/django_project/core/context_processors.py @@ -21,6 +21,27 @@ def add_intercom_app_id(request): else: return {} +# noinspection PyPep8Naming +def add_matomo_variables(request): + """Add our matomo vars to the context + + :param request: Http Request obj + + """ + try: + from core.settings.private import MATOMO_SITE_ID + from core.settings.private import MATOMO_URL + except ImportError: + MATOMO_SITE_ID = None + MATOMO_URL = None + + if MATOMO_SITE_ID and MATOMO_URL: + return {'matomo_site_id': MATOMO_SITE_ID, 'matomo_url': MATOMO_URL} + else: + return {} + + + def stripe_public_key(request): """Return stripe public key. diff --git a/django_project/core/settings/base.py b/django_project/core/settings/base.py index 4658b657b..0a6fc15bc 100644 --- a/django_project/core/settings/base.py +++ b/django_project/core/settings/base.py @@ -106,6 +106,7 @@ # Already defined Django-related contexts 'django.contrib.auth.context_processors.auth', 'core.context_processors.add_intercom_app_id', + 'core.context_processors.add_matomo_variables', 'core.context_processors.stripe_public_key', 'core.context_processors.sustaining_member_context', 'django.template.context_processors.i18n',