Skip to content

Commit

Permalink
Merge pull request #515 from OpenUpSA/fix/analytics-downloads
Browse files Browse the repository at this point in the history
Dynamic GTM and GA4 settings
  • Loading branch information
paulmwatson authored Jan 24, 2024
2 parents 5d234dd + f51515a commit e73c3d3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

WTF_CSRF_ENABLED = False if TEST else True
SECRET_KEY = env.get("FLASK_SECRET_KEY", "NSTHNSTHaoensutCGSRCGnsthoesucgsrSNTH")
GOOGLE_ANALYTICS_ID = "G-EBG7VD75NV"
GOOGLE_ANALYTICS_ID = env.get("GOOGLE_ANALYTICS_ID", None)
GOOGLE_TAG_MANAGER_ID = env.get("GOOGLE_TAG_MANAGER_ID", None)

SQLALCHEMY_DATABASE_URI = env.get(
"SQLALCHEMY_DATABASE_URI",
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ services:
- REDIS_URL=redis://redis:6379/0
- SQLALCHEMY_DATABASE_URI=postgresql://pmg:pmg@postgres/pmg?client_encoding=utf8
- ES_SERVER=http://elastic:9200
- GOOGLE_ANALYTICS_ID=G-XN8MJJNSEE
- GOOGLE_TAG_MANAGER_ID=GTM-MMCNPLT6
ports:
- "5000:5000"
command: python app.py runserver
Expand Down
4 changes: 2 additions & 2 deletions pmg/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-W7T6ZWH7');</script>
})(window,document,'script','dataLayer','{{ config["GOOGLE_TAG_MANAGER_ID"] }}');</script>
<!-- End Google Tag Manager -->

<meta charset="utf-8">
Expand Down Expand Up @@ -102,7 +102,7 @@
<body class="{{ request.endpoint }} {% if current_user.is_authenticated %}logged-in{% else %}not-logged-in{% endif %}">

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W7T6ZWH7"
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{ config["GOOGLE_TAG_MANAGER_ID"] }}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

Expand Down
2 changes: 1 addition & 1 deletion pmg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def track_pageview(path=None, ignore_bots=True):
""" User Google Analytics to track this pageview. """
from pmg import app

ga_id = app.config.get("GOOGLE_ANALYTICS_ID")
ga_id = app.config["GOOGLE_ANALYTICS_ID"]
if not ga_id:
return False

Expand Down

0 comments on commit e73c3d3

Please sign in to comment.