| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230 |
| import { h, render } from 'preact';
import Modal from '../modal/Modal';
import { debug, isParameterSet, parseUrl } from '../shared/utils';
import { API_STATUS } from './ConsentManagementProvider';
class ConsentManagementPlatform {
constructor(
tracker,
cookieManager,
optInManager,
geoManager,
contentManager,
consentManagementProvider,
options,
location
) {
this.tracker = tracker;
this.cookieManager = cookieManager;
this.optInManager = optInManager;
this.geoManager = geoManager;
this.contentManager = contentManager;
this.consentManagementProvider = consentManagementProvider;
this.options = options;
this.location = location;
this.isReset = false;
}
removeApp = () => {
if (this.root) {
render(null, this.root, this.root.lastChild);
this.root.parentNode.removeChild(this.root);
this.root = null;
}
};
// Non-IAB tracking is accepted. Some or all IAB vendors or purposes _may_ be accepted
onAcceptTracking = (allowedVendors, allowedPurposes, allowedSpecialFeatures, allowedProviders) => {
this.consentManagementProvider.configure({
allowedVendors: allowedVendors,
allowedProviders: allowedProviders,
allowedVendorPurposes: allowedPurposes,
allowedSpecialFeatures: allowedSpecialFeatures
});
this.consentManagementProvider.install().then(() => {
this.options.onAcceptTracking(allowedVendors, allowedPurposes);
this.options.onConsentsReady();
});
this.cookieManager.setSessionCookiesOnAccept();
};
// Non-IAB tracking is rejected. Some or all IAB vendors or purposes _may_ be accepted
onRejectTracking = (allowedVendors, allowedPurposes, allowedSpecialFeatures, allowedProviders) => {
this.consentManagementProvider.configure({
allowedVendors: allowedVendors,
allowedProviders: allowedProviders,
allowedVendorPurposes: allowedPurposes,
allowedSpecialFeatures: allowedSpecialFeatures
});
this.consentManagementProvider.install().then(() => {
this.options.onRejectTracking(allowedVendors, allowedPurposes);
this.options.onConsentsReady();
});
};
getConsent() {
// Nothing is needed if the geo does not require any consent
if (!this.geoRequiresTrackingConsent()) {
return {
gdprConsent: true,
geoRequiresConsent: false,
};
}
if (this.hasUserConsented() === undefined) {
return {
gdprConsent: false,
geoRequiresConsent: true,
};
}
const gdprConsent = this.hasUserConsented();
debug('GDPR', 'User consent', gdprConsent);
return {
gdprConsent,
geoRequiresConsent: true,
};
}
hasUserConsented() {
const hasConsentCookie = this.consentManagementProvider.hasUserConsent() || isParameterSet('mobile-app');
if (this.isOnWhiteListedPage()) {
return false;
} else if (!this.geoRequiresTrackingConsent()) {
return true;
} else if (this.isGpcEnabled()) {
return false;
} else if (hasConsentCookie && this.optInManager.hasAcceptedTracking()) {
return true;
} else if (hasConsentCookie && this.optInManager.hasRejectedTracking()) {
return false;
} else if (!this.geoManager.hasGeoCookie()) {
return false;
}
return undefined;
}
isOnWhiteListedPage() {
const { host, pathname, search } = this.location;
if (this.isReset || search.includes('withdrawConsent=true')) {
return false;
}
const { content } = this.contentManager;
const privacyParsedUrl = parseUrl(content.privacyPolicyUrl);
const partnerParsedUrl = parseUrl(content.partnerListUrl);
if (privacyParsedUrl.hostname === host && pathname === privacyParsedUrl.pathname) {
return true;
} else if (partnerParsedUrl.hostname === host && pathname === partnerParsedUrl.pathname) {
return true;
}
return false;
}
geoRequiresTrackingConsent() {
return this.geoManager.hasSpecialPrivacyLaw();
}
reset() {
this.isReset = true;
this.clear();
this.consentManagementProvider.installStub();
this.render();
}
clear() {
this.optInManager.clear();
this.consentManagementProvider.uninstall();
}
render() {
if (!this.root) {
this.root = document.createElement('div');
document.body.appendChild(this.root);
}
this.consentManagementProvider.configure({
gdprApplies: this.geoRequiresTrackingConsent(),
});
this.consentManagementProvider.initialize();
this.consentManagementProvider.loadVendorList()
.then(() => this.contentManager.fetchTranslations())
.then(() => {
if (this.consentManagementProvider.isVendorTCFPolicyVersionOutdated()) {
this.consentManagementProvider.setVendorConsentCookie(null);
}
this.checkUserConsent();
});
if (this.isGpcEnabled()) {
this.tracker.trackGpcImpression();
}
}
checkUserConsent() {
switch (this.hasUserConsented()) {
case true:
this.onAcceptTracking();
break;
case false:
if (this.isGpcEnabled()) {
this.onRejectTracking([], [], [], []);
} else {
this.onRejectTracking();
}
break;
default:
if (!isParameterSet('mobile-app')) {
this.renderModal();
}
}
}
renderModal() {
const options = {
// ToDo: get rid of hardcoded list of purposes during cleanup
enabledPurposes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
enabledVendors: this.options.enabledVendors,
enabledProviders: this.options.enabledProviders,
enabledSpecialFeatures: [1, 2],
zIndex: this.options.zIndex,
preventScrollOn: this.options.preventScrollOn,
isCurse: this.options.isCurse,
};
this.consentManagementProvider.updateApi(API_STATUS.UI_VISIBLE_NEW);
import(/* webpackChunkName: "gdpr-modal" */ '../modal/Modal').then(({ default: Modal }) => {
render(
<Modal
onRequestAppRemove={this.removeApp}
onAcceptTracking={this.onAcceptTracking}
onRejectTracking={this.onRejectTracking}
tracker={this.tracker}
optInManager={this.optInManager}
geoManager={this.geoManager}
options={options}
content={this.contentManager.content}
language={this.contentManager.language}
/>,
this.root,
this.root.lastChild
);
});
}
isGpcEnabled() {
return window.navigator && window.navigator.globalPrivacyControl;
}
}
export default ConsentManagementPlatform;
|