Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Add Google Tag to .env (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoirint authored Feb 24, 2023
1 parent e3bee4f commit 4fc3b72
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Nalypoll/Nalypoll/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.conf import settings

def nalypoll_gtag(request):
return {
'NALYPOLL_GTAG': settings.NALYPOLL_GTAG,
}
4 changes: 4 additions & 0 deletions Nalypoll/Nalypoll/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'Nalypoll.context_processors.nalypoll_gtag',
],
},
},
Expand Down Expand Up @@ -166,3 +167,6 @@

if 'DJANGO_STATIC_ROOT' in os.environ:
STATIC_ROOT = os.environ['DJANGO_STATIC_ROOT']


NALYPOLL_GTAG = os.environ.get('NALYPOLL_GTAG')
10 changes: 5 additions & 5 deletions Nalypoll/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@
crossorigin="anonymous"></script>
<script src="{% static 'js/barchartrace.js' %}"></script>


<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-157155944-4"></script>
{% if NALYPOLL_GTAG %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ NALYPOLL_GTAG }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-157155944-4');
gtag('config', '{{ NALYPOLL_GTAG }}');
</script>

{% endif %}

<!-- https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/set-up-twitter-for-websites -->
<script>window.twttr = (function(d, s, id) {
Expand Down
3 changes: 3 additions & 0 deletions template.env.django
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ CAN_REGISTER_SELF_TWEET_ONLY=1
DELTA_CHECK_TWEETS=15
DELTA_CHECK_USERS=60

# Google Analytics GA4 tag
NALYPOLL_GTAG=

TWITTER_TOKEN=
TWITTER_API_KEY=
TWITTER_API_SECRET=

0 comments on commit 4fc3b72

Please sign in to comment.