Skip to content

Commit e7420a9

Browse files
committed
use global variables to track consent
1 parent fc023e2 commit e7420a9

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

analytics.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class AnalyticsTracker {
1818
static EVENT_ID_NETWORK_REQUEST = 5000;
1919
static EVENT_ID_SEARCH_INPUT = 5001; // TODO change this after DAP update
2020

21+
static CONSENT_KEY = 'deepl_cookie_consent';
22+
static CONSENT_ACCEPTED = 'accepted';
23+
2124
static isProdStage = window.location.hostname === "developers.deepl.com";
2225
static statisticsUrl = this.isProdStage ?
2326
"https://s.deepl.com/web/statistics"
@@ -388,7 +391,7 @@ class AnalyticsTracker {
388391
// ========================
389392
static hasConsent() {
390393
// Check localStorage for consent
391-
return localStorage.getItem('deepl_cookie_consent') === 'accepted';
394+
return localStorage.getItem(this.CONSENT_KEY) === this.CONSENT_ACCEPTED;
392395
}
393396

394397
// ========================

cookie-banner.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
// Constants
2+
const CONSENT_KEY = 'deepl_cookie_consent';
3+
const CONSENT_ACCEPTED = 'accepted';
4+
const CONSENT_REJECTED = 'rejected';
5+
16
const showCookieBanner = () => {
27
// Check localStorage for consent
3-
const consent = localStorage.getItem('deepl_cookie_consent');
8+
const consent = localStorage.getItem(CONSENT_KEY);
49

510
// Only hide banner if user has explicitly accepted or rejected
6-
if (consent === 'accepted' || consent === 'rejected') return;
11+
if (consent === CONSENT_ACCEPTED || consent === CONSENT_REJECTED) return;
712

813
const banner = document.createElement('div');
914
banner.id = 'cookie-banner';
@@ -28,14 +33,14 @@ const showCookieBanner = () => {
2833
const rejectBtn = document.getElementById('cookie-reject');
2934

3035
acceptBtn.onclick = function () {
31-
localStorage.setItem('deepl_cookie_consent', 'accepted');
36+
localStorage.setItem(CONSENT_KEY, CONSENT_ACCEPTED);
3237
banner.remove();
3338
// Reload to enable telemetry
3439
window.location.reload();
3540
};
3641

3742
rejectBtn.onclick = function () {
38-
localStorage.setItem('deepl_cookie_consent', 'rejected');
43+
localStorage.setItem(CONSENT_KEY, CONSENT_REJECTED);
3944
banner.remove();
4045
};
4146
}

0 commit comments

Comments
 (0)