diff --git a/assets/javascripts/app/settings.coffee b/assets/javascripts/app/settings.coffee index 1d2e43bd..a03d0b5e 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' @@ -28,6 +29,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..0821036e 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 DevDocs is used 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 = -> """