From 88c6cd497f22716dbaaec5e97220d69e68c75ef9 Mon Sep 17 00:00:00 2001 From: Stefan Koegl Date: Tue, 4 May 2010 23:49:28 +0200 Subject: [PATCH] optionally add google analytics code to base.html --- mygpo/settings.py | 10 ++++++++++ mygpo/web/googleanalytics.py | 26 ++++++++++++++++++++++++++ mygpo/web/templates/base.html | 6 ++++++ mygpo/web/templatetags/googleanalytics.py | 25 +++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 mygpo/web/googleanalytics.py create mode 100644 mygpo/web/templatetags/googleanalytics.py diff --git a/mygpo/settings.py b/mygpo/settings.py index 5eb415ef..761eda9c 100644 --- a/mygpo/settings.py +++ b/mygpo/settings.py @@ -118,6 +118,16 @@ AUTHENTICATION_BACKENDS = ( 'mygpo.auth_backends.EmailAuthenticationBackend', ) +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", + "mygpo.web.googleanalytics.processor", +) + + DEFAULT_FROM_EMAIL = 'mygpo@my.gpodder.org' AUTH_PROFILE_MODULE = "api.UserProfile" diff --git a/mygpo/web/googleanalytics.py b/mygpo/web/googleanalytics.py new file mode 100644 index 00000000..5f8be2ed --- /dev/null +++ b/mygpo/web/googleanalytics.py @@ -0,0 +1,26 @@ +# +# This file is part of my.gpodder.org. +# +# my.gpodder.org is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# my.gpodder.org is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public +# License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with my.gpodder.org. If not, see . +# + +from mygpo import settings + +def processor(request): + pid = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_ID', None) + if pid: + return {'google_analytics_property_id': pid} + else: + return {} + diff --git a/mygpo/web/templates/base.html b/mygpo/web/templates/base.html index e18e8927..05488784 100644 --- a/mygpo/web/templates/base.html +++ b/mygpo/web/templates/base.html @@ -26,6 +26,12 @@ {% block head %}{% endblock %} + + {% if google_analytics_property_id %} + {% load googleanalytics %} + {{ google_analytics_property_id|google_analytics_async }} + {% endif %} +
diff --git a/mygpo/web/templatetags/googleanalytics.py b/mygpo/web/templatetags/googleanalytics.py new file mode 100644 index 00000000..1ddfdbfa --- /dev/null +++ b/mygpo/web/templatetags/googleanalytics.py @@ -0,0 +1,25 @@ +from django import template +from django.utils.safestring import mark_safe + +register = template.Library() + +@register.filter +def google_analytics_async(property_id): + s = """ + """ % property_id + + return mark_safe(s) + -- 2.11.4.GIT