Skip to content

Commit

Permalink
Added Google Analytics.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhiiva committed Jul 30, 2020
1 parent b0d570a commit 6da89d3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions agagd/agagd/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
'django.contrib.messages.context_processors.messages',
# Custom context_processors
'django.template.context_processors.request',
'agagd_core.context_processors.google_analytics_tracking_id',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
Expand Down
2 changes: 2 additions & 0 deletions agagd/agagd/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
else:
DEBUG = False

GOOGLE_ANALYTICS_TRACKING_ID = os.getenv('GOOGLE_ANALYTICS_TRACKING_ID', '')

ADMIN_ENABLED = False

# For SECRET_KEY, we want to be absolutely certain a value is provided
Expand Down
1 change: 1 addition & 0 deletions agagd/agagd_core/context_processors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .google_analytics import *
3 changes: 3 additions & 0 deletions agagd/agagd_core/context_processors/google_analytics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def google_analytics_tracking_id(request):
from django.conf import settings
return {'google_analytics_tracking_id': settings.GOOGLE_ANALYTICS_TRACKING_ID}
13 changes: 13 additions & 0 deletions agagd/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
<script src={% static "lib/jquery-2.1.0.min.js" %}></script>
<script src={% static "lib/jquery-ui/js/jquery-ui-1.10.3.custom.min.js" %}></script>
{% endblock %}
{% block google_analytics %}
{% if google_analytics_tracking_id != '' %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ google_analytics_tracking_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '{{ google_analytics_tracking_id }}' );
</script>
{% endif %}
{% endblock %}
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
Expand Down

0 comments on commit 6da89d3

Please sign in to comment.