From 7f6cce2f6e2293ff2a0b2a783640e1765c6165d8 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Sun, 27 Jan 2019 14:14:24 -0500 Subject: [PATCH] Add client-side analytics via Azure AppInsights See https://docs.microsoft.com/en-us/azure/azure-monitor/app/javascript --- Dockerfile | 1 + app/app/settings.py | 1 + app/server/templates/base.html | 1 + app/server/templates/tags/azure_appinsights.html | 14 ++++++++++++++ app/server/templatetags/analytics.py | 8 ++++++++ 5 files changed, 25 insertions(+) create mode 100644 app/server/templates/tags/azure_appinsights.html diff --git a/Dockerfile b/Dockerfile index ac7fd99f..9c7fc973 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,7 @@ ENV SECRET_KEY="change-me-in-production" ENV BIND="0.0.0.0:80" ENV WORKERS="2" ENV GOOGLE_TRACKING_ID="" +ENV AZURE_APPINSIGHTS_IKEY="" EXPOSE 80 diff --git a/app/app/settings.py b/app/app/settings.py index 66a6e879..7a358791 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -185,5 +185,6 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') IMPORT_BATCH_SIZE = 500 GOOGLE_TRACKING_ID = os.getenv('GOOGLE_TRACKING_ID', 'UA-125643874-2') +AZURE_APPINSIGHTS_IKEY = os.getenv('AZURE_APPINSIGHTS_IKEY') django_heroku.settings(locals(), test_runner=False) diff --git a/app/server/templates/base.html b/app/server/templates/base.html index 91574c1f..c8a4c25c 100644 --- a/app/server/templates/base.html +++ b/app/server/templates/base.html @@ -35,6 +35,7 @@ {% block header %}{% endblock %} + {% azure_appinsights %} diff --git a/app/server/templates/tags/azure_appinsights.html b/app/server/templates/tags/azure_appinsights.html new file mode 100644 index 00000000..951e906b --- /dev/null +++ b/app/server/templates/tags/azure_appinsights.html @@ -0,0 +1,14 @@ +{# See https://apmtips.com/blog/2015/03/18/javascript-snippet-explained/ #} +{% if azure_appinsights_ikey %} + +{% endif %} diff --git a/app/server/templatetags/analytics.py b/app/server/templatetags/analytics.py index 9667a560..a623cb71 100644 --- a/app/server/templatetags/analytics.py +++ b/app/server/templatetags/analytics.py @@ -8,3 +8,11 @@ register = template.Library() @register.inclusion_tag('tags/google_analytics.html') def google_analytics(): return {'google_tracking_id': settings.GOOGLE_TRACKING_ID} + + +@register.inclusion_tag('tags/azure_appinsights.html') +def azure_appinsights(): + return { + 'DEBUG': settings.DEBUG, + 'azure_appinsights_ikey': settings.AZURE_APPINSIGHTS_IKEY, + }