@mparticle/web-onetrust-kit 2.0.3 → 2.0.5

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.
@@ -10,9 +10,14 @@ var CCPA_PURPOSE = 'data_sale_opt_out';
10
10
  var initialization = {
11
11
  name: 'OneTrust',
12
12
  moduleId: 134,
13
- consentMapping: [],
13
+ consentMapping: {},
14
+ googleVendorConsentMapping: {},
15
+ iabVendorConsentMapping: {},
16
+ generalVendorConsentMapping: {},
14
17
  getConsentGroupIds: function() {
15
- return window.OnetrustActiveGroups ? window.OnetrustActiveGroups.split(',') : [];
18
+ return window.OnetrustActiveGroups
19
+ ? window.OnetrustActiveGroups.split(',')
20
+ : [];
16
21
  },
17
22
 
18
23
  parseConsentMapping: function(rawConsentMapping) {
@@ -25,7 +30,7 @@ var initialization = {
25
30
  var purpose = mapping.map;
26
31
  _consentMapping[mapping.value] = {
27
32
  purpose: purpose,
28
- regulation: purpose === CCPA_PURPOSE ? CONSENT_REGULATIONS.CCPA : CONSENT_REGULATIONS.GDPR
33
+ regulation: purpose === CCPA_PURPOSE ? CONSENT_REGULATIONS.CCPA : CONSENT_REGULATIONS.GDPR
29
34
  };
30
35
  });
31
36
  }
@@ -35,8 +40,19 @@ var initialization = {
35
40
 
36
41
  initForwarder: function(forwarderSettings) {
37
42
  var self = this;
38
- self.consentMapping = self.parseConsentMapping(forwarderSettings.consentGroups);
39
-
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
+ );
40
56
  // Wrap exisitng OptanonWrapper in case customer is using
41
57
  // it for something custom so we can hijack
42
58
  var OptanonWrapperCopy = window.OptanonWrapper;
@@ -45,6 +61,7 @@ var initialization = {
45
61
  if (window.Optanon && window.Optanon.OnConsentChanged) {
46
62
  window.Optanon.OnConsentChanged(function() {
47
63
  self.createConsentEvents();
64
+ self.createVendorConsentEvents();
48
65
  });
49
66
  }
50
67
 
@@ -53,9 +70,80 @@ var initialization = {
53
70
  };
54
71
  },
55
72
  createConsentEvents: function () {
56
- if (window.Optanon) {
73
+ var user = mParticle.Identity.getCurrentUser();
74
+ if (!window.Optanon || !user) {
75
+ return;
76
+ }
77
+
78
+ var location = window.location.href;
79
+ var consentState =
80
+ user.getConsentState() || mParticle.Consent.createConsentState();
81
+
82
+ for (var key in this.consentMapping) {
83
+ // removes all non-digits
84
+ // 1st version of OneTrust required a selection from group1, group2, etc
85
+ if (key.indexOf('group') >= 0) {
86
+ key = key.replace(/\D/g, '');
87
+ }
88
+
89
+ // Although consent purposes can be inputted into the UI in any casing
90
+ // the SDK will automatically lowercase them to prevent pseudo-duplicate
91
+ // consent purposes, so we call `toLowerCase` on the consentMapping purposes here
92
+ var consentPurpose = this.consentMapping[key].purpose.toLowerCase();
93
+ var regulation = this.consentMapping[key].regulation;
94
+
95
+ var latestOTConsentBoolean =
96
+ 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
+ var ccpaConsent = mParticle.Consent.createCCPAConsent(
103
+ latestOTConsentBoolean,
104
+ Date.now(),
105
+ consentPurpose,
106
+ location
107
+ );
108
+ consentState.setCCPAConsentState(ccpaConsent);
109
+ break;
110
+
111
+ case CONSENT_REGULATIONS.GDPR:
112
+ var GDPRConsentState =
113
+ consentState.getGDPRConsentState() || {};
114
+
115
+ // if the consent boolean exists, and the current users consent
116
+ // is the same as the latest OT consent (consent hasn't changed)
117
+ // then don't update the consent state
118
+ if (GDPRConsentState[consentPurpose]) {
119
+ var currentConsentBoolean =
120
+ GDPRConsentState[consentPurpose].Consented;
121
+ if (currentConsentBoolean === latestOTConsentBoolean) {
122
+ break;
123
+ }
124
+ }
125
+
126
+ var gdprConsent = mParticle.Consent.createGDPRConsent(
127
+ latestOTConsentBoolean,
128
+ Date.now(),
129
+ consentPurpose,
130
+ location
131
+ );
132
+ consentState.addGDPRConsentState(consentPurpose, gdprConsent);
133
+ break;
134
+
135
+ default:
136
+ console.error('Unknown Consent Regulation', regulation);
137
+ }
138
+ }
139
+
140
+ user.setConsentState(consentState);
141
+ },
142
+
143
+ createVendorConsentEvents: function() {
144
+ var self = this;
145
+ if (window.OneTrust && window.OneTrust.getVendorConsentsRequestV2) {
57
146
  var location = window.location.href,
58
- consent,
59
147
  consentState,
60
148
  user = mParticle.Identity.getCurrentUser();
61
149
 
@@ -65,43 +153,154 @@ var initialization = {
65
153
  if (!consentState) {
66
154
  consentState = mParticle.Consent.createConsentState();
67
155
  }
68
- for (var key in this.consentMapping) {
69
- var consentPurpose = this.consentMapping[key].purpose;
70
- var regulation = this.consentMapping[key].regulation;
71
- var consentBoolean = false;
72
-
73
- // removes all non-digits
74
- // 1st version of OneTrust required a selection from group1, group2, etc
75
- if (key.indexOf('group') >= 0) {
76
- key = key.replace(/\D/g, '');
77
- }
78
156
 
79
- consentBoolean = (this.getConsentGroupIds().indexOf(key) > -1);
80
-
81
- // At present, only CCPA and GDPR are known regulations
82
- // Using a switch in case a new regulation is added in the future
83
- switch (regulation) {
84
- case CONSENT_REGULATIONS.CCPA:
85
- consent = mParticle.Consent.createCCPAConsent(consentBoolean, Date.now(), consentPurpose, location);
86
- consentState.setCCPAConsentState(consent);
87
- break;
88
- case CONSENT_REGULATIONS.GDPR:
89
- consent = mParticle.Consent.createGDPRConsent(consentBoolean, Date.now(), consentPurpose, location);
90
- consentState.addGDPRConsentState(consentPurpose, consent);
91
- break;
92
- default:
93
- console.error('Unknown Consent Regulation', regulation);
94
- }
95
- }
157
+ OneTrust.getVendorConsentsRequestV2(function(
158
+ oneTrustVendorConsent
159
+ ) {
160
+ // oneTrustVendorConsent object is in the shape of
161
+ // {
162
+ // ...
163
+ // addtlConsent:
164
+ // '1~39.43.46.55.61.70.83.89.93.108.117.122.124.131',
165
+ // vendor: {
166
+ // consents: '10100111011' //
167
+ // },
168
+ // ...
169
+ // };
170
+ //
171
+ // Google Vendors are in addtlConsent - to the right of
172
+ // "1~" are ids for which Google Vendor the user has consented,
173
+ // ie. 39, 43, 46, etc, but not 1, 2, 3 which are not in this list
174
+ //
175
+ // IAB Vendors are in vendor.consents
176
+ // 1 = consented, 0 = rejected. The index+1 is the IAB Vendor ID
177
+ // ie. If IAB ID is 5, the index is 4 in the consent string
178
+ // to the left, or 0 (rejected))
179
+ setGoogleVendorRequests(
180
+ oneTrustVendorConsent,
181
+ self.googleVendorConsentMapping,
182
+ consentState,
183
+ location
184
+ );
185
+
186
+ setIABVendorRequests(
187
+ oneTrustVendorConsent,
188
+ self.iabVendorConsentMapping,
189
+ consentState,
190
+ location
191
+ );
192
+
193
+ setGeneralVendorRequests(
194
+ // general vendor consent is on the OptAnonActiveGroups string, similar to GDPR consent
195
+ self.getConsentGroupIds(),
196
+ self.generalVendorConsentMapping,
197
+ consentState,
198
+ location
199
+ );
200
+ });
96
201
 
97
202
  user.setConsentState(consentState);
98
203
  }
99
204
  }
100
- }
205
+ },
101
206
  };
102
207
 
208
+ function setGoogleVendorRequests(
209
+ oneTrustVendorConsent,
210
+ googleVendorConsentMapping,
211
+ consentState,
212
+ location
213
+ ) {
214
+ try {
215
+ // turn Google Vendor Consent string into an array of IDs
216
+ var googleConsentedVendors = oneTrustVendorConsent
217
+ ? oneTrustVendorConsent.addtlConsent
218
+ .slice()
219
+ .split('~')[1]
220
+ .split('.')
221
+ : null;
222
+
223
+ if (googleConsentedVendors && googleConsentedVendors.length) {
224
+ for (var vendorId in googleVendorConsentMapping) {
225
+ var consentPurpose = googleVendorConsentMapping[vendorId].purpose;
226
+ // consent is true if the vendor id is in the array of consented IDs
227
+ var consentBoolean = googleConsentedVendors.indexOf(vendorId) > -1;
228
+ var consent = mParticle.Consent.createGDPRConsent(
229
+ consentBoolean,
230
+ Date.now(),
231
+ consentPurpose,
232
+ location
233
+ );
234
+ consentState.addGDPRConsentState(consentPurpose, consent);
235
+ }
236
+ }
237
+ } catch (e) {
238
+ console.error(
239
+ 'There was a problem setting Google Vendor Consents: ',
240
+ e
241
+ );
242
+ }
243
+ }
244
+
245
+ function setIABVendorRequests(
246
+ oneTrustVendorConsent,
247
+ IABVendorConsentMappings,
248
+ consentState,
249
+ location
250
+ ) {
251
+ try {
252
+ var IABConsentedVendors = oneTrustVendorConsent
253
+ ? oneTrustVendorConsent.vendor.consents
254
+ : null;
255
+ for (var vendorIndex in IABVendorConsentMappings) {
256
+ var consentPurpose = IABVendorConsentMappings[vendorIndex].purpose;
257
+ // consent is true if the (vendorIndex - 1) is 1
258
+ var consentBoolean = IABConsentedVendors[parseInt(vendorIndex) - 1] === '1';
259
+ var consent = mParticle.Consent.createGDPRConsent(
260
+ consentBoolean,
261
+ Date.now(),
262
+ consentPurpose,
263
+ location
264
+ );
265
+ consentState.addGDPRConsentState(consentPurpose, consent);
266
+ }
267
+ } catch (e) {
268
+ console.error('There was a problem setting IAB Vendor Consents: ', e);
269
+ }
270
+ }
271
+
272
+ function setGeneralVendorRequests(
273
+ oneTrustVendorConsent,
274
+ generalVendorConsentMapping,
275
+ consentState,
276
+ location
277
+ ) {
278
+ try {
279
+ if (window.Optanon) {
280
+ for (var vendorId in generalVendorConsentMapping) {
281
+ var consentPurpose = generalVendorConsentMapping[vendorId].purpose;
282
+ // consent is true if the vendorId is in the oneTrustVendorConsent array
283
+ var consentBoolean = oneTrustVendorConsent.indexOf(vendorId) > -1;
284
+ var consent = mParticle.Consent.createGDPRConsent(
285
+ consentBoolean,
286
+ Date.now(),
287
+ consentPurpose,
288
+ location
289
+ );
290
+
291
+ consentState.addGDPRConsentState(consentPurpose, consent);
292
+ }
293
+ }
294
+ } catch (e) {
295
+ console.error(
296
+ 'There was a problem setting General Vendor Consents: ',
297
+ e
298
+ );
299
+ }
300
+ }
301
+
103
302
  var initialization_1 = {
104
- initialization: initialization
303
+ initialization: initialization,
105
304
  };
106
305
 
107
306
  //
@@ -120,95 +319,97 @@ var initialization_1 = {
120
319
  // limitations under the License.
121
320
  var Initialization = initialization_1.initialization;
122
321
 
123
- var name = Initialization.name,
124
- moduleId = Initialization.moduleId;
322
+ var name = Initialization.name,
323
+ moduleId = Initialization.moduleId;
125
324
 
126
- var constructor = function () {
127
- var self = this,
128
- isInitialized = false,
129
- forwarderSettings;
325
+ var constructor = function () {
326
+ var self = this,
327
+ isInitialized = false,
328
+ forwarderSettings;
130
329
 
131
- self.name = Initialization.name;
330
+ self.name = Initialization.name;
132
331
 
133
- function initForwarder(settings) {
134
- forwarderSettings = settings;
135
- if (!isInitialized) {
136
- try {
137
- Initialization.initForwarder(forwarderSettings, isInitialized);
138
- isInitialized = true;
139
- } catch (e) {
140
- console.log('Failed to initialize ' + name + ' - ' + e);
141
- }
142
-
143
- Initialization.createConsentEvents();
332
+ function initForwarder(settings) {
333
+ forwarderSettings = settings;
334
+ if (!isInitialized) {
335
+ try {
336
+ Initialization.initForwarder(forwarderSettings, isInitialized);
337
+ isInitialized = true;
338
+ } catch (e) {
339
+ console.log('Failed to initialize ' + name + ' - ' + e);
144
340
  }
341
+
342
+ Initialization.createConsentEvents();
343
+ Initialization.createVendorConsentEvents();
145
344
  }
345
+ }
146
346
 
147
- function onUserIdentified() {
148
- if (isInitialized) {
149
- try {
150
- Initialization.createConsentEvents();
151
- } catch (e) {
152
- return {error: 'Error setting user identity on forwarder ' + name + '; ' + e};
153
- }
154
- }
155
- else {
156
- return 'Can\'t set new user identities on forwader ' + name + ', not initialized';
347
+ function onUserIdentified() {
348
+ if (isInitialized) {
349
+ try {
350
+ Initialization.createConsentEvents();
351
+ Initialization.createVendorConsentEvents();
352
+ } catch (e) {
353
+ return {error: 'Error setting user identity on forwarder ' + name + '; ' + e};
157
354
  }
158
355
  }
356
+ else {
357
+ return 'Can\'t set new user identities on forwader ' + name + ', not initialized';
358
+ }
359
+ }
159
360
 
160
- this.init = initForwarder;
161
- this.onUserIdentified = onUserIdentified;
162
- this.process = function() {
361
+ this.init = initForwarder;
362
+ this.onUserIdentified = onUserIdentified;
363
+ this.process = function() {
163
364
 
164
- };
165
365
  };
366
+ };
166
367
 
167
- function getId() {
168
- return moduleId;
169
- }
170
-
171
- function isObject(val) {
172
- return val != null && typeof val === 'object' && Array.isArray(val) === false;
173
- }
368
+ function getId() {
369
+ return moduleId;
370
+ }
174
371
 
175
- function register(config) {
176
- if (!config) {
177
- console.log('You must pass a config object to register the kit ' + name);
178
- return;
179
- }
372
+ function isObject(val) {
373
+ return val != null && typeof val === 'object' && Array.isArray(val) === false;
374
+ }
180
375
 
181
- if (!isObject(config)) {
182
- console.log('\'config\' must be an object. You passed in a ' + typeof config);
183
- return;
184
- }
376
+ function register(config) {
377
+ if (!config) {
378
+ console.log('You must pass a config object to register the kit ' + name);
379
+ return;
380
+ }
185
381
 
186
- if (isObject(config.kits)) {
187
- config.kits[name] = {
188
- constructor: constructor
189
- };
190
- } else {
191
- config.kits = {};
192
- config.kits[name] = {
193
- constructor: constructor
194
- };
195
- }
196
- console.log('Successfully registered ' + name + ' to your mParticle configuration');
382
+ if (!isObject(config)) {
383
+ console.log('\'config\' must be an object. You passed in a ' + typeof config);
384
+ return;
197
385
  }
198
386
 
199
- if (typeof window !== 'undefined') {
200
- if (window && window.mParticle && window.mParticle.addForwarder) {
201
- window.mParticle.addForwarder({
202
- name: name,
203
- constructor: constructor,
204
- getId: getId
205
- });
206
- }
387
+ if (isObject(config.kits)) {
388
+ config.kits[name] = {
389
+ constructor: constructor
390
+ };
391
+ } else {
392
+ config.kits = {};
393
+ config.kits[name] = {
394
+ constructor: constructor
395
+ };
396
+ }
397
+ console.log('Successfully registered ' + name + ' to your mParticle configuration');
398
+ }
399
+
400
+ if (typeof window !== 'undefined') {
401
+ if (window && window.mParticle && window.mParticle.addForwarder) {
402
+ window.mParticle.addForwarder({
403
+ name: name,
404
+ constructor: constructor,
405
+ getId: getId
406
+ });
207
407
  }
408
+ }
208
409
 
209
- var oneTrustWrapper = {
210
- register: register
211
- };
410
+ var oneTrustWrapper = {
411
+ register: register
412
+ };
212
413
  var oneTrustWrapper_1 = oneTrustWrapper.register;
213
414
 
214
415
  exports.default = oneTrustWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-onetrust-kit",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
5
  "description": "mParticle integration sdk for OneTrust",
6
6
  "browser": "dist/OneTrustKit.common.js",
@@ -16,18 +16,18 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "chai": "^4.2.0",
19
- "karma": "^5.1.0",
19
+ "karma": "^6.3.4",
20
20
  "karma-chai": "^0.1.0",
21
21
  "karma-chrome-launcher": "^3.1.0",
22
22
  "karma-firefox-launcher": "^1.3.0",
23
23
  "karma-mocha": "^2.0.1",
24
- "mocha": "^2.5.3",
24
+ "mocha": "^9.0.2",
25
25
  "rollup": "^1.13.1",
26
26
  "rollup-plugin-commonjs": "^10.0.0",
27
27
  "rollup-plugin-node-resolve": "^5.0.1",
28
28
  "shelljs": "^0.8.4",
29
29
  "should": "^7.1.0",
30
- "watchify": "^3.11.1"
30
+ "watchify": "^4.0.0"
31
31
  },
32
32
  "dependencies": {
33
33
  "isobject": "^4.0.0",