Skip to content

Commit

Permalink
GDPR Changes (#337)
Browse files Browse the repository at this point in the history
- Added notification when user first visits the site
- Notification provides options to opt-out of analytics
- Notification can be redisplayed by clicking on the "Privacy" link at the bottom of every page
- Client-only cookie used to maintain user setting.

- Removed non-essential npm bundles.
- Dev environment contains one vulnerability due to transitive dependency (less). This dependency is only used when generating the static site and is required.
  • Loading branch information
aricart authored May 4, 2018
1 parent 67d5638 commit 365f09d
Show file tree
Hide file tree
Showing 9 changed files with 3,468 additions and 8,024 deletions.
2 changes: 0 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ pygmentsCodeFences = "true"
pygmentsUseClasses = "true"
pygmentsStyle = "native"

googleAnalytics = "UA-111730698-1"

[params]
leftNav = false
description = "NATS is a high performance messaging system that acts as a distributed messaging queue for cloud native applications, IoT device messaging, and microservices architecture."
Expand Down
34 changes: 15 additions & 19 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
var gulp = require('gulp'),
// plumber = require('gulp-plumber'),
// debug = require('gulp-debug'),
concat = require('gulp-concat'),
// rename = require('gulp-rename'),
watch = require('gulp-watch'),
// watch = require('gulp-watch'),
less = require('gulp-less'),
uglify = require('gulp-uglify'),
minifyCSS = require('gulp-minify-css'),
minifyCSS = require('gulp-clean-css'),
gm = require('gulp-gm'),
imageResize = require('gulp-image-resize'),
// gulpif = require('gulp-if'),
autoprefixer = require('gulp-autoprefixer'),
sourcemaps = require('gulp-sourcemaps'),
clean = require('gulp-clean'),
Expand Down Expand Up @@ -95,25 +91,25 @@ gulp.task('clean', function() {
// HUGO
gulp.task('hugo', shell.task('hugo'));

// Watch
gulp.task('watch', function() {
gulp.watch('src/less/**/*.less', [ 'less' ]);
gulp.watch('src/js/**/*.js', [ 'js' ]);
gulp.watch('src/img/**/*', [ 'img' ]);
gulp.watch('src/font/**/*', [ 'font' ]);
gulp.watch('src/user_logos/**/*', [ 'userLogos' ]);
gulp.watch('src/partner_logos/**/*', [ 'partnerLogos' ]);
gulp.watch('src/company_logos/**/*', [ 'companyLogos' ]);
gulp.watch('src/blog/**/*', [ 'blogImages' ]);
gulp.watch('src/blog/**/*', [ 'blogImagesGifs' ]);
});
// // Watch
// gulp.task('watch', function() {
// gulp.watch('src/less/**/*.less', [ 'less' ]);
// gulp.watch('src/js/**/*.js', [ 'js' ]);
// gulp.watch('src/img/**/*', [ 'img' ]);
// gulp.watch('src/font/**/*', [ 'font' ]);
// gulp.watch('src/user_logos/**/*', [ 'userLogos' ]);
// gulp.watch('src/partner_logos/**/*', [ 'partnerLogos' ]);
// gulp.watch('src/company_logos/**/*', [ 'companyLogos' ]);
// gulp.watch('src/blog/**/*', [ 'blogImages' ]);
// gulp.watch('src/blog/**/*', [ 'blogImagesGifs' ]);
// });

gulp.task('help', function(){
console.log('if gulp build fails, simply add ".pipe(plumber())" to the task to see the error');
});

// Default Task
gulp.task('default', [ 'less', 'js', 'img', 'font', 'docsImages', 'userLogos', 'partnerLogos', 'blogImages', 'blogImagesGifs', 'watch' ]);
// gulp.task('default', [ 'less', 'js', 'img', 'font', 'docsImages', 'userLogos', 'partnerLogos', 'blogImages', 'blogImagesGifs', 'watch' ]);

// Build for Production
gulp.task('build', function (callback) {
Expand Down
7 changes: 4 additions & 3 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a target="_blank" href="https://www.reddit.com/r/NATS_io/"><i class="icon icon-reddit"></i></a>
</p>
<p>NATS is <a href="https://github.com/nats-io/gnatsd" target="_blank">open-source
software</a>, as is <a href="https://github.com/nats-io/nats-site" target="_blank">this site</a>.
software</a>, as is <a href="https://github.com/nats-io/nats-site" target="_blank">this site</a>. <a id="priv" class="dynamic" target="_blank">Privacy</a>.
</p>
</div>
<div class="col-xs-6 copyright">
Expand All @@ -31,9 +31,10 @@
</div>
</div>
</footer>
<!-- End Footer -->
{{ partial "gdpr.html" . }}

<!-- End Footer -->
{{ partial "js.html" . }}
</body>
</body>
</html>

99 changes: 99 additions & 0 deletions layouts/partials/gdpr.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<div id="gdpr" class="hide navbar-fixed-bottom footer">
<h3>Privacy Policy</h3>
We value and respect your privacy. Analytics is used to track consumers of our site and improve its content. We do
not share, nor sell data to third parties, nor link to any personal information on the collected data.
Thank you for your interest in NATS.
</p>
<form>
<div>
<div class="checkbox">
<label><input id="disable_analytics" value="true" type="checkbox">Disable analytics</label>
</div>
<span class="pull-right">
<button type="button" class="btn btn-success" onclick="gdprOK()">OK</button>
</span>
</div>
</form>
</div>

<script>
function getGAKey() {
return "UA-111730698-1";
}

function getGAKeyDisableKey() {
return "ga-disable-" + getGAKey();
}
function getCookie() {
var cookies = document.cookie;
var a = cookies.split(";");
return a.find(function (e) {
e = e.trim();
return e.startsWith("ga-disable=");
});
}

function updateCheckbox(tc) {
// set the state of the html to match in case the preview it
var checked = false;
if (tc) {
checked = tc.trim().split('=')[1] === "true";
}
$('#disable_analytics').prop('checked', checked);
}

function addGA() {
// now load google analytics script
if (!$('#gascript').length) {
var s = document.createElement('script', {async: '', id: 'gascript'});
s.type = 'text/javascript';
s.src = 'https://www.google-analytics.com/analytics.js';
$('body').append(s);
}
}

function checkTrack() {
var tc = getCookie();
updateCheckbox(tc);

// set it up early
var disable = $('#disable_analytics').is(':checked');
window[getGAKeyDisableKey()] = disable;

if (!tc) {
openPrivacy(tc);
} else {
var disable = tc.trim().split('=')[1] === "true";
// set a property on the window to disable ga
// https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out
window[getGAKeyDisableKey()] = disable;
addGA();
}
}

function openPrivacy(tc) {
var sel = $('#gdpr');
sel.removeClass('hide');
var height = sel.outerHeight();
$('body').css('padding-bottom', height + "px");
return false;
}


function oneYearFromNow() {
var d = new Date();
d.setFullYear(d.getFullYear() + 1);
return d;
}

function gdprOK() {
var disable = $('#disable_analytics').is(':checked');
window[getGAKeyDisableKey()] = disable;
$('#gdpr').addClass('hide');
$('body').css('padding-bottom', '0px');
var d = new Date();
d.setFullYear(d.getFullYear() + 1);
document.cookie = "ga-disable=" + disable + "; expires=" + oneYearFromNow().toUTCString() + "; path=/";
addGA();
}
</script>
3 changes: 2 additions & 1 deletion layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{{ end }}
</head>
<body id='{{ if isset .Params "cssid" }}{{ .Params.cssid }}{{ else if eq .Section "blog" }}blog-post{{ else if eq .Section "documentation" }}nats-documentation-detail{{ else if eq .Section "download" }}download{{ else if .IsHome }}home{{else}}{{ urlize .Title }}{{ end }}-page'>
<nav class='navbar navbar-default navbar-fixed-top{{if eq (relURL .URL) ("/" | safeHTML)}} home-page{{end}}'>
<nav class='navbar navbar-default navbar-fixed-top{{if eq (relURL .URL) ("/" | safeHTML)}} home-page{{end}}'>
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
Expand Down Expand Up @@ -86,3 +86,4 @@
</div><!--/.nav-collapse -->
</div>
</nav>

29 changes: 26 additions & 3 deletions layouts/partials/js.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

<script>
$(document).ready(function() {
checkTrack();
});

$('#priv').on('click', function(e) {
openPrivacy();
});

</script>


<script src="/js/index.js"></script>
<!-- Github Buttons -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
<!-- Google Analytics -->
{{ template "_internal/google_analytics.html" . }}


<!-- Google Analytics Configuration - scripts added dynamically after user opts in or out-->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', getGAKey(), {
cookieExpires: 0
});
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
Loading

0 comments on commit 365f09d

Please sign in to comment.