Skip to content

Commit 83cc93c

Browse files
committed
Replace TrustArc cookie consent with OneTrust
1 parent 6285677 commit 83cc93c

File tree

4 files changed

+77
-20
lines changed

4 files changed

+77
-20
lines changed

server.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const express = require("express");
22
const enforce = require("express-sslify");
33
const languages = require("./libraries.json");
4+
const dotenv = require("dotenv").config();
45

56
const app = express();
67

@@ -17,7 +18,10 @@ if (process.env.NODE_ENV === "production") {
1718
);
1819
}
1920

20-
// app.use(fetchGithubStars);
21+
app.use((req, res, next) => {
22+
res.locals.COOKIE_CONSENT_DOMAIN_ID = process.env.COOKIE_CONSENT_DOMAIN_ID;
23+
next();
24+
});
2125
app.use(express.static("dist/website"));
2226
app.get("/", function(req, res) {
2327
res.render("index");
@@ -28,7 +32,9 @@ app.get("/introduction", function(req, res) {
2832
});
2933

3034
app.get("/libraries", function(req, res) {
31-
res.render("libraries", { languages: languages });
35+
res.render("libraries", {
36+
languages: languages
37+
});
3238
});
3339

3440
// Fallback for the homepage JWT handbook CTA A/B experiment we ran

src/cookie-consent.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const COOKIE_CONSENT_NECESSARY = 1;
2+
const COOKIE_CONSENT_PERFORMANCE = 2;
3+
const COOKIE_CONSENT_FUNCTIONAL = 3;
4+
const COOKIE_CONSENT_ADVERTISING = 4;
5+
6+
function addScripts(lvl) {
7+
//Reject all
8+
if (!lvl) {
9+
return;
10+
}
11+
12+
// Necessary
13+
if (lvl.includes(COOKIE_CONSENT_NECESSARY)) {
14+
// GTM
15+
(function(w, d, s, l, i) {
16+
w[l] = w[l] || [];
17+
w[l].push({
18+
'gtm.start': new Date().getTime(),
19+
event: 'gtm.js'
20+
});
21+
var f = d.getElementsByTagName(s)[0],
22+
j = d.createElement(s),
23+
dl = l != 'dataLayer' ? '&l=' + l : '';
24+
j.async = true;
25+
j.src =
26+
'//www.googletagmanager.com/gtm.js?id=' + i + dl;
27+
f.parentNode.insertBefore(j, f);
28+
})(window, document, 'script', 'dataLayer', 'GTM-W7FRLJ');
29+
}
30+
31+
// Functional
32+
if (lvl.includes(COOKIE_CONSENT_FUNCTIONAL)) {
33+
(function(d, s, id) {
34+
var js, fjs = d.getElementsByTagName(s)[0],
35+
p = /^http:/.test(d.location) ? 'http' : 'https';
36+
if (!d.getElementById(id)) {
37+
js = d.createElement(s);
38+
js.id = id;
39+
js.src = p + '://platform.twitter.com/widgets.js';
40+
fjs.parentNode.insertBefore(js, fjs);
41+
}
42+
})(document, 'script', 'twitter-wjs');
43+
}
44+
}
45+
46+
// Add required scripts without waiting for the user consent
47+
addScripts(window.OnetrustActiveGroups);
48+
49+
// Poll for the consent being onscreen.
50+
const POLL_MAX = 10;
51+
const POLL_INTERVAL = 200;
52+
let tries = 0;
53+
const poll = window.setInterval(() => {
54+
if (tries >= POLL_MAX) {
55+
addScripts(window.OnetrustActiveGroups)
56+
return window.clearInterval(poll);
57+
}
58+
59+
if (document.getElementById("onetrust-accept-btn-handler")) {
60+
window.OneTrust.OnConsentChanged(() => addScripts(window.OnetrustActiveGroups));
61+
return window.clearInterval(poll);
62+
} else {
63+
tries++;
64+
}
65+
}, POLL_INTERVAL);

views/website/layout.pug

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,10 @@ html(lang='en')
3838
// Chrome extension link, required for inline installs
3939
link(rel="chrome-webstore-item", href="https://chrome.google.com/webstore/detail/ppmmlchacdbknfphdeafcbmklcghghmd")
4040

41-
// Google Tag Manager
42-
script.
43-
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
44-
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
45-
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
46-
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
47-
})(window,document,'script','dataLayer','GTM-W7FRLJ');
48-
// End Google Tag Manager
49-
5041
body
5142
// Google Tag Manager (noscript)
5243
noscript
5344
iframe(src='https://www.googletagmanager.com/ns.html?id=GTM-W7FRLJ', height='0', width='0', style='display:none;visibility:hidden')
54-
// End Google Tag Manager (noscript)
5545

5646
include ./navigation.pug
5747

@@ -72,11 +62,6 @@ html(lang='en')
7262
.column.social-counter
7363
a.twitter-follow-button(href='https://twitter.com/auth0', data-show-count='true') Follow @auth0
7464

75-
script.
76-
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');
77-
7865
if process.env.NODE_ENV === "production"
79-
div
80-
div(id="consent_blackbar")
81-
div(id="teconsent" style="position: absolute; bottom: -100px;")
82-
script(async="async" src="//consent.trustarc.com/notice?domain=auth0banner.com&c=teconsent&js=nj&noticeType=bb&text=true" crossOrigin)
66+
script(src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js", type="text/javascript", charset="UTF-8", data-domain-script=COOKIE_CONSENT_DOMAIN_ID, id="consent-script")
67+
script(src="/js/cookie-consent.js")

webpack.website-dev.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = merge(common, {
88
entry: {
99
index: './src/website/index.js',
1010
introduction: './src/website/introduction/index.js',
11-
libraries: './src/website/libraries/index.js'
11+
libraries: './src/website/libraries/index.js',
12+
"cookie-consent": './src/cookie-consent.js'
1213
},
1314
output: {
1415
filename: '[name].js',

0 commit comments

Comments
 (0)