@mparticle/web-onetrust-kit 2.0.1 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OneTrustKit.common.js +248 -45
- package/package.json +35 -26
|
@@ -1,31 +1,73 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
3
|
/* eslint-disable no-undef */
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var CONSENT_REGULATIONS = {
|
|
5
|
+
GDPR: 'gdpr',
|
|
6
|
+
CCPA: 'ccpa'
|
|
7
|
+
};
|
|
8
|
+
var CCPA_PURPOSE = 'data_sale_opt_out';
|
|
7
9
|
|
|
8
10
|
var initialization = {
|
|
9
11
|
name: 'OneTrust',
|
|
10
12
|
moduleId: 134,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
consentMapping: {},
|
|
14
|
+
googleVendorConsentMapping: {},
|
|
15
|
+
iabVendorConsentMapping: {},
|
|
16
|
+
generalVendorConsentMapping: {},
|
|
17
|
+
getConsentGroupIds: function() {
|
|
18
|
+
return window.OnetrustActiveGroups
|
|
19
|
+
? window.OnetrustActiveGroups.split(',')
|
|
20
|
+
: [];
|
|
14
21
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
|
|
23
|
+
parseConsentMapping: function(rawConsentMapping) {
|
|
24
|
+
var _consentMapping = {};
|
|
25
|
+
if (rawConsentMapping) {
|
|
26
|
+
var parsedMapping = JSON.parse(rawConsentMapping.replace(/"/g, '\"'));
|
|
27
|
+
|
|
28
|
+
// TODO: [67837] Revise this to use an actual 'regulation' mapping if UI ever returns this
|
|
29
|
+
parsedMapping.forEach(function(mapping) {
|
|
30
|
+
var purpose = mapping.map;
|
|
31
|
+
_consentMapping[mapping.value] = {
|
|
32
|
+
purpose: purpose,
|
|
33
|
+
regulation: purpose === CCPA_PURPOSE ? CONSENT_REGULATIONS.CCPA : CONSENT_REGULATIONS.GDPR
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return _consentMapping;
|
|
18
39
|
},
|
|
40
|
+
|
|
19
41
|
initForwarder: function(forwarderSettings) {
|
|
20
42
|
var self = this;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
self.consentMapping = self.parseConsentMapping(
|
|
44
|
+
forwarderSettings.consentGroups
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
self.googleVendorConsentMapping = self.parseConsentMapping(
|
|
48
|
+
forwarderSettings.vendorGoogleConsentGroups
|
|
49
|
+
);
|
|
50
|
+
self.iabVendorConsentMapping = self.parseConsentMapping(
|
|
51
|
+
forwarderSettings.vendorIABConsentGroups
|
|
52
|
+
);
|
|
53
|
+
self.generalVendorConsentMapping = self.parseConsentMapping(
|
|
54
|
+
forwarderSettings.vendorGeneralConsentGroups
|
|
55
|
+
);
|
|
56
|
+
// Wrap exisitng OptanonWrapper in case customer is using
|
|
57
|
+
// it for something custom so we can hijack
|
|
58
|
+
var OptanonWrapperCopy = window.OptanonWrapper;
|
|
59
|
+
|
|
60
|
+
window.OptanonWrapper = function () {
|
|
61
|
+
if (window.Optanon && window.Optanon.OnConsentChanged) {
|
|
62
|
+
window.Optanon.OnConsentChanged(function() {
|
|
63
|
+
self.createConsentEvents();
|
|
64
|
+
self.createVendorConsentEvents();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Run original OptanonWrapper()
|
|
69
|
+
OptanonWrapperCopy();
|
|
70
|
+
};
|
|
29
71
|
},
|
|
30
72
|
createConsentEvents: function () {
|
|
31
73
|
if (window.Optanon) {
|
|
@@ -40,9 +82,10 @@ var initialization = {
|
|
|
40
82
|
if (!consentState) {
|
|
41
83
|
consentState = mParticle.Consent.createConsentState();
|
|
42
84
|
}
|
|
43
|
-
for (var key in consentMapping) {
|
|
44
|
-
var consentPurpose = consentMapping[key];
|
|
45
|
-
var
|
|
85
|
+
for (var key in this.consentMapping) {
|
|
86
|
+
var consentPurpose = this.consentMapping[key].purpose;
|
|
87
|
+
var regulation = this.consentMapping[key].regulation;
|
|
88
|
+
var consentBoolean = false;
|
|
46
89
|
|
|
47
90
|
// removes all non-digits
|
|
48
91
|
// 1st version of OneTrust required a selection from group1, group2, etc
|
|
@@ -50,35 +93,191 @@ var initialization = {
|
|
|
50
93
|
key = key.replace(/\D/g, '');
|
|
51
94
|
}
|
|
52
95
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
96
|
+
consentBoolean = (this.getConsentGroupIds().indexOf(key) > -1);
|
|
97
|
+
|
|
98
|
+
// At present, only CCPA and GDPR are known regulations
|
|
99
|
+
// Using a switch in case a new regulation is added in the future
|
|
100
|
+
switch (regulation) {
|
|
101
|
+
case CONSENT_REGULATIONS.CCPA:
|
|
102
|
+
consent = mParticle.Consent.createCCPAConsent(consentBoolean, Date.now(), consentPurpose, location);
|
|
103
|
+
consentState.setCCPAConsentState(consent);
|
|
104
|
+
break;
|
|
105
|
+
case CONSENT_REGULATIONS.GDPR:
|
|
106
|
+
consent = mParticle.Consent.createGDPRConsent(consentBoolean, Date.now(), consentPurpose, location);
|
|
107
|
+
consentState.addGDPRConsentState(consentPurpose, consent);
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
console.error('Unknown Consent Regulation', regulation);
|
|
57
111
|
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
user.setConsentState(consentState);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
createVendorConsentEvents: function() {
|
|
120
|
+
var self = this;
|
|
121
|
+
if (window.OneTrust && window.OneTrust.getVendorConsentsRequestV2) {
|
|
122
|
+
var location = window.location.href,
|
|
123
|
+
consentState,
|
|
124
|
+
user = mParticle.Identity.getCurrentUser();
|
|
125
|
+
|
|
126
|
+
if (user) {
|
|
127
|
+
consentState = user.getConsentState();
|
|
58
128
|
|
|
59
|
-
|
|
60
|
-
consentState.
|
|
129
|
+
if (!consentState) {
|
|
130
|
+
consentState = mParticle.Consent.createConsentState();
|
|
61
131
|
}
|
|
62
132
|
|
|
133
|
+
OneTrust.getVendorConsentsRequestV2(function(
|
|
134
|
+
oneTrustVendorConsent
|
|
135
|
+
) {
|
|
136
|
+
// oneTrustVendorConsent object is in the shape of
|
|
137
|
+
// {
|
|
138
|
+
// ...
|
|
139
|
+
// addtlConsent:
|
|
140
|
+
// '1~39.43.46.55.61.70.83.89.93.108.117.122.124.131',
|
|
141
|
+
// vendor: {
|
|
142
|
+
// consents: '10100111011' //
|
|
143
|
+
// },
|
|
144
|
+
// ...
|
|
145
|
+
// };
|
|
146
|
+
//
|
|
147
|
+
// Google Vendors are in addtlConsent - to the right of
|
|
148
|
+
// "1~" are ids for which Google Vendor the user has consented,
|
|
149
|
+
// ie. 39, 43, 46, etc, but not 1, 2, 3 which are not in this list
|
|
150
|
+
//
|
|
151
|
+
// IAB Vendors are in vendor.consents
|
|
152
|
+
// 1 = consented, 0 = rejected. The index+1 is the IAB Vendor ID
|
|
153
|
+
// ie. If IAB ID is 5, the index is 4 in the consent string
|
|
154
|
+
// to the left, or 0 (rejected))
|
|
155
|
+
setGoogleVendorRequests(
|
|
156
|
+
oneTrustVendorConsent,
|
|
157
|
+
self.googleVendorConsentMapping,
|
|
158
|
+
consentState,
|
|
159
|
+
location
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
setIABVendorRequests(
|
|
163
|
+
oneTrustVendorConsent,
|
|
164
|
+
self.iabVendorConsentMapping,
|
|
165
|
+
consentState,
|
|
166
|
+
location
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
setGeneralVendorRequests(
|
|
170
|
+
// general vendor consent is on the OptAnonActiveGroups string, similar to GDPR consent
|
|
171
|
+
self.getConsentGroupIds(),
|
|
172
|
+
self.generalVendorConsentMapping,
|
|
173
|
+
consentState,
|
|
174
|
+
location
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
63
178
|
user.setConsentState(consentState);
|
|
64
179
|
}
|
|
65
180
|
}
|
|
66
|
-
}
|
|
181
|
+
},
|
|
67
182
|
};
|
|
68
183
|
|
|
69
|
-
function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
184
|
+
function setGoogleVendorRequests(
|
|
185
|
+
oneTrustVendorConsent,
|
|
186
|
+
googleVendorConsentMapping,
|
|
187
|
+
consentState,
|
|
188
|
+
location
|
|
189
|
+
) {
|
|
190
|
+
try {
|
|
191
|
+
// turn Google Vendor Consent string into an array of IDs
|
|
192
|
+
var googleConsentedVendors = oneTrustVendorConsent
|
|
193
|
+
? oneTrustVendorConsent.addtlConsent
|
|
194
|
+
.slice()
|
|
195
|
+
.split('~')[1]
|
|
196
|
+
.split('.')
|
|
197
|
+
: null;
|
|
198
|
+
|
|
199
|
+
if (googleConsentedVendors && googleConsentedVendors.length) {
|
|
200
|
+
for (var vendorId in googleVendorConsentMapping) {
|
|
201
|
+
var consentPurpose = googleVendorConsentMapping[vendorId].purpose;
|
|
202
|
+
// consent is true if the vendor id is in the array of consented IDs
|
|
203
|
+
var consentBoolean = googleConsentedVendors.indexOf(vendorId) > -1;
|
|
204
|
+
var consent = mParticle.Consent.createGDPRConsent(
|
|
205
|
+
consentBoolean,
|
|
206
|
+
Date.now(),
|
|
207
|
+
consentPurpose,
|
|
208
|
+
location
|
|
209
|
+
);
|
|
210
|
+
consentState.addGDPRConsentState(consentPurpose, consent);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {
|
|
214
|
+
console.error(
|
|
215
|
+
'There was a problem setting Google Vendor Consents: ',
|
|
216
|
+
e
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function setIABVendorRequests(
|
|
222
|
+
oneTrustVendorConsent,
|
|
223
|
+
IABVendorConsentMappings,
|
|
224
|
+
consentState,
|
|
225
|
+
location
|
|
226
|
+
) {
|
|
227
|
+
try {
|
|
228
|
+
var IABConsentedVendors = oneTrustVendorConsent
|
|
229
|
+
? oneTrustVendorConsent.vendor.consents
|
|
230
|
+
: null;
|
|
231
|
+
|
|
232
|
+
for (var vendorIndex in IABVendorConsentMappings) {
|
|
233
|
+
var consentPurpose = IABVendorConsentMappings[vendorIndex].purpose;
|
|
234
|
+
// consent is true if the (vendorIndex - 1) is 1
|
|
235
|
+
var consentBoolean = IABConsentedVendors[parseInt(vendorIndex) - 1] === '1';
|
|
236
|
+
var consent = mParticle.Consent.createGDPRConsent(
|
|
237
|
+
consentBoolean,
|
|
238
|
+
Date.now(),
|
|
239
|
+
consentPurpose,
|
|
240
|
+
location
|
|
241
|
+
);
|
|
242
|
+
consentState.addGDPRConsentState(consentPurpose, consent);
|
|
243
|
+
}
|
|
244
|
+
} catch (e) {
|
|
245
|
+
console.error('There was a problem setting IAB Vendor Consents: ', e);
|
|
75
246
|
}
|
|
247
|
+
}
|
|
76
248
|
|
|
77
|
-
|
|
249
|
+
function setGeneralVendorRequests(
|
|
250
|
+
oneTrustVendorConsent,
|
|
251
|
+
generalVendorConsentMapping,
|
|
252
|
+
consentState,
|
|
253
|
+
location
|
|
254
|
+
) {
|
|
255
|
+
try {
|
|
256
|
+
if (window.Optanon) {
|
|
257
|
+
for (var vendorId in generalVendorConsentMapping) {
|
|
258
|
+
var consentPurpose = generalVendorConsentMapping[vendorId].purpose;
|
|
259
|
+
// consent is true if the vendorId is in the oneTrustVendorConsent array
|
|
260
|
+
var consentBoolean = oneTrustVendorConsent.indexOf(vendorId) > -1;
|
|
261
|
+
var consent = mParticle.Consent.createGDPRConsent(
|
|
262
|
+
consentBoolean,
|
|
263
|
+
Date.now(),
|
|
264
|
+
consentPurpose,
|
|
265
|
+
location
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
consentState.addGDPRConsentState(consentPurpose, consent);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
} catch (e) {
|
|
272
|
+
console.error(
|
|
273
|
+
'There was a problem setting General Vendor Consents: ',
|
|
274
|
+
e
|
|
275
|
+
);
|
|
276
|
+
}
|
|
78
277
|
}
|
|
79
278
|
|
|
80
279
|
var initialization_1 = {
|
|
81
|
-
initialization: initialization
|
|
280
|
+
initialization: initialization,
|
|
82
281
|
};
|
|
83
282
|
|
|
84
283
|
//
|
|
@@ -118,6 +317,7 @@ var Initialization = initialization_1.initialization;
|
|
|
118
317
|
}
|
|
119
318
|
|
|
120
319
|
Initialization.createConsentEvents();
|
|
320
|
+
Initialization.createVendorConsentEvents();
|
|
121
321
|
}
|
|
122
322
|
}
|
|
123
323
|
|
|
@@ -125,12 +325,13 @@ var Initialization = initialization_1.initialization;
|
|
|
125
325
|
if (isInitialized) {
|
|
126
326
|
try {
|
|
127
327
|
Initialization.createConsentEvents();
|
|
328
|
+
Initialization.createVendorConsentEvents();
|
|
128
329
|
} catch (e) {
|
|
129
330
|
return {error: 'Error setting user identity on forwarder ' + name + '; ' + e};
|
|
130
331
|
}
|
|
131
332
|
}
|
|
132
333
|
else {
|
|
133
|
-
return 'Can\'t set new user identities on forwader
|
|
334
|
+
return 'Can\'t set new user identities on forwader ' + name + ', not initialized';
|
|
134
335
|
}
|
|
135
336
|
}
|
|
136
337
|
|
|
@@ -151,12 +352,12 @@ var Initialization = initialization_1.initialization;
|
|
|
151
352
|
|
|
152
353
|
function register(config) {
|
|
153
354
|
if (!config) {
|
|
154
|
-
|
|
355
|
+
console.log('You must pass a config object to register the kit ' + name);
|
|
155
356
|
return;
|
|
156
357
|
}
|
|
157
358
|
|
|
158
359
|
if (!isObject(config)) {
|
|
159
|
-
|
|
360
|
+
console.log('\'config\' must be an object. You passed in a ' + typeof config);
|
|
160
361
|
return;
|
|
161
362
|
}
|
|
162
363
|
|
|
@@ -170,15 +371,17 @@ var Initialization = initialization_1.initialization;
|
|
|
170
371
|
constructor: constructor
|
|
171
372
|
};
|
|
172
373
|
}
|
|
173
|
-
|
|
374
|
+
console.log('Successfully registered ' + name + ' to your mParticle configuration');
|
|
174
375
|
}
|
|
175
376
|
|
|
176
|
-
if (
|
|
177
|
-
window.mParticle.addForwarder
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
377
|
+
if (typeof window !== 'undefined') {
|
|
378
|
+
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
379
|
+
window.mParticle.addForwarder({
|
|
380
|
+
name: name,
|
|
381
|
+
constructor: constructor,
|
|
382
|
+
getId: getId
|
|
383
|
+
});
|
|
384
|
+
}
|
|
182
385
|
}
|
|
183
386
|
|
|
184
387
|
var oneTrustWrapper = {
|
package/package.json
CHANGED
|
@@ -1,28 +1,37 @@
|
|
|
1
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
|
-
|
|
2
|
+
"name": "@mparticle/web-onetrust-kit",
|
|
3
|
+
"version": "2.0.4",
|
|
4
|
+
"author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
|
|
5
|
+
"description": "mParticle integration sdk for OneTrust",
|
|
6
|
+
"browser": "dist/OneTrustKit.common.js",
|
|
7
|
+
"main": "dist/OneTrustKit.common.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/OneTrustKit.common.js"
|
|
10
|
+
],
|
|
11
|
+
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-onetrust",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "rollup --config rollup.config.js",
|
|
14
|
+
"watch": "rollup --config rollup.config.js -w",
|
|
15
|
+
"test": "node test/boilerplate/test-karma.js"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"chai": "^4.2.0",
|
|
19
|
+
"karma": "^6.3.4",
|
|
20
|
+
"karma-chai": "^0.1.0",
|
|
21
|
+
"karma-chrome-launcher": "^3.1.0",
|
|
22
|
+
"karma-firefox-launcher": "^1.3.0",
|
|
23
|
+
"karma-mocha": "^2.0.1",
|
|
24
|
+
"mocha": "^9.0.2",
|
|
25
|
+
"rollup": "^1.13.1",
|
|
26
|
+
"rollup-plugin-commonjs": "^10.0.0",
|
|
27
|
+
"rollup-plugin-node-resolve": "^5.0.1",
|
|
28
|
+
"shelljs": "^0.8.4",
|
|
29
|
+
"should": "^7.1.0",
|
|
30
|
+
"watchify": "^4.0.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"isobject": "^4.0.0",
|
|
34
|
+
"@mparticle/web-sdk": "^2.11.15"
|
|
35
|
+
},
|
|
36
|
+
"license": "Apache-2.0"
|
|
28
37
|
}
|