From 007fc794c38bf4d109ef146e47da8bd5b9d9d320 Mon Sep 17 00:00:00 2001 From: Andrii Marynets Date: Tue, 27 Jun 2017 23:47:30 +0300 Subject: [PATCH] Add google analytics to data center light --- datacenterlight/context_processor.py | 16 ++++++++++++++++ .../templates/datacenterlight/base.html | 3 +++ .../includes/_google_analytics.html | 15 +++++++++++++++ .../templates/datacenterlight/order_detail.html | 2 +- dynamicweb/settings/base.py | 5 +++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 datacenterlight/context_processor.py create mode 100644 datacenterlight/templates/datacenterlight/includes/_google_analytics.html diff --git a/datacenterlight/context_processor.py b/datacenterlight/context_processor.py new file mode 100644 index 00000000..b49ea364 --- /dev/null +++ b/datacenterlight/context_processor.py @@ -0,0 +1,16 @@ +from django.conf import settings + + +def google_analytics(request): + """ + Use the variables returned in this function to + render your Google Analytics tracking code template. + """ + ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_ID', False) + ga_domain = getattr(settings, 'GOOGLE_ANALYTICS_DOMAIN', False) + if not settings.DEBUG and ga_prop_id and ga_domain: + return { + 'GOOGLE_ANALYTICS_PROPERTY_ID': ga_prop_id, + 'GOOGLE_ANALYTICS_DOMAIN': ga_domain, + } + return {} diff --git a/datacenterlight/templates/datacenterlight/base.html b/datacenterlight/templates/datacenterlight/base.html index c62d92f7..bf0e0ca0 100644 --- a/datacenterlight/templates/datacenterlight/base.html +++ b/datacenterlight/templates/datacenterlight/base.html @@ -47,6 +47,9 @@ {% include "datacenterlight/includes/_footer.html" %} + + {% include "datacenterlight/includes/_google_analytics.html" %} + diff --git a/datacenterlight/templates/datacenterlight/includes/_google_analytics.html b/datacenterlight/templates/datacenterlight/includes/_google_analytics.html new file mode 100644 index 00000000..d074dfd3 --- /dev/null +++ b/datacenterlight/templates/datacenterlight/includes/_google_analytics.html @@ -0,0 +1,15 @@ + +{% if GOOGLE_ANALYTICS_PROPERTY_ID %} + +{% else %} + +{% endif %} + \ No newline at end of file diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index cb412558..8b53df5d 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -2,7 +2,7 @@ {% load staticfiles bootstrap3 %} {% load i18n %} {% block content %} - +{% include 'datacenterlight/includes/_google_analytics.html' %}
{% if messages %}
diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index d276f022..f3a80470 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -161,6 +161,7 @@ TEMPLATES = [ "django.contrib.messages.context_processors.messages", 'sekizai.context_processors.sekizai', 'cms.context_processors.cms_settings', + 'datacenterlight.context_processor.google_analytics', ], }, }, @@ -509,3 +510,7 @@ 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_ID = 'UA-62285904-9' +GOOGLE_ANALYTICS_DOMAIN = 'auto'