@mparticle/web-onetrust-kit 2.0.3 → 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.
@@ -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
 
@@ -97,11 +114,170 @@ var initialization = {
97
114
  user.setConsentState(consentState);
98
115
  }
99
116
  }
100
- }
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();
128
+
129
+ if (!consentState) {
130
+ consentState = mParticle.Consent.createConsentState();
131
+ }
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
+
178
+ user.setConsentState(consentState);
179
+ }
180
+ }
181
+ },
101
182
  };
102
183
 
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);
246
+ }
247
+ }
248
+
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
+ }
277
+ }
278
+
103
279
  var initialization_1 = {
104
- initialization: initialization
280
+ initialization: initialization,
105
281
  };
106
282
 
107
283
  //
@@ -141,6 +317,7 @@ var Initialization = initialization_1.initialization;
141
317
  }
142
318
 
143
319
  Initialization.createConsentEvents();
320
+ Initialization.createVendorConsentEvents();
144
321
  }
145
322
  }
146
323
 
@@ -148,12 +325,13 @@ var Initialization = initialization_1.initialization;
148
325
  if (isInitialized) {
149
326
  try {
150
327
  Initialization.createConsentEvents();
328
+ Initialization.createVendorConsentEvents();
151
329
  } catch (e) {
152
330
  return {error: 'Error setting user identity on forwarder ' + name + '; ' + e};
153
331
  }
154
332
  }
155
333
  else {
156
- return 'Can\'t set new user identities on forwader ' + name + ', not initialized';
334
+ return 'Can\'t set new user identities on forwader ' + name + ', not initialized';
157
335
  }
158
336
  }
159
337
 
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.4",
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",