Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add GA handling.

  • Loading branch information...
commit 93ed96fb4f9e9fc0b564f9b9b7208494d3171ec9 1 parent c100435
@dracos dracos authored
View
3  conf/general.yml-example
@@ -25,6 +25,9 @@ DJANGO_SECRET_KEY: 'gu^&xc)hoibh3x&s+9009jbn4d$!nq0lz+syx-^x8%z24!kfs4'
# Mapped to Django's DEBUG and TEMPLATE_DEBUG settings. Optional, defaults to True.
DEBUG: True
+# A GA code
+GOOGLE_ANALYTICS: ""
+
# A list of IP addresses or User Agents that should be excluded from rate limiting. Optional.
RATE_LIMIT:
- '127.0.0.1'
View
6 mapit/context_processors.py
@@ -1,3 +1,7 @@
+from django.conf import settings
+
def country(request):
- from django.conf import settings
return { 'country': settings.MAPIT_COUNTRY }
+
+def analytics(request):
+ return { 'GOOGLE_ANALYTICS': settings.GOOGLE_ANALYTICS }
View
16 mapit/templates/mapit/base.html
@@ -18,8 +18,22 @@
<script src="{% url mapit_index %}static/mapit/leaflet/leaflet.js"></script>
{% if norobots %}
-<meta name="robots" content="noindex, follow">
+ <meta name="robots" content="noindex, follow">
{% endif %}
+
+{% if GOOGLE_ANALYTICS %}
+<script type="text/javascript">
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', '{{ GOOGLE_ANALYTICS }}']);
+ _gaq.push(['_trackPageview']);
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+</script>
+{% endif %}
+
</head>
<body id="mapit-mysociety-org" class="">
View
5 project/settings.py
@@ -35,6 +35,9 @@
# limiting. Optional.
MAPIT_RATE_LIMIT = config.get('RATE_LIMIT', [])
+# A GA code for analytics
+GOOGLE_ANALYTICS = config.get('GOOGLE_ANALYTICS', '')
+
# Django settings for mapit project.
DEBUG = config.get('DEBUG', True)
@@ -161,12 +164,14 @@
'django.core.context_processors.request',
'django.contrib.auth.context_processors.auth',
'mapit.context_processors.country',
+ 'mapit.context_processors.analytics',
)
else:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
'django.core.context_processors.auth',
'mapit.context_processors.country',
+ 'mapit.context_processors.analytics',
#'django.core.context_processors.debug',
#'django.core.context_processors.i18n',
#'django.core.context_processors.media',
Please sign in to comment.
Something went wrong with that request. Please try again.