@mparticle/web-google-analytics-4-client-kit 1.4.3 → 1.4.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.
|
@@ -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
|
|
|
@@ -258,6 +252,42 @@ Common.prototype.limitProductAttributes = function (attributes) {
|
|
|
258
252
|
return this.mergeObjects(limitedProductAttributes, reservedAttributes);
|
|
259
253
|
};
|
|
260
254
|
|
|
255
|
+
Common.prototype.getEventConsentState = function (eventConsentState) {
|
|
256
|
+
return eventConsentState && eventConsentState.getGDPRConsentState
|
|
257
|
+
? eventConsentState.getGDPRConsentState()
|
|
258
|
+
: {};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
|
|
262
|
+
// If consent payload is empty,
|
|
263
|
+
// we never sent an initial default consent state
|
|
264
|
+
// so we shouldn't send an update.
|
|
265
|
+
if (
|
|
266
|
+
this.consentPayloadAsString &&
|
|
267
|
+
this.consentMappings &&
|
|
268
|
+
!this.isEmpty(consentState)
|
|
269
|
+
) {
|
|
270
|
+
var updatedConsentPayload =
|
|
271
|
+
this.consentHandler.generateConsentStatePayloadFromMappings(
|
|
272
|
+
consentState,
|
|
273
|
+
this.consentMappings
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
|
|
277
|
+
|
|
278
|
+
if (eventConsentAsString !== this.consentPayloadAsString) {
|
|
279
|
+
gtag('consent', 'update', updatedConsentPayload);
|
|
280
|
+
this.consentPayloadAsString = eventConsentAsString;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
Common.prototype.sendDefaultConsentPayloadToGoogle = function (consentPayload) {
|
|
286
|
+
this.consentPayloadAsString = JSON.stringify(consentPayload);
|
|
287
|
+
|
|
288
|
+
gtag('consent', 'default', consentPayload);
|
|
289
|
+
};
|
|
290
|
+
|
|
261
291
|
Common.prototype.truncateEventName = function (eventName) {
|
|
262
292
|
return truncateString(eventName, EVENT_NAME_MAX_LENGTH);
|
|
263
293
|
};
|
|
@@ -680,6 +710,11 @@ CommerceHandler.prototype.logPromotionEvent = function (event) {
|
|
|
680
710
|
event.PromotionAction.PromotionList.forEach(function (promotion) {
|
|
681
711
|
ga4CommerceEventParameters = buildPromotion(promotion);
|
|
682
712
|
|
|
713
|
+
ga4CommerceEventParameters = self.common.mergeObjects(
|
|
714
|
+
ga4CommerceEventParameters,
|
|
715
|
+
self.common.limitEventAttributes(event.EventAttributes)
|
|
716
|
+
);
|
|
717
|
+
|
|
683
718
|
self.sendCommerceEventToGA4(
|
|
684
719
|
mapGA4EcommerceEventName(event),
|
|
685
720
|
ga4CommerceEventParameters
|
|
@@ -706,6 +741,11 @@ CommerceHandler.prototype.logImpressionEvent = function (event, affiliation) {
|
|
|
706
741
|
affiliation
|
|
707
742
|
);
|
|
708
743
|
|
|
744
|
+
ga4CommerceEventParameters = self.common.mergeObjects(
|
|
745
|
+
ga4CommerceEventParameters,
|
|
746
|
+
self.common.limitEventAttributes(event.EventAttributes)
|
|
747
|
+
);
|
|
748
|
+
|
|
709
749
|
self.sendCommerceEventToGA4(
|
|
710
750
|
mapGA4EcommerceEventName(event),
|
|
711
751
|
ga4CommerceEventParameters
|
|
@@ -1007,32 +1047,6 @@ function EventHandler(common) {
|
|
|
1007
1047
|
this.common = common || {};
|
|
1008
1048
|
}
|
|
1009
1049
|
|
|
1010
|
-
EventHandler.prototype.maybeSendConsentUpdateToGa4 = function (event) {
|
|
1011
|
-
// If consent payload is empty,
|
|
1012
|
-
// we never sent an initial default consent state
|
|
1013
|
-
// so we shouldn't send an update.
|
|
1014
|
-
if (this.common.consentPayloadAsString && this.common.consentMappings) {
|
|
1015
|
-
var eventConsentState = this.common.consentHandler.getEventConsentState(
|
|
1016
|
-
event.ConsentState
|
|
1017
|
-
);
|
|
1018
|
-
|
|
1019
|
-
if (!this.common.isEmpty(eventConsentState)) {
|
|
1020
|
-
var updatedConsentPayload =
|
|
1021
|
-
this.common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
1022
|
-
eventConsentState,
|
|
1023
|
-
this.common.consentMappings
|
|
1024
|
-
);
|
|
1025
|
-
|
|
1026
|
-
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
|
|
1027
|
-
|
|
1028
|
-
if (eventConsentAsString !== this.common.consentPayloadAsString) {
|
|
1029
|
-
gtag('consent', 'update', updatedConsentPayload);
|
|
1030
|
-
this.common.consentPayloadAsString = eventConsentAsString;
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
1050
|
// TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5715
|
|
1037
1051
|
EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
|
|
1038
1052
|
var standardizedEventName;
|
|
@@ -1063,7 +1077,10 @@ EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
|
|
|
1063
1077
|
};
|
|
1064
1078
|
|
|
1065
1079
|
EventHandler.prototype.logEvent = function (event) {
|
|
1066
|
-
this.
|
|
1080
|
+
var eventConsentState = this.common.getEventConsentState(
|
|
1081
|
+
event.ConsentState
|
|
1082
|
+
);
|
|
1083
|
+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
|
|
1067
1084
|
this.sendEventToGA4(event.EventName, event.EventAttributes);
|
|
1068
1085
|
};
|
|
1069
1086
|
|
|
@@ -1114,7 +1131,10 @@ EventHandler.prototype.logPageView = function (event) {
|
|
|
1114
1131
|
event.EventAttributes
|
|
1115
1132
|
);
|
|
1116
1133
|
|
|
1117
|
-
this.
|
|
1134
|
+
var eventConsentState = this.common.getEventConsentState(
|
|
1135
|
+
event.ConsentState
|
|
1136
|
+
);
|
|
1137
|
+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
|
|
1118
1138
|
this.sendEventToGA4('page_view', eventAttributes);
|
|
1119
1139
|
|
|
1120
1140
|
return true;
|
|
@@ -1293,22 +1313,29 @@ var initialization = {
|
|
|
1293
1313
|
|
|
1294
1314
|
common.consentPayloadDefaults =
|
|
1295
1315
|
common.consentHandler.getConsentSettings();
|
|
1296
|
-
var
|
|
1297
|
-
|
|
1298
|
-
|
|
1316
|
+
var defaultConsentPayload = common.cloneObject(
|
|
1317
|
+
common.consentPayloadDefaults
|
|
1318
|
+
);
|
|
1319
|
+
var updatedConsentState = common.consentHandler.getUserConsentState();
|
|
1320
|
+
var updatedDefaultConsentPayload =
|
|
1299
1321
|
common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
1300
|
-
|
|
1322
|
+
updatedConsentState,
|
|
1301
1323
|
common.consentMappings
|
|
1302
1324
|
);
|
|
1303
1325
|
|
|
1326
|
+
// If a default consent payload exists (as selected in the mParticle UI), set it as the default
|
|
1304
1327
|
if (!common.isEmpty(defaultConsentPayload)) {
|
|
1305
|
-
common.
|
|
1306
|
-
|
|
1328
|
+
common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
|
|
1329
|
+
// If a default consent payload does not exist, but the user currently has updated their consent,
|
|
1330
|
+
// send that as the default because a default must be sent
|
|
1331
|
+
} else if (!common.isEmpty(updatedDefaultConsentPayload)) {
|
|
1332
|
+
common.sendDefaultConsentPayloadToGoogle(
|
|
1333
|
+
updatedDefaultConsentPayload
|
|
1307
1334
|
);
|
|
1308
|
-
|
|
1309
|
-
gtag('consent', 'default', defaultConsentPayload);
|
|
1310
1335
|
}
|
|
1311
1336
|
|
|
1337
|
+
common.maybeSendConsentUpdateToGoogle(updatedConsentState);
|
|
1338
|
+
|
|
1312
1339
|
return isInitialized;
|
|
1313
1340
|
},
|
|
1314
1341
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-google-analytics-4-client-kit",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
|
|
5
5
|
"description": "mParticle integration sdk for Google Analytics",
|
|
6
6
|
"main": "dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js",
|