Merge pull request #110 from satnogs/analytics
[Fixes #101] Implement Analytics and DoNotTrackmerge-requests/113/head
commit
f5bec6896d
|
@ -0,0 +1,12 @@
|
|||
from django.conf import settings
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
|
||||
def analytics(request):
|
||||
"""Returns analytics code."""
|
||||
if settings.ENVIRONMENT == 'production':
|
||||
return {'analytics_code': render_to_string('includes/analytics.html',
|
||||
{'google_analytics_key': settings.GOOGLE_ANALYTICS_KEY,
|
||||
'user': request.user })}
|
||||
else:
|
||||
return {'analytics_code': ''}
|
|
@ -74,6 +74,8 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
|||
|
||||
'allauth.account.context_processors.account',
|
||||
'allauth.socialaccount.context_processors.socialaccount',
|
||||
|
||||
'network.base.context_processors.analytics',
|
||||
)
|
||||
TEMPLATE_DIRS = (
|
||||
path.join(BASE_DIR, 'templates'),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from base import *
|
||||
|
||||
ENVIRONMENT = 'dev'
|
||||
|
||||
# Debug
|
||||
DEBUG = True
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
from base import *
|
||||
|
||||
ENVIRONMENT = 'production'
|
||||
|
||||
# Apps
|
||||
INSTALLED_APPS += ('djangosecure', )
|
||||
|
@ -21,3 +22,6 @@ EMAIL_HOST = "localhost"
|
|||
EMAIL_PORT = 25
|
||||
DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', 'noreply@example.com')
|
||||
SERVER_EMAIL = DEFAULT_FROM_EMAIL
|
||||
|
||||
# Analytics
|
||||
GOOGLE_ANALYTICS_KEY = os.getenv('GOOGLE_ANALYTICS_KEY', None)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import os
|
||||
from base import *
|
||||
|
||||
ENVIRONMENT = 'stage'
|
||||
|
||||
# Security
|
||||
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '*')
|
||||
|
||||
|
|
|
@ -113,5 +113,8 @@
|
|||
<script src="{% static 'js/lib/bootstrap.min.js' %}"></script>
|
||||
{% block javascript %}
|
||||
{% endblock javascript %}
|
||||
|
||||
<!-- Google Analytics -->
|
||||
{{ analytics_code }}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<script>
|
||||
if (navigator.doNotTrack !== '1') {
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', '{{ google_analytics_key }}', 'auto');
|
||||
ga('send', 'pageview');
|
||||
{% if user.is_active %}
|
||||
ga('set', '&uid', {{user.id}});
|
||||
{% endif %}
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue