From c5b2f181774edfad7f063ead619118ef867f37c3 Mon Sep 17 00:00:00 2001 From: Warren Chen Date: Thu, 12 Feb 2026 12:06:04 +0900 Subject: [PATCH] Add GA4 integration with measurement ID and context processor --- innovedus_cms/mysite/context_processors.py | 7 +++++++ innovedus_cms/mysite/settings/base.py | 4 ++++ innovedus_cms/mysite/templates/base.html | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 innovedus_cms/mysite/context_processors.py diff --git a/innovedus_cms/mysite/context_processors.py b/innovedus_cms/mysite/context_processors.py new file mode 100644 index 0000000..ee31c19 --- /dev/null +++ b/innovedus_cms/mysite/context_processors.py @@ -0,0 +1,7 @@ +from django.conf import settings + + +def ga4(request): + return { + "ga4_measurement_id": getattr(settings, "GA4_MEASUREMENT_ID", ""), + } diff --git a/innovedus_cms/mysite/settings/base.py b/innovedus_cms/mysite/settings/base.py index e040ad4..4b43aa4 100644 --- a/innovedus_cms/mysite/settings/base.py +++ b/innovedus_cms/mysite/settings/base.py @@ -26,6 +26,9 @@ def env_list(name, default): return default +GA4_MEASUREMENT_ID = os.environ.get("GA4_MEASUREMENT_ID", "").strip() + + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ @@ -87,6 +90,7 @@ TEMPLATES = [ "django.contrib.messages.context_processors.messages", "wagtail.contrib.settings.context_processors.settings", "home.context_processors.navigation_pages", + "mysite.context_processors.ga4", ], }, }, diff --git a/innovedus_cms/mysite/templates/base.html b/innovedus_cms/mysite/templates/base.html index a406f9a..f34b3cf 100644 --- a/innovedus_cms/mysite/templates/base.html +++ b/innovedus_cms/mysite/templates/base.html @@ -17,6 +17,15 @@ {% endif %} + {% if ga4_measurement_id %} + + + {% endif %} {# Force all links in the live preview panel to be opened in a new tab #} {% if request.in_preview_panel %}