Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Google Analytics snippet for djiki.info website

  • Loading branch information...
commit ca3153ef3ac579131102832ea329b80c5d110e28 1 parent 4140188
@emesik authored
Showing with 38 additions and 0 deletions.
  1. +4 −0 ga_processor.py
  2. +9 −0 settings.py
  3. +25 −0 templates/base.html
View
4 ga_processor.py
@@ -0,0 +1,4 @@
+from django.conf import settings
+
+def google_analytics(ctx):
+ return {'GOOGLE_ANALYTICS_ID': getattr(settings, 'GOOGLE_ANALYTICS_ID', '')}
View
9 settings.py
@@ -103,6 +103,15 @@
'djiki',
)
+TEMPLATE_CONTEXT_PROCESSORS = (
+ 'django.contrib.auth.context_processors.auth',
+ 'django.core.context_processors.debug',
+ 'django.core.context_processors.i18n',
+ 'django.core.context_processors.media',
+ 'django.contrib.messages.context_processors.messages',
+ 'ga_processor.google_analytics',
+)
+
DJIKI_IMAGES_PATH = 'djimages/' # relative to MEDIA_ROOT
DJIKI_ALLOW_ANONYMOUS_EDITS = True
View
25 templates/base.html
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+{% comment %}
+
+This is an example template. It's being used on a live site, http://djiki.info
+which is the Djiki homepage.
+
+Feel free to replace it with anything you like.
+
+{% endcomment %}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
@@ -30,6 +38,23 @@
{% endif %}
{% endblock %}
{% block page %}{% endblock %}
+{% block google-analytics %}
+{% if GOOGLE_ANALYTICS_ID %}
+<script type="text/javascript">
+
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', '{{ GOOGLE_ANALYTICS_ID }}']);
+ _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 %}
+{% endblock %}
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.