@mparticle/web-onetrust-kit 2.0.4 → 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.
@@ -70,50 +70,74 @@ var initialization = {
70
70
  };
71
71
  },
72
72
  createConsentEvents: function () {
73
- if (window.Optanon) {
74
- var location = window.location.href,
75
- consent,
76
- consentState,
77
- user = mParticle.Identity.getCurrentUser();
78
-
79
- if (user) {
80
- consentState = user.getConsentState();
73
+ var user = mParticle.Identity.getCurrentUser();
74
+ if (!window.Optanon || !user) {
75
+ return;
76
+ }
81
77
 
82
- if (!consentState) {
83
- consentState = mParticle.Consent.createConsentState();
84
- }
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;
89
-
90
- // removes all non-digits
91
- // 1st version of OneTrust required a selection from group1, group2, etc
92
- if (key.indexOf('group') >= 0) {
93
- key = key.replace(/\D/g, '');
94
- }
78
+ var location = window.location.href;
79
+ var consentState =
80
+ user.getConsentState() || mParticle.Consent.createConsentState();
95
81
 
96
- consentBoolean = (this.getConsentGroupIds().indexOf(key) > -1);
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
+ }
97
88
 
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);
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) {
108
122
  break;
109
- default:
110
- console.error('Unknown Consent Regulation', regulation);
123
+ }
111
124
  }
112
- }
113
125
 
114
- user.setConsentState(consentState);
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);
115
137
  }
116
138
  }
139
+
140
+ user.setConsentState(consentState);
117
141
  },
118
142
 
119
143
  createVendorConsentEvents: function() {
@@ -228,7 +252,6 @@ function setIABVendorRequests(
228
252
  var IABConsentedVendors = oneTrustVendorConsent
229
253
  ? oneTrustVendorConsent.vendor.consents
230
254
  : null;
231
-
232
255
  for (var vendorIndex in IABVendorConsentMappings) {
233
256
  var consentPurpose = IABVendorConsentMappings[vendorIndex].purpose;
234
257
  // consent is true if the (vendorIndex - 1) is 1
@@ -296,97 +319,97 @@ var initialization_1 = {
296
319
  // limitations under the License.
297
320
  var Initialization = initialization_1.initialization;
298
321
 
299
- var name = Initialization.name,
300
- moduleId = Initialization.moduleId;
322
+ var name = Initialization.name,
323
+ moduleId = Initialization.moduleId;
301
324
 
302
- var constructor = function () {
303
- var self = this,
304
- isInitialized = false,
305
- forwarderSettings;
325
+ var constructor = function () {
326
+ var self = this,
327
+ isInitialized = false,
328
+ forwarderSettings;
306
329
 
307
- self.name = Initialization.name;
330
+ self.name = Initialization.name;
308
331
 
309
- function initForwarder(settings) {
310
- forwarderSettings = settings;
311
- if (!isInitialized) {
312
- try {
313
- Initialization.initForwarder(forwarderSettings, isInitialized);
314
- isInitialized = true;
315
- } catch (e) {
316
- console.log('Failed to initialize ' + name + ' - ' + e);
317
- }
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);
340
+ }
341
+
342
+ Initialization.createConsentEvents();
343
+ Initialization.createVendorConsentEvents();
344
+ }
345
+ }
318
346
 
347
+ function onUserIdentified() {
348
+ if (isInitialized) {
349
+ try {
319
350
  Initialization.createConsentEvents();
320
351
  Initialization.createVendorConsentEvents();
352
+ } catch (e) {
353
+ return {error: 'Error setting user identity on forwarder ' + name + '; ' + e};
321
354
  }
322
355
  }
323
-
324
- function onUserIdentified() {
325
- if (isInitialized) {
326
- try {
327
- Initialization.createConsentEvents();
328
- Initialization.createVendorConsentEvents();
329
- } catch (e) {
330
- return {error: 'Error setting user identity on forwarder ' + name + '; ' + e};
331
- }
332
- }
333
- else {
334
- return 'Can\'t set new user identities on forwader ' + name + ', not initialized';
335
- }
356
+ else {
357
+ return 'Can\'t set new user identities on forwader ' + name + ', not initialized';
336
358
  }
359
+ }
337
360
 
338
- this.init = initForwarder;
339
- this.onUserIdentified = onUserIdentified;
340
- this.process = function() {
361
+ this.init = initForwarder;
362
+ this.onUserIdentified = onUserIdentified;
363
+ this.process = function() {
341
364
 
342
- };
343
365
  };
366
+ };
344
367
 
345
- function getId() {
346
- return moduleId;
347
- }
368
+ function getId() {
369
+ return moduleId;
370
+ }
348
371
 
349
- function isObject(val) {
350
- return val != null && typeof val === 'object' && Array.isArray(val) === false;
351
- }
372
+ function isObject(val) {
373
+ return val != null && typeof val === 'object' && Array.isArray(val) === false;
374
+ }
352
375
 
353
- function register(config) {
354
- if (!config) {
355
- console.log('You must pass a config object to register the kit ' + name);
356
- return;
357
- }
376
+ function register(config) {
377
+ if (!config) {
378
+ console.log('You must pass a config object to register the kit ' + name);
379
+ return;
380
+ }
358
381
 
359
- if (!isObject(config)) {
360
- console.log('\'config\' must be an object. You passed in a ' + typeof config);
361
- return;
362
- }
382
+ if (!isObject(config)) {
383
+ console.log('\'config\' must be an object. You passed in a ' + typeof config);
384
+ return;
385
+ }
363
386
 
364
- if (isObject(config.kits)) {
365
- config.kits[name] = {
366
- constructor: constructor
367
- };
368
- } else {
369
- config.kits = {};
370
- config.kits[name] = {
371
- constructor: constructor
372
- };
373
- }
374
- console.log('Successfully registered ' + name + ' to your mParticle configuration');
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
+ };
375
396
  }
397
+ console.log('Successfully registered ' + name + ' to your mParticle configuration');
398
+ }
376
399
 
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
- }
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
+ });
385
407
  }
408
+ }
386
409
 
387
- var oneTrustWrapper = {
388
- register: register
389
- };
410
+ var oneTrustWrapper = {
411
+ register: register
412
+ };
390
413
  var oneTrustWrapper_1 = oneTrustWrapper.register;
391
414
 
392
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.4",
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",