diff --git a/datacenterlight/templates/datacenterlight/base.html b/datacenterlight/templates/datacenterlight/base.html index becb36d8..2c3f0e5d 100644 --- a/datacenterlight/templates/datacenterlight/base.html +++ b/datacenterlight/templates/datacenterlight/base.html @@ -33,6 +33,9 @@ + + {% include "google_analytics.html" %} + diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 42f916e3..273074cf 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -67,7 +67,7 @@

{% trans "Disk space"%} {{vm.disk_size}} GB


{% trans "Configuration"%} {{request.session.template.name}}

-
+

{% trans "Total"%}

{{vm.price}} CHF

{% endwith %} @@ -83,8 +83,8 @@ {% endif %} - - + + {% include 'google_analytics.html' %} + diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index d276f022..ba304ff9 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -118,6 +118,7 @@ INSTALLED_APPS = ( MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', + 'utils.middleware.MultipleProxyMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -138,6 +139,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(PROJECT_DIR, 'cms_templates/'), + os.path.join(PROJECT_DIR, 'templates'), os.path.join(PROJECT_DIR, 'cms_templates/djangocms_blog/'), os.path.join(PROJECT_DIR, 'membership'), os.path.join(PROJECT_DIR, 'hosting/templates/'), @@ -161,6 +163,7 @@ TEMPLATES = [ "django.contrib.messages.context_processors.messages", 'sekizai.context_processors.sekizai', 'cms.context_processors.cms_settings', + 'utils.context_processor.google_analytics', ], }, }, @@ -509,3 +512,12 @@ OPENNEBULA_ENDPOINT = env('OPENNEBULA_ENDPOINT') # dcl email configurations DCL_TEXT = env('DCL_TEXT') DCL_SUPPORT_FROM_ADDRESS = env('DCL_SUPPORT_FROM_ADDRESS') + +# Settings for Google analytics +GOOGLE_ANALYTICS_PROPERTY_IDS = { + 'datacenterlight.ch': 'UA-62285904-9', + 'digitalglarus.ch': 'UA-62285904-2', + '127.0.0.1:8000': 'localhost', + 'dynamicweb-development.ungleich.ch': 'development', + 'dynamicweb-staging.ungleich.ch': 'staging' +} diff --git a/templates/google_analytics.html b/templates/google_analytics.html new file mode 100644 index 00000000..64dbae40 --- /dev/null +++ b/templates/google_analytics.html @@ -0,0 +1,13 @@ +{% if GOOGLE_ANALYTICS_PROPERTY_ID %} + +{% else %} + +{% endif %} \ No newline at end of file diff --git a/utils/context_processor.py b/utils/context_processor.py new file mode 100644 index 00000000..740591ba --- /dev/null +++ b/utils/context_processor.py @@ -0,0 +1,15 @@ +from django.conf import settings + + +def google_analytics(request): + """ + Use the variables returned in this function to + render your Google Analytics tracking code template. + """ + host = request.get_host() + ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_IDS', False).get(host) + if not settings.DEBUG and ga_prop_id: + return { + 'GOOGLE_ANALYTICS_PROPERTY_ID': ga_prop_id + } + return {} diff --git a/utils/middleware.py b/utils/middleware.py new file mode 100644 index 00000000..d37bdbfd --- /dev/null +++ b/utils/middleware.py @@ -0,0 +1,17 @@ +class MultipleProxyMiddleware(object): + FORWARDED_FOR_FIELDS = [ + 'HTTP_X_FORWARDED_FOR', + 'HTTP_X_FORWARDED_HOST', + 'HTTP_X_FORWARDED_SERVER', + ] + + def process_request(self, request): + """ + Rewrites the proxy headers so that only the most + recent proxy is used. + """ + for field in self.FORWARDED_FOR_FIELDS: + if field in request.META: + if ',' in request.META[field]: + parts = request.META[field].split(',') + request.META[field] = parts[-1].strip() \ No newline at end of file