@mparticle/web-double-click-kit 2.1.2 → 2.1.3

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.
@@ -50,12 +50,6 @@ ConsentHandler.prototype.getUserConsentState = function () {
50
50
  return userConsentState;
51
51
  };
52
52
 
53
- ConsentHandler.prototype.getEventConsentState = function (eventConsentState) {
54
- return eventConsentState && eventConsentState.getGDPRConsentState
55
- ? eventConsentState.getGDPRConsentState()
56
- : {};
57
- };
58
-
59
53
  ConsentHandler.prototype.getConsentSettings = function () {
60
54
  var consentSettings = {};
61
55
 
@@ -170,6 +164,42 @@ Common.prototype.sendGtagConsent = function (type, payload) {
170
164
  gtag('consent', type, payload);
171
165
  };
172
166
 
167
+ Common.prototype.getEventConsentState = function (eventConsentState) {
168
+ return eventConsentState && eventConsentState.getGDPRConsentState
169
+ ? eventConsentState.getGDPRConsentState()
170
+ : {};
171
+ };
172
+
173
+ Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
174
+ // If consent payload is empty,
175
+ // we never sent an initial default consent state
176
+ // so we shouldn't send an update.
177
+ if (
178
+ this.consentPayloadAsString &&
179
+ this.consentMappings &&
180
+ !this.isEmpty(consentState)
181
+ ) {
182
+ var updatedConsentPayload =
183
+ this.consentHandler.generateConsentStatePayloadFromMappings(
184
+ consentState,
185
+ this.consentMappings
186
+ );
187
+
188
+ var eventConsentAsString = JSON.stringify(updatedConsentPayload);
189
+
190
+ if (eventConsentAsString !== this.consentPayloadAsString) {
191
+ this.sendGtagConsent('update', updatedConsentPayload);
192
+ this.consentPayloadAsString = eventConsentAsString;
193
+ }
194
+ }
195
+ };
196
+
197
+ Common.prototype.sendDefaultConsentPayloadToGoogle = function (consentPayload) {
198
+ this.consentPayloadAsString = JSON.stringify(consentPayload);
199
+
200
+ this.sendGtagConsent('default', consentPayload);
201
+ };
202
+
173
203
  Common.prototype.cloneObject = function (obj) {
174
204
  return JSON.parse(JSON.stringify(obj));
175
205
  };
@@ -282,34 +312,11 @@ function EventHandler(common) {
282
312
  this.common = common || {};
283
313
  }
284
314
 
285
- EventHandler.prototype.maybeSendConsentUpdateToGoogle = function (event) {
286
- // If consent payload is empty,
287
- // we never sent an initial default consent state
288
- // so we shouldn't send an update.
289
- if (this.common.consentPayloadAsString && this.common.consentMappings) {
290
- var eventConsentState = this.common.consentHandler.getEventConsentState(
291
- event.ConsentState
292
- );
293
-
294
- if (!this.common.isEmpty(eventConsentState)) {
295
- var updatedConsentPayload =
296
- this.common.consentHandler.generateConsentStatePayloadFromMappings(
297
- eventConsentState,
298
- this.common.consentMappings
299
- );
300
-
301
- var eventConsentAsString = JSON.stringify(updatedConsentPayload);
302
-
303
- if (eventConsentAsString !== this.common.consentPayloadAsString) {
304
- this.common.sendGtagConsent('update', updatedConsentPayload);
305
- this.common.consentPayloadAsString = eventConsentAsString;
306
- }
307
- }
308
- }
309
- };
310
-
311
315
  EventHandler.prototype.logEvent = function (event) {
312
- this.maybeSendConsentUpdateToGoogle(event);
316
+ var eventConsentState = this.common.getEventConsentState(
317
+ event.ConsentState
318
+ );
319
+ this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
313
320
 
314
321
  var gtagProperties = {};
315
322
  this.common.setCustomVariables(event, gtagProperties);
@@ -453,20 +460,28 @@ var initialization = {
453
460
 
454
461
  common.consentPayloadDefaults =
455
462
  common.consentHandler.getConsentSettings();
456
- var initialConsentState = common.consentHandler.getUserConsentState();
457
- var defaultConsentPayload =
463
+ var defaultConsentPayload = common.cloneObject(
464
+ common.consentPayloadDefaults
465
+ );
466
+ var updatedConsentState = common.consentHandler.getUserConsentState();
467
+ var updatedDefaultConsentPayload =
458
468
  common.consentHandler.generateConsentStatePayloadFromMappings(
459
- initialConsentState,
469
+ updatedConsentState,
460
470
  common.consentMappings
461
471
  );
462
-
472
+
473
+ // If a default consent payload exists (as selected in the mParticle UI), set it as the default
463
474
  if (!common.isEmpty(defaultConsentPayload)) {
464
- common.consentPayloadAsString = JSON.stringify(
465
- defaultConsentPayload
475
+ common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
476
+ // If a default consent payload does not exist, but the user currently has updated their consent,
477
+ // send that as the default because a default must be sent
478
+ } else if (!common.isEmpty(updatedDefaultConsentPayload)) {
479
+ common.sendDefaultConsentPayloadToGoogle(
480
+ updatedDefaultConsentPayload
466
481
  );
467
-
468
- common.sendGtagConsent('default', defaultConsentPayload);
469
482
  }
483
+
484
+ common.maybeSendConsentUpdateToGoogle(updatedConsentState);
470
485
  },
471
486
  };
472
487
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-double-click-kit",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-doubleclick",
5
5
  "main": "dist/DoubleClick-Kit.common.js",
6
6
  "browser": "dist/DoubleClick-Kit.common.js",