From 66a0b82e3ce758e24b6581bdc1375bdc00d3849e Mon Sep 17 00:00:00 2001 From: Jasper van Merle Date: Tue, 5 Feb 2019 01:21:45 +0100 Subject: [PATCH] Ask for consent before enabling Google Analytics and Gauges --- assets/javascripts/app/settings.coffee | 2 + assets/javascripts/lib/page.coffee | 18 ++++++- .../javascripts/templates/notif_tmpl.coffee | 6 +++ .../templates/pages/about_tmpl.coffee | 3 +- .../templates/pages/settings_tmpl.coffee | 4 ++ assets/javascripts/tracking.js | 50 ++++++++++--------- .../views/content/settings_page.coffee | 8 +++ .../javascripts/views/layout/document.coffee | 12 +++-- assets/stylesheets/components/_notif.scss | 4 ++ 9 files changed, 77 insertions(+), 30 deletions(-) diff --git a/assets/javascripts/app/settings.coffee b/assets/javascripts/app/settings.coffee index 8d309c41..ca7ccbc6 100644 --- a/assets/javascripts/app/settings.coffee +++ b/assets/javascripts/app/settings.coffee @@ -5,6 +5,7 @@ class app.Settings 'manualUpdate' 'fastScroll' 'arrowScroll' + 'analyticsConsent' 'docs' 'dark' 'layout' @@ -26,6 +27,7 @@ class app.Settings news: 0 manualUpdate: false schema: 1 + analyticsConsent: false constructor: -> @store = new CookieStore diff --git a/assets/javascripts/lib/page.coffee b/assets/javascripts/lib/page.coffee index 5d3f6c88..ba2f2647 100644 --- a/assets/javascripts/lib/page.coffee +++ b/assets/javascripts/lib/page.coffee @@ -199,5 +199,21 @@ page.track = (fn) -> return track = -> - tracker.call() for tracker in trackers + consentGiven = Cookies.get('analyticsConsent') + consentAsked = Cookies.get('analyticsConsentAsked') + + if consentGiven == '1' + tracker.call() for tracker in trackers + else if consentGiven == undefined and consentAsked == undefined + # Only ask for consent once per browser session + Cookies.set('analyticsConsentAsked', '1') + + new app.views.Notif 'AnalyticsConsent', autoHide: null + return + +@resetAnalytics = -> + for cookie in document.cookie.split(/;\s?/) + name = cookie.split('=')[0] + if name[0] == '_' + Cookies.expire(name) return diff --git a/assets/javascripts/templates/notif_tmpl.coffee b/assets/javascripts/templates/notif_tmpl.coffee index 93611a5c..8989daff 100644 --- a/assets/javascripts/templates/notif_tmpl.coffee +++ b/assets/javascripts/templates/notif_tmpl.coffee @@ -68,3 +68,9 @@ app.templates.notifShare = -> app.templates.notifUpdateDocs = -> textNotif """ Documentation updates available. """, """ Install them as soon as possible to avoid broken pages. """ + +app.templates.notifAnalyticsConsent = -> + textNotif """ Tracking cookies """, + """ We would like to gather usage data about how you use DevDocs through Google Analytics and Gauges. We only collect anonymous traffic information. + Please confirm if you accept our tracking cookies. You can always change your decision in the settings. +
Accept or Decline """ diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 5d997403..e7b4cc80 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -73,7 +73,8 @@ app.templates.aboutPage = -> """