Permalink
Browse files

Add GA handling.

  • Loading branch information...
1 parent c100435 commit 93ed96fb4f9e9fc0b564f9b9b7208494d3171ec9 @dracos dracos committed Sep 20, 2012
Showing with 28 additions and 2 deletions.
  1. +3 −0 conf/general.yml-example
  2. +5 −1 mapit/context_processors.py
  3. +15 −1 mapit/templates/mapit/base.html
  4. +5 −0 project/settings.py
@@ -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'
@@ -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 }
@@ -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
@@ -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',

0 comments on commit 93ed96f

Please sign in to comment.