From ecf84d5e2ee71b6c9f4dbb3e4e73e8fc6a26f394 Mon Sep 17 00:00:00 2001 From: paulmwatson Date: Wed, 24 Jan 2024 10:48:39 +0200 Subject: [PATCH] Fixed up Google Analytics 4 (gtag) --- docker-compose.yml | 1 + .../templates/admin/base_site.html | 2 ++ pombola/core/context_processors.py | 1 + pombola/settings/base.py | 1 + pombola/settings/south_africa.py | 3 --- pombola/templates/default_base.html | 19 +++++++++++-------- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b40edbc30..49ba1f906 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,7 @@ services: - GOOGLE_RECAPTCHA_SECRET_KEY - ENVIRONMENT=development - SENTRY_DSN=https://36d69cae4d76e0452f3fbdbb5019a279@o242378.ingest.sentry.io/5246237 + - GOOGLE_ANALYTICS_ID=G-T25P07Y7G2 ports: - "8000:8000" command: bin/wait-for-deps.sh python manage.py runserver 0.0.0.0:8000 diff --git a/pombola/admin_additions/templates/admin/base_site.html b/pombola/admin_additions/templates/admin/base_site.html index cfa5a4398..d93adad31 100644 --- a/pombola/admin_additions/templates/admin/base_site.html +++ b/pombola/admin_additions/templates/admin/base_site.html @@ -47,6 +47,7 @@ //]]> + {% if settings.GOOGLE_ANALYTICS_ACCOUNT %} + {% endif %} {% include 'autocomplete_light/static.html' %} diff --git a/pombola/core/context_processors.py b/pombola/core/context_processors.py index cbd8bea0a..4cbe8da80 100644 --- a/pombola/core/context_processors.py +++ b/pombola/core/context_processors.py @@ -8,6 +8,7 @@ def add_settings( request ): 'settings': { 'STAGING': settings.STAGING, 'GOOGLE_ANALYTICS_ACCOUNT': settings.GOOGLE_ANALYTICS_ACCOUNT, + 'GOOGLE_ANALYTICS_ID': settings.GOOGLE_ANALYTICS_ID, 'POLLDADDY_WIDGET_ID': settings.POLLDADDY_WIDGET_ID, 'DISQUS_SHORTNAME': settings.DISQUS_SHORTNAME, 'DISQUS_USE_IDENTIFIERS': settings.DISQUS_USE_IDENTIFIERS, diff --git a/pombola/settings/base.py b/pombola/settings/base.py index 3859c99ca..404b06078 100644 --- a/pombola/settings/base.py +++ b/pombola/settings/base.py @@ -346,6 +346,7 @@ # misc settings HTTPLIB2_CACHE_DIR = os.path.join(data_dir, "httplib2_cache") GOOGLE_ANALYTICS_ACCOUNT = os.environ.get("GOOGLE_ANALYTICS_ACCOUNT", None) +GOOGLE_ANALYTICS_ID = os.environ.get("GOOGLE_ANALYTICS_ID", None) GOOGLE_SITE_VERIFICATION = os.environ.get("GOOGLE_SITE_VERIFICATION", None) # Markitup settings diff --git a/pombola/settings/south_africa.py b/pombola/settings/south_africa.py index 297a4af39..a67bf892e 100644 --- a/pombola/settings/south_africa.py +++ b/pombola/settings/south_africa.py @@ -44,6 +44,3 @@ }, 'TIMEOUT': 60*60*24, } - - -GOOGLE_ANALYTICS_ID = 'G-RK0Z57HMF6' \ No newline at end of file diff --git a/pombola/templates/default_base.html b/pombola/templates/default_base.html index 023057d7e..c0db79637 100644 --- a/pombola/templates/default_base.html +++ b/pombola/templates/default_base.html @@ -1,6 +1,17 @@ + {% if settings.GOOGLE_ANALYTICS_ID %} + + + + {% endif %} {% comment %} The Google Analytics documentation says that the experiment @@ -81,14 +92,6 @@ {% block extra_headers %}{% endblock %} - - {% block header %}