Merge pull request #979 from jmerle/cookies-consent

Cookie consent
pull/1028/head
Jasper van Merle 6 years ago committed by GitHub
commit 482d8709ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,7 @@ class app.Settings
'manualUpdate' 'manualUpdate'
'fastScroll' 'fastScroll'
'arrowScroll' 'arrowScroll'
'analyticsConsent'
'docs' 'docs'
'dark' 'dark'
'layout' 'layout'
@ -28,6 +29,7 @@ class app.Settings
news: 0 news: 0
manualUpdate: false manualUpdate: false
schema: 1 schema: 1
analyticsConsent: false
constructor: -> constructor: ->
@store = new CookieStore @store = new CookieStore

@ -199,5 +199,21 @@ page.track = (fn) ->
return return
track = -> 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 return

@ -68,3 +68,9 @@ app.templates.notifShare = ->
app.templates.notifUpdateDocs = -> app.templates.notifUpdateDocs = ->
textNotif """ Documentation updates available. """, textNotif """ Documentation updates available. """,
""" <a href="/offline">Install them</a> as soon as possible to avoid broken pages. """ """ <a href="/offline">Install them</a> 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.
<br><span class="_notif-right"><a href="#" data-behavior="accept-analytics">Accept</a> or <a href="#" data-behavior="decline-analytics">Decline</a></span> """

@ -73,7 +73,8 @@ app.templates.aboutPage = -> """
<ul> <ul>
<li><a href="https://devdocs.io">devdocs.io</a> ("App") is operated by <a href="https://www.freecodecamp.org/">freeCodeCamp</a> ("We"). <li><a href="https://devdocs.io">devdocs.io</a> ("App") is operated by <a href="https://www.freecodecamp.org/">freeCodeCamp</a> ("We").
<li>We do not collect personal information through the app. <li>We do not collect personal information through the app.
<li>We use Google Analytics, Gauges and Sentry to collect anonymous traffic information and improve the app. <li>We use Google Analytics and Gauges to collect anonymous traffic information if you have given consent to this. You can change your decision in the <a href="/settings">settings</a>.
<li>We use Sentry to collect crash data and improve the app.
<li>The app uses cookies to store user preferences. <li>The app uses cookies to store user preferences.
<li>By using the app, you signify your acceptance of this policy. If you do not agree to this policy, please do not use the app. <li>By using the app, you signify your acceptance of this policy. If you do not agree to this policy, please do not use the app.
<li>If you have any questions regarding privacy, please email <a href="mailto:privacy@freecodecamp.org">privacy@freecodecamp.org</a>. <li>If you have any questions regarding privacy, please email <a href="mailto:privacy@freecodecamp.org">privacy@freecodecamp.org</a>.

@ -15,6 +15,10 @@ app.templates.settingsPage = (settings) -> """
<input type="checkbox" form="settings" name="layout" value="_sidebar-hidden"#{if settings['_sidebar-hidden'] then ' checked' else ''}>Automatically hide and show the sidebar <input type="checkbox" form="settings" name="layout" value="_sidebar-hidden"#{if settings['_sidebar-hidden'] then ' checked' else ''}>Automatically hide and show the sidebar
<small>Tip: drag the edge of the sidebar to resize it.</small> <small>Tip: drag the edge of the sidebar to resize it.</small>
</label> </label>
<label class="_settings-label">
<input type="checkbox" form="settings" name="analyticsConsent"#{if settings.analyticsConsent then ' checked' else ''}>Enable tracking cookies
<small>With this checked, we enable Google Analytics and Gauges to collect anonymous traffic information.</small>
</label>
</div> </div>
</div> </div>

@ -1,28 +1,32 @@
try { try {
if (app.config.env == 'production') { if (app.config.env === 'production') {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ if (Cookies.get('analyticsConsent') === '1') {
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
ga('create', 'UA-5544833-12', 'devdocs.io'); })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
page.track(function() { ga('create', 'UA-5544833-12', 'devdocs.io');
ga('send', 'pageview', { page.track(function() {
page: location.pathname + location.search + location.hash, ga('send', 'pageview', {
dimension1: app.router.context && app.router.context.doc && app.router.context.doc.slug_without_version page: location.pathname + location.search + location.hash,
dimension1: app.router.context && app.router.context.doc && app.router.context.doc.slug_without_version
});
}); });
});
page.track(function() { page.track(function() {
if (window._gauges) if (window._gauges)
_gauges.push(['track']); _gauges.push(['track']);
else else
(function() { (function() {
var _gauges=_gauges||[];!function(){var a=document.createElement("script"); var _gauges=_gauges||[];!function(){var a=document.createElement("script");
a.type="text/javascript",a.async=!0,a.id="gauges-tracker", a.type="text/javascript",a.async=!0,a.id="gauges-tracker",
a.setAttribute("data-site-id","51c15f82613f5d7819000067"), a.setAttribute("data-site-id","51c15f82613f5d7819000067"),
a.src="https://secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0]; a.src="https://secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0];
b.parentNode.insertBefore(a,b)}(); b.parentNode.insertBefore(a,b)}();
})(); })();
}); });
} else {
resetAnalytics();
}
} }
} catch(e) { } } catch(e) { }

@ -14,6 +14,7 @@ class app.views.SettingsPage extends app.View
settings.dark = app.settings.get('dark') settings.dark = app.settings.get('dark')
settings.smoothScroll = !app.settings.get('fastScroll') settings.smoothScroll = !app.settings.get('fastScroll')
settings.arrowScroll = app.settings.get('arrowScroll') settings.arrowScroll = app.settings.get('arrowScroll')
settings.analyticsConsent = app.settings.get('analyticsConsent')
settings[layout] = app.settings.hasLayout(layout) for layout in app.settings.LAYOUTS settings[layout] = app.settings.hasLayout(layout) for layout in app.settings.LAYOUTS
settings settings
@ -32,6 +33,11 @@ class app.views.SettingsPage extends app.View
app.settings.set('fastScroll', !enable) app.settings.set('fastScroll', !enable)
return return
toggleAnalyticsConsent: (enable) ->
app.settings.set('analyticsConsent', if enable then '1' else '0')
resetAnalytics() unless enable
return
toggle: (name, enable) -> toggle: (name, enable) ->
app.settings.set(name, enable) app.settings.set(name, enable)
return return
@ -75,6 +81,8 @@ class app.views.SettingsPage extends app.View
@toggleSmoothScroll input.checked @toggleSmoothScroll input.checked
when 'import' when 'import'
@import input.files[0], input @import input.files[0], input
when 'analyticsConsent'
@toggleAnalyticsConsent input.checked
else else
@toggle input.name, input.checked @toggle input.name, input.checked
return return

@ -75,9 +75,11 @@ class app.views.Document extends app.View
return unless target.hasAttribute('data-behavior') return unless target.hasAttribute('data-behavior')
$.stopEvent(event) $.stopEvent(event)
switch target.getAttribute('data-behavior') switch target.getAttribute('data-behavior')
when 'back' then history.back() when 'back' then history.back()
when 'reload' then window.location.reload() when 'reload' then window.location.reload()
when 'reboot' then app.reboot() when 'reboot' then app.reboot()
when 'hard-reload' then app.reload() when 'hard-reload' then app.reload()
when 'reset' then app.reset() if confirm('Are you sure you want to reset DevDocs?') when 'reset' then app.reset() if confirm('Are you sure you want to reset DevDocs?')
when 'accept-analytics' then Cookies.set('analyticsConsent', '1') && app.reboot()
when 'decline-analytics' then Cookies.set('analyticsConsent', '0') && app.reboot()
return return

@ -134,3 +134,7 @@
._notif-info { color: var(--textColorLight); } ._notif-info { color: var(--textColorLight); }
} }
._notif-right {
float: right;
}

Loading…
Cancel
Save