Skip to content

Commit 8a29dc5

Browse files
ISSUE-467: Add google analytics (#468)
Co-authored-by: Tomas Zulberti <tomas@jampp.com>
1 parent b8249f1 commit 8a29dc5

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

community/context_processors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
def pyar_wiki_url(request):
22
from django.conf import settings
33
# return the value you want as a dictionnary. you may add multiple values in there.
4-
return {'PYAR_WIKI_URL': settings.PYAR_WIKI_URL}
4+
return {
5+
'PYAR_WIKI_URL': settings.PYAR_WIKI_URL,
6+
'GOOGLE_TRACKING_ID': settings.GOOGLE_TRACKING_ID,
7+
}

community/templates/base.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@
2828
<link rel="icon" href="{% static 'img/icons/pyar.ico' %}" type="image/ico">
2929

3030
{% block extra_head %}{% endblock %}
31+
32+
{% if GOOGLE_TRACKING_ID %}
33+
<!-- Global site tag (gtag.js) - Google Analytics -->
34+
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-169755710-1"></script>
35+
<script>
36+
window.dataLayer = window.dataLayer || [];
37+
function gtag(){dataLayer.push(arguments);}
38+
gtag('js', new Date());
3139

32-
40+
gtag('config', '{{ GOOGLE_TRACKING_ID }}');
41+
</script>
42+
{% endif %}
3343
</head>
3444
<body>
3545

pyarweb/settings/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,5 @@
224224
'font-size',
225225
]
226226
TAGGIT_CASE_INSENSITIVE = True
227+
228+
GOOGLE_TRACKING_ID = os.environ.get('GOOGLE_TRACKING_ID', '')

0 commit comments

Comments
 (0)