@mparticle/web-google-tag-manager-kit 2.1.1 → 2.1.2

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
 
@@ -251,6 +245,44 @@ Common.prototype.sendConsent = function (type, payload) {
251
245
  customDataLayer('consent', type, payload);
252
246
  };
253
247
 
248
+ Common.prototype.getEventConsentState = function (eventConsentState) {
249
+ return eventConsentState && eventConsentState.getGDPRConsentState
250
+ ? eventConsentState.getGDPRConsentState()
251
+ : {};
252
+ };
253
+
254
+ Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
255
+ // If consent payload is empty,
256
+ // we never sent an initial default consent state
257
+ // so we shouldn't send an update.
258
+ if (
259
+ this.consentPayloadAsString &&
260
+ this.consentMappings &&
261
+ !this.isEmpty(consentState)
262
+ ) {
263
+ var updatedConsentPayload =
264
+ this.consentHandler.generateConsentStatePayloadFromMappings(
265
+ consentState,
266
+ this.consentMappings
267
+ );
268
+
269
+ var eventConsentAsString = JSON.stringify(updatedConsentPayload);
270
+
271
+ if (eventConsentAsString !== this.consentPayloadAsString) {
272
+ this.sendConsent('update', updatedConsentPayload);
273
+ this.consentPayloadAsString = eventConsentAsString;
274
+ }
275
+ }
276
+ };
277
+
278
+ Common.prototype.sendDefaultConsentPayloadToGoogle = function (consentPayload) {
279
+ this.consentPayloadAsString = JSON.stringify(
280
+ consentPayload
281
+ );
282
+
283
+ this.sendConsent('default', consentPayload);
284
+ };
285
+
254
286
  Common.prototype.cloneObject = function (obj) {
255
287
  return JSON.parse(JSON.stringify(obj));
256
288
  };
@@ -576,34 +608,11 @@ function EventHandler(common) {
576
608
  this.common = common || {};
577
609
  }
578
610
 
579
- EventHandler.prototype.maybeSendConsentUpdateToGoogle = function (event) {
580
- // If consent payload is empty,
581
- // we never sent an initial default consent state
582
- // so we shouldn't send an update.
583
- if (this.common.consentPayloadAsString && this.common.consentMappings) {
584
- var eventConsentState = this.common.consentHandler.getEventConsentState(
585
- event.ConsentState
586
- );
587
-
588
- if (!this.common.isEmpty(eventConsentState)) {
589
- var updatedConsentPayload =
590
- this.common.consentHandler.generateConsentStatePayloadFromMappings(
591
- eventConsentState,
592
- this.common.consentMappings
593
- );
594
-
595
- var eventConsentAsString = JSON.stringify(updatedConsentPayload);
596
-
597
- if (eventConsentAsString !== this.common.consentPayloadAsString) {
598
- this.common.sendConsent('update', updatedConsentPayload);
599
- this.common.consentPayloadAsString = eventConsentAsString;
600
- }
601
- }
602
- }
603
- };
604
-
605
611
  EventHandler.prototype.logEvent = function (event) {
606
- this.maybeSendConsentUpdateToGoogle(event);
612
+ var eventConsentState = this.common.getEventConsentState(
613
+ event.ConsentState
614
+ );
615
+ this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
607
616
  this.common.send({
608
617
  event: event,
609
618
  });
@@ -614,7 +623,10 @@ EventHandler.prototype.logEvent = function (event) {
614
623
  EventHandler.prototype.logError = function() {};
615
624
 
616
625
  EventHandler.prototype.logPageView = function (event) {
617
- this.maybeSendConsentUpdateToGoogle(event);
626
+ var eventConsentState = this.common.getEventConsentState(
627
+ event.ConsentState
628
+ );
629
+ this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
618
630
  this.common.send({
619
631
  event: event,
620
632
  eventType: 'screen_view'
@@ -785,21 +797,26 @@ var initialization = {
785
797
 
786
798
  common.consentPayloadDefaults =
787
799
  common.consentHandler.getConsentSettings();
788
- var initialConsentState = common.consentHandler.getUserConsentState();
789
800
 
790
- var defaultConsentPayload =
801
+ var defaultConsentPayload = common.cloneObject(common.consentPayloadDefaults);
802
+ var updatedConsentState = common.consentHandler.getUserConsentState();
803
+ var updatedDefaultConsentPayload =
791
804
  common.consentHandler.generateConsentStatePayloadFromMappings(
792
- initialConsentState,
805
+ updatedConsentState,
793
806
  common.consentMappings
794
807
  );
795
808
 
809
+ // If a default consent payload exists (as selected in the mParticle UI), set it as the default
796
810
  if (!common.isEmpty(defaultConsentPayload)) {
797
- common.consentPayloadAsString = JSON.stringify(
798
- defaultConsentPayload
799
- );
800
-
801
- common.sendConsent('default', defaultConsentPayload);
811
+ common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
812
+ // If a default consent payload does not exist, but the user currently has updated their consent,
813
+ // send that as the default because a default must be sent
814
+ } else if (!common.isEmpty(updatedDefaultConsentPayload)) {
815
+ common.sendDefaultConsentPayloadToGoogle(updatedDefaultConsentPayload);
802
816
  }
817
+
818
+ common.maybeSendConsentUpdateToGoogle(updatedConsentState);
819
+
803
820
  },
804
821
  };
805
822
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-google-tag-manager-kit",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-google-tag-manager",
5
5
  "main": "dist/GoogleTagManager-Kit.common.js",
6
6
  "browser": "dist/GoogleTagManager-Kit.common.js",