@mparticle/web-google-tag-manager-kit 2.1.0 → 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
 
@@ -94,7 +88,7 @@ ConsentHandler.prototype.generateConsentStatePayloadFromMappings = function (
94
88
 
95
89
  for (var i = 0; i <= mappings.length - 1; i++) {
96
90
  var mappingEntry = mappings[i];
97
- var mpMappedConsentName = mappingEntry.map;
91
+ var mpMappedConsentName = mappingEntry.map.toLowerCase();
98
92
  var googleMappedConsentName = mappingEntry.value;
99
93
 
100
94
  if (
@@ -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
 
@@ -1093,8 +1110,7 @@ var constructor = function() {
1093
1110
 
1094
1111
  function logSessionStart(event) {
1095
1112
  try {
1096
- sessionHandler_1.onSessionStart(event);
1097
- return true;
1113
+ return sessionHandler_1.onSessionStart(event);
1098
1114
  } catch (e) {
1099
1115
  return {
1100
1116
  error: 'Error starting session on forwarder ' + name + '; ' + e,
@@ -1104,8 +1120,7 @@ var constructor = function() {
1104
1120
 
1105
1121
  function logSessionEnd(event) {
1106
1122
  try {
1107
- sessionHandler_1.onSessionEnd(event);
1108
- return true;
1123
+ return sessionHandler_1.onSessionEnd(event);
1109
1124
  } catch (e) {
1110
1125
  return {
1111
1126
  error: 'Error ending session on forwarder ' + name + '; ' + e,
@@ -1115,8 +1130,7 @@ var constructor = function() {
1115
1130
 
1116
1131
  function logError(event) {
1117
1132
  try {
1118
- self.eventHandler.logError(event);
1119
- return true;
1133
+ return self.eventHandler.logError(event);
1120
1134
  } catch (e) {
1121
1135
  return {
1122
1136
  error: 'Error logging error on forwarder ' + name + '; ' + e,
@@ -1126,8 +1140,7 @@ var constructor = function() {
1126
1140
 
1127
1141
  function logPageView(event) {
1128
1142
  try {
1129
- self.eventHandler.logPageView(event);
1130
- return true;
1143
+ return self.eventHandler.logPageView(event);
1131
1144
  } catch (e) {
1132
1145
  return {
1133
1146
  error:
@@ -1138,8 +1151,7 @@ var constructor = function() {
1138
1151
 
1139
1152
  function logEvent(event) {
1140
1153
  try {
1141
- self.eventHandler.logEvent(event);
1142
- return true;
1154
+ return self.eventHandler.logEvent(event);
1143
1155
  } catch (e) {
1144
1156
  return {
1145
1157
  error: 'Error logging event on forwarder ' + name + '; ' + e,
@@ -1149,8 +1161,7 @@ var constructor = function() {
1149
1161
 
1150
1162
  function logEcommerceEvent(event) {
1151
1163
  try {
1152
- self.commerceHandler.logCommerceEvent(event);
1153
- return true;
1164
+ return self.commerceHandler.logCommerceEvent(event);
1154
1165
  } catch (e) {
1155
1166
  return {
1156
1167
  error:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-google-tag-manager-kit",
3
- "version": "2.1.0",
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",
@@ -9,8 +9,7 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "test": "npm run build && npm run test:karma",
12
- "test:karma": "npm run testKarma",
13
- "testKarma": "node test/boilerplate/test-karma.js",
12
+ "test:karma": "node test/test-karma.js",
14
13
  "build": "ENVIRONMENT=production rollup --config rollup.config.js",
15
14
  "watch": "ENVIRONMENT=production rollup --config rollup.config.js -w",
16
15
  "testEndToEnd": "browserify node_modules/@mparticle/web-kit-wrapper/end-to-end-testapp/index.js -v -o test/end-to-end-testapp/build/compilation.js && open http://localhost:8082/node_modules/@mparticle/web-kit-wrapper/end-to-end-testapp/index.html && node node_modules/@mparticle/web-kit-wrapper/end-to-end-testapp/server"
@@ -20,8 +19,11 @@
20
19
  },
21
20
  "devDependencies": {
22
21
  "@mparticle/web-kit-wrapper": "^1.0.5",
22
+ "@semantic-release/changelog": "^5.0.1",
23
+ "@semantic-release/exec": "^5.0.0",
24
+ "@semantic-release/git": "^9.0.0",
23
25
  "chai": "^4.3.4",
24
- "karma": "^3.1.1",
26
+ "karma": "^5.1.0",
25
27
  "karma-chai": "^0.1.0",
26
28
  "karma-chrome-launcher": "^2.2.0",
27
29
  "karma-edge-launcher": "^0.4.2",