@mparticle/web-google-analytics-4-client-kit 1.4.4 → 1.5.0
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
|
};
|
|
@@ -900,6 +930,9 @@ function parseProduct(product, affiliation) {
|
|
|
900
930
|
case 'Variant':
|
|
901
931
|
productWithAllAttributes.item_variant = product.Variant;
|
|
902
932
|
break;
|
|
933
|
+
case 'Position':
|
|
934
|
+
productWithAllAttributes.index = product.Position;
|
|
935
|
+
break;
|
|
903
936
|
case 'Attributes':
|
|
904
937
|
break;
|
|
905
938
|
default:
|
|
@@ -1017,32 +1050,6 @@ function EventHandler(common) {
|
|
|
1017
1050
|
this.common = common || {};
|
|
1018
1051
|
}
|
|
1019
1052
|
|
|
1020
|
-
EventHandler.prototype.maybeSendConsentUpdateToGa4 = function (event) {
|
|
1021
|
-
// If consent payload is empty,
|
|
1022
|
-
// we never sent an initial default consent state
|
|
1023
|
-
// so we shouldn't send an update.
|
|
1024
|
-
if (this.common.consentPayloadAsString && this.common.consentMappings) {
|
|
1025
|
-
var eventConsentState = this.common.consentHandler.getEventConsentState(
|
|
1026
|
-
event.ConsentState
|
|
1027
|
-
);
|
|
1028
|
-
|
|
1029
|
-
if (!this.common.isEmpty(eventConsentState)) {
|
|
1030
|
-
var updatedConsentPayload =
|
|
1031
|
-
this.common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
1032
|
-
eventConsentState,
|
|
1033
|
-
this.common.consentMappings
|
|
1034
|
-
);
|
|
1035
|
-
|
|
1036
|
-
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
|
|
1037
|
-
|
|
1038
|
-
if (eventConsentAsString !== this.common.consentPayloadAsString) {
|
|
1039
|
-
gtag('consent', 'update', updatedConsentPayload);
|
|
1040
|
-
this.common.consentPayloadAsString = eventConsentAsString;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
};
|
|
1045
|
-
|
|
1046
1053
|
// TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5715
|
|
1047
1054
|
EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
|
|
1048
1055
|
var standardizedEventName;
|
|
@@ -1073,7 +1080,10 @@ EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
|
|
|
1073
1080
|
};
|
|
1074
1081
|
|
|
1075
1082
|
EventHandler.prototype.logEvent = function (event) {
|
|
1076
|
-
this.
|
|
1083
|
+
var eventConsentState = this.common.getEventConsentState(
|
|
1084
|
+
event.ConsentState
|
|
1085
|
+
);
|
|
1086
|
+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
|
|
1077
1087
|
this.sendEventToGA4(event.EventName, event.EventAttributes);
|
|
1078
1088
|
};
|
|
1079
1089
|
|
|
@@ -1124,7 +1134,10 @@ EventHandler.prototype.logPageView = function (event) {
|
|
|
1124
1134
|
event.EventAttributes
|
|
1125
1135
|
);
|
|
1126
1136
|
|
|
1127
|
-
this.
|
|
1137
|
+
var eventConsentState = this.common.getEventConsentState(
|
|
1138
|
+
event.ConsentState
|
|
1139
|
+
);
|
|
1140
|
+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
|
|
1128
1141
|
this.sendEventToGA4('page_view', eventAttributes);
|
|
1129
1142
|
|
|
1130
1143
|
return true;
|
|
@@ -1303,22 +1316,29 @@ var initialization = {
|
|
|
1303
1316
|
|
|
1304
1317
|
common.consentPayloadDefaults =
|
|
1305
1318
|
common.consentHandler.getConsentSettings();
|
|
1306
|
-
var
|
|
1307
|
-
|
|
1308
|
-
|
|
1319
|
+
var defaultConsentPayload = common.cloneObject(
|
|
1320
|
+
common.consentPayloadDefaults
|
|
1321
|
+
);
|
|
1322
|
+
var updatedConsentState = common.consentHandler.getUserConsentState();
|
|
1323
|
+
var updatedDefaultConsentPayload =
|
|
1309
1324
|
common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
1310
|
-
|
|
1325
|
+
updatedConsentState,
|
|
1311
1326
|
common.consentMappings
|
|
1312
1327
|
);
|
|
1313
1328
|
|
|
1329
|
+
// If a default consent payload exists (as selected in the mParticle UI), set it as the default
|
|
1314
1330
|
if (!common.isEmpty(defaultConsentPayload)) {
|
|
1315
|
-
common.
|
|
1316
|
-
|
|
1331
|
+
common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
|
|
1332
|
+
// If a default consent payload does not exist, but the user currently has updated their consent,
|
|
1333
|
+
// send that as the default because a default must be sent
|
|
1334
|
+
} else if (!common.isEmpty(updatedDefaultConsentPayload)) {
|
|
1335
|
+
common.sendDefaultConsentPayloadToGoogle(
|
|
1336
|
+
updatedDefaultConsentPayload
|
|
1317
1337
|
);
|
|
1318
|
-
|
|
1319
|
-
gtag('consent', 'default', defaultConsentPayload);
|
|
1320
1338
|
}
|
|
1321
1339
|
|
|
1340
|
+
common.maybeSendConsentUpdateToGoogle(updatedConsentState);
|
|
1341
|
+
|
|
1322
1342
|
return isInitialized;
|
|
1323
1343
|
},
|
|
1324
1344
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-google-analytics-4-client-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
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",
|