Skip to content

Commit bed5deb

Browse files
committed
including gtag via env var
1 parent 255c8f8 commit bed5deb

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/django_project/core/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,5 @@
301301
)
302302
PROJECT_VERSION = env.str("IMAGE_TAG", "0.0.0")
303303
PROJECT_SOURCE = "https://github.com/SpokaneTech/SpokanePythonWeb"
304+
305+
GOOGLE_ANALYTICS_TAG_ID: str | None = env.str("GOOGLE_ANALYTICS_TAG_ID", None)

src/django_project/web/templates/web/full/host_info.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
<html lang="en">
55

66
<head>
7+
{% if GOOGLE_ANALYTICS_TAG_ID %}
78
<!-- Google tag (gtag.js) -->
8-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-X6VK8H1VLF"></script>
9+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ GOOGLE_ANALYTICS_TAG_ID }}"></script>
910
<script>
10-
window.dataLayer = window.dataLayer || [];
11-
function gtag(){dataLayer.push(arguments);}
12-
gtag('js', new Date());
11+
window.dataLayer = window.dataLayer || [];
12+
function gtag(){dataLayer.push(arguments);}
13+
gtag('js', new Date());
1314

14-
gtag('config', 'G-X6VK8H1VLF');
15+
gtag('config', '{{ GOOGLE_ANALYTICS_TAG_ID }}');
1516
</script>
17+
{% endif %}
1618
<meta charset="UTF-8">
1719
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1820
<meta name="description"

src/django_project/web/templates/web/full/index.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
<html lang="en">
55

66
<head>
7+
{% if GOOGLE_ANALYTICS_TAG_ID %}
78
<!-- Google tag (gtag.js) -->
8-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-X6VK8H1VLF"></script>
9+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ GOOGLE_ANALYTICS_TAG_ID }}"></script>
910
<script>
10-
window.dataLayer = window.dataLayer || [];
11-
function gtag(){dataLayer.push(arguments);}
12-
gtag('js', new Date());
11+
window.dataLayer = window.dataLayer || [];
12+
function gtag(){dataLayer.push(arguments);}
13+
gtag('js', new Date());
1314

14-
gtag('config', 'G-X6VK8H1VLF');
15+
gtag('config', '{{ GOOGLE_ANALYTICS_TAG_ID }}');
1516
</script>
17+
{% endif %}
1618
<meta charset="UTF-8">
1719
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1820
<meta name="description"

src/envs/.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SECRET_KEY=change_me
33
ALLOWED_HOSTS=localhost,127.0.0.1
44
INTERNAL_IPS=localhost,127.0.0.1
55
DJANGO_SETTINGS_MODULE=core.settings
6+
GOOGLE_ANALYTICS_TAG_ID=
67
LOG_PATH="/home/$USER/projects/django_project/django_logs"
78
DB_ENGINE=django.db.backends.sqlite3
89
DB_NAME=my_django_project.sqlite3

0 commit comments

Comments
 (0)