Commits

Lars Yencken  committed 4b7ef9b

Adds Google Analytics tracking code.

  • Participants
  • Parent commits 9e83821

Comments (0)

Files changed (3)

File simsearch/context.py

                 'number': fctx.rev(),
             }}
 
+def site_settings(request):
+    return {'settings': settings}
+
 # vim: ts=4 sw=4 sts=4 et tw=78:

File simsearch/settings.py

 
 N_NEIGHBOURS_RECALLED = 15
 
+GOOGLE_ANALYTICS_CODE = None
+
 # Tradeoff in Pr(a|s) and likelihood of reaching a further target from s'
 UPDATE_GAMMA = 0.7
 
     "django.core.context_processors.media",
     "django.contrib.messages.context_processors.messages",
     'simsearch.context.mercurial_revision',
+    'simsearch.context.site_settings',
 )
 
 MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'

File simsearch/templates/base.html

 	<title>Visual kanji search</title>
   {% block headers %}
   {% endblock %}
+
+  {% if settings.GOOGLE_ANALYTICS_CODE %}
+  <script type="text/javascript">
+    var _gaq = _gaq || [];
+    _gaq.push(['_setAccount', '{{settings.GOOGLE_ANALYTICS_CODE}}']);
+    _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 {% block body_tags %}{% endblock %}>