@mparticle/web-google-analytics-4-client-kit 1.5.0 → 3.1.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.
|
@@ -23,13 +23,16 @@ var googleConsentProperties = [
|
|
|
23
23
|
'ad_user_data',
|
|
24
24
|
'ad_personalization',
|
|
25
25
|
'analytics_storage',
|
|
26
|
+
'functionality_storage',
|
|
27
|
+
'personalization_storage',
|
|
28
|
+
'security_storage',
|
|
26
29
|
];
|
|
27
30
|
|
|
28
31
|
function ConsentHandler(common) {
|
|
29
32
|
this.common = common || {};
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
ConsentHandler.prototype.getUserConsentState = function
|
|
35
|
+
ConsentHandler.prototype.getUserConsentState = function() {
|
|
33
36
|
var userConsentState = {};
|
|
34
37
|
|
|
35
38
|
if (mParticle.Identity && mParticle.Identity.getCurrentUser) {
|
|
@@ -39,8 +42,7 @@ ConsentHandler.prototype.getUserConsentState = function () {
|
|
|
39
42
|
return {};
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
var consentState =
|
|
43
|
-
mParticle.Identity.getCurrentUser().getConsentState();
|
|
45
|
+
var consentState = mParticle.Identity.getCurrentUser().getConsentState();
|
|
44
46
|
|
|
45
47
|
if (consentState && consentState.getGDPRConsentState) {
|
|
46
48
|
userConsentState = consentState.getGDPRConsentState();
|
|
@@ -50,7 +52,7 @@ ConsentHandler.prototype.getUserConsentState = function () {
|
|
|
50
52
|
return userConsentState;
|
|
51
53
|
};
|
|
52
54
|
|
|
53
|
-
ConsentHandler.prototype.getConsentSettings = function
|
|
55
|
+
ConsentHandler.prototype.getConsentSettings = function() {
|
|
54
56
|
var consentSettings = {};
|
|
55
57
|
|
|
56
58
|
var googleToMpConsentSettingsMapping = {
|
|
@@ -58,11 +60,14 @@ ConsentHandler.prototype.getConsentSettings = function () {
|
|
|
58
60
|
ad_personalization: 'defaultAdPersonalizationConsentSDK',
|
|
59
61
|
ad_storage: 'defaultAdStorageConsentSDK',
|
|
60
62
|
analytics_storage: 'defaultAnalyticsStorageConsentSDK',
|
|
63
|
+
functionality_storage: 'defaultFunctionalityStorageConsentSDK',
|
|
64
|
+
personalization_storage: 'defaultPersonalizationStorageConsentSDK',
|
|
65
|
+
security_storage: 'defaultSecurityStorageConsentSDK',
|
|
61
66
|
};
|
|
62
67
|
|
|
63
68
|
var forwarderSettings = this.common.forwarderSettings;
|
|
64
69
|
|
|
65
|
-
Object.keys(googleToMpConsentSettingsMapping).forEach(function
|
|
70
|
+
Object.keys(googleToMpConsentSettingsMapping).forEach(function(
|
|
66
71
|
googleConsentKey
|
|
67
72
|
) {
|
|
68
73
|
var mpConsentSettingKey =
|
|
@@ -78,7 +83,7 @@ ConsentHandler.prototype.getConsentSettings = function () {
|
|
|
78
83
|
return consentSettings;
|
|
79
84
|
};
|
|
80
85
|
|
|
81
|
-
ConsentHandler.prototype.generateConsentStatePayloadFromMappings = function
|
|
86
|
+
ConsentHandler.prototype.generateConsentStatePayloadFromMappings = function(
|
|
82
87
|
consentState,
|
|
83
88
|
mappings
|
|
84
89
|
) {
|
|
@@ -165,7 +170,7 @@ function Common() {
|
|
|
165
170
|
|
|
166
171
|
Common.prototype.forwarderSettings = null;
|
|
167
172
|
|
|
168
|
-
Common.prototype.mergeObjects = function
|
|
173
|
+
Common.prototype.mergeObjects = function() {
|
|
169
174
|
var resObj = {};
|
|
170
175
|
for (var i = 0; i < arguments.length; i += 1) {
|
|
171
176
|
var obj = arguments[i],
|
|
@@ -177,7 +182,7 @@ Common.prototype.mergeObjects = function () {
|
|
|
177
182
|
return resObj;
|
|
178
183
|
};
|
|
179
184
|
|
|
180
|
-
Common.prototype.truncateAttributes = function
|
|
185
|
+
Common.prototype.truncateAttributes = function(
|
|
181
186
|
attributes,
|
|
182
187
|
keyLimit,
|
|
183
188
|
valueLimit
|
|
@@ -185,7 +190,7 @@ Common.prototype.truncateAttributes = function (
|
|
|
185
190
|
var truncatedAttributes = {};
|
|
186
191
|
|
|
187
192
|
if (!isEmpty(attributes)) {
|
|
188
|
-
Object.keys(attributes).forEach(function
|
|
193
|
+
Object.keys(attributes).forEach(function(attribute) {
|
|
189
194
|
var key = truncateString(attribute, keyLimit);
|
|
190
195
|
var valueLimitOverride;
|
|
191
196
|
switch (key) {
|
|
@@ -209,7 +214,7 @@ Common.prototype.truncateAttributes = function (
|
|
|
209
214
|
return truncatedAttributes;
|
|
210
215
|
};
|
|
211
216
|
|
|
212
|
-
Common.prototype.limitAttributes = function
|
|
217
|
+
Common.prototype.limitAttributes = function(attributes, limitNumber) {
|
|
213
218
|
if (isEmpty(attributes)) {
|
|
214
219
|
return {};
|
|
215
220
|
}
|
|
@@ -220,7 +225,7 @@ Common.prototype.limitAttributes = function (attributes, limitNumber) {
|
|
|
220
225
|
|
|
221
226
|
var limitedAttributes = attributeKeys
|
|
222
227
|
.slice(0, limitNumber)
|
|
223
|
-
.reduce(function
|
|
228
|
+
.reduce(function(obj, key) {
|
|
224
229
|
obj[key] = attributes[key];
|
|
225
230
|
return obj;
|
|
226
231
|
}, {});
|
|
@@ -228,11 +233,11 @@ Common.prototype.limitAttributes = function (attributes, limitNumber) {
|
|
|
228
233
|
return limitedAttributes;
|
|
229
234
|
};
|
|
230
235
|
|
|
231
|
-
Common.prototype.limitEventAttributes = function
|
|
236
|
+
Common.prototype.limitEventAttributes = function(attributes) {
|
|
232
237
|
return this.limitAttributes(attributes, EVENT_ATTRIBUTE_MAX_NUMBER);
|
|
233
238
|
};
|
|
234
239
|
|
|
235
|
-
Common.prototype.limitProductAttributes = function
|
|
240
|
+
Common.prototype.limitProductAttributes = function(attributes) {
|
|
236
241
|
var productAttributes = {};
|
|
237
242
|
var reservedAttributes = {};
|
|
238
243
|
|
|
@@ -252,13 +257,13 @@ Common.prototype.limitProductAttributes = function (attributes) {
|
|
|
252
257
|
return this.mergeObjects(limitedProductAttributes, reservedAttributes);
|
|
253
258
|
};
|
|
254
259
|
|
|
255
|
-
Common.prototype.getEventConsentState = function
|
|
260
|
+
Common.prototype.getEventConsentState = function(eventConsentState) {
|
|
256
261
|
return eventConsentState && eventConsentState.getGDPRConsentState
|
|
257
262
|
? eventConsentState.getGDPRConsentState()
|
|
258
263
|
: {};
|
|
259
264
|
};
|
|
260
265
|
|
|
261
|
-
Common.prototype.maybeSendConsentUpdateToGoogle = function
|
|
266
|
+
Common.prototype.maybeSendConsentUpdateToGoogle = function(consentState) {
|
|
262
267
|
// If consent payload is empty,
|
|
263
268
|
// we never sent an initial default consent state
|
|
264
269
|
// so we shouldn't send an update.
|
|
@@ -267,11 +272,10 @@ Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
|
|
|
267
272
|
this.consentMappings &&
|
|
268
273
|
!this.isEmpty(consentState)
|
|
269
274
|
) {
|
|
270
|
-
var updatedConsentPayload =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
);
|
|
275
|
+
var updatedConsentPayload = this.consentHandler.generateConsentStatePayloadFromMappings(
|
|
276
|
+
consentState,
|
|
277
|
+
this.consentMappings
|
|
278
|
+
);
|
|
275
279
|
|
|
276
280
|
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
|
|
277
281
|
|
|
@@ -282,17 +286,17 @@ Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
|
|
|
282
286
|
}
|
|
283
287
|
};
|
|
284
288
|
|
|
285
|
-
Common.prototype.sendDefaultConsentPayloadToGoogle = function
|
|
289
|
+
Common.prototype.sendDefaultConsentPayloadToGoogle = function(consentPayload) {
|
|
286
290
|
this.consentPayloadAsString = JSON.stringify(consentPayload);
|
|
287
291
|
|
|
288
292
|
gtag('consent', 'default', consentPayload);
|
|
289
293
|
};
|
|
290
294
|
|
|
291
|
-
Common.prototype.truncateEventName = function
|
|
295
|
+
Common.prototype.truncateEventName = function(eventName) {
|
|
292
296
|
return truncateString(eventName, EVENT_NAME_MAX_LENGTH);
|
|
293
297
|
};
|
|
294
298
|
|
|
295
|
-
Common.prototype.truncateEventAttributes = function
|
|
299
|
+
Common.prototype.truncateEventAttributes = function(eventAttributes) {
|
|
296
300
|
return this.truncateAttributes(
|
|
297
301
|
eventAttributes,
|
|
298
302
|
EVENT_ATTRIBUTE_KEY_MAX_LENGTH,
|
|
@@ -300,7 +304,7 @@ Common.prototype.truncateEventAttributes = function (eventAttributes) {
|
|
|
300
304
|
);
|
|
301
305
|
};
|
|
302
306
|
|
|
303
|
-
Common.prototype.standardizeParameters = function
|
|
307
|
+
Common.prototype.standardizeParameters = function(parameters) {
|
|
304
308
|
var standardizedParameters = {};
|
|
305
309
|
for (var key in parameters) {
|
|
306
310
|
var standardizedKey = this.standardizeName(key);
|
|
@@ -309,10 +313,16 @@ Common.prototype.standardizeParameters = function (parameters) {
|
|
|
309
313
|
return standardizedParameters;
|
|
310
314
|
};
|
|
311
315
|
|
|
312
|
-
Common.prototype.standardizeName = function
|
|
313
|
-
if (
|
|
316
|
+
Common.prototype.standardizeName = function(name) {
|
|
317
|
+
if (
|
|
318
|
+
window.GoogleAnalytics4Kit.hasOwnProperty(
|
|
319
|
+
'setCustomNameStandardization'
|
|
320
|
+
)
|
|
321
|
+
) {
|
|
314
322
|
try {
|
|
315
|
-
name = window.GoogleAnalytics4Kit.setCustomNameStandardization(
|
|
323
|
+
name = window.GoogleAnalytics4Kit.setCustomNameStandardization(
|
|
324
|
+
name
|
|
325
|
+
);
|
|
316
326
|
} catch (e) {
|
|
317
327
|
console.warn(
|
|
318
328
|
'Error calling setCustomNameStandardization callback. Check your callback. Data will still be sent without user-defined standardization. See our docs for proper use - https://docs.mparticle.com/integrations/google-analytics-4/event/',
|
|
@@ -359,7 +369,7 @@ Common.prototype.standardizeName = function (name) {
|
|
|
359
369
|
function removeForbiddenPrefix(name) {
|
|
360
370
|
var str = name.slice();
|
|
361
371
|
|
|
362
|
-
FORBIDDEN_PREFIXES.forEach(function
|
|
372
|
+
FORBIDDEN_PREFIXES.forEach(function(prefix) {
|
|
363
373
|
if (str.indexOf(prefix) === 0) {
|
|
364
374
|
str = str.replace(prefix, '');
|
|
365
375
|
}
|
|
@@ -380,15 +390,16 @@ Common.prototype.standardizeName = function (name) {
|
|
|
380
390
|
!doesNameStartsWithLetter(standardizedName) ||
|
|
381
391
|
doesNameStartWithForbiddenPrefix(standardizedName)
|
|
382
392
|
) {
|
|
383
|
-
standardizedName =
|
|
384
|
-
|
|
393
|
+
standardizedName = removeNonAlphabetCharacterFromStart(
|
|
394
|
+
standardizedName
|
|
395
|
+
);
|
|
385
396
|
standardizedName = removeForbiddenPrefix(standardizedName);
|
|
386
397
|
}
|
|
387
398
|
|
|
388
399
|
return standardizedName;
|
|
389
400
|
};
|
|
390
401
|
|
|
391
|
-
Common.prototype.truncateUserAttributes = function
|
|
402
|
+
Common.prototype.truncateUserAttributes = function(userAttributes) {
|
|
392
403
|
return this.truncateAttributes(
|
|
393
404
|
userAttributes,
|
|
394
405
|
USER_ATTRIBUTE_KEY_MAX_LENGTH,
|
|
@@ -396,7 +407,7 @@ Common.prototype.truncateUserAttributes = function (userAttributes) {
|
|
|
396
407
|
);
|
|
397
408
|
};
|
|
398
409
|
|
|
399
|
-
Common.prototype.getUserId = function
|
|
410
|
+
Common.prototype.getUserId = function(
|
|
400
411
|
user,
|
|
401
412
|
externalUserIdentityType,
|
|
402
413
|
hashUserId
|
|
@@ -483,7 +494,7 @@ Common.prototype.getUserId = function (
|
|
|
483
494
|
}
|
|
484
495
|
};
|
|
485
496
|
|
|
486
|
-
Common.prototype.cloneObject = function
|
|
497
|
+
Common.prototype.cloneObject = function(obj) {
|
|
487
498
|
return JSON.parse(JSON.stringify(obj));
|
|
488
499
|
};
|
|
489
500
|
|
|
@@ -526,7 +537,7 @@ var ADD_SHIPPING_INFO = 'add_shipping_info',
|
|
|
526
537
|
ADD_PAYMENT_INFO = 'add_payment_info',
|
|
527
538
|
VIEW_CART = 'view_cart';
|
|
528
539
|
|
|
529
|
-
CommerceHandler.prototype.logCommerceEvent = function
|
|
540
|
+
CommerceHandler.prototype.logCommerceEvent = function(event) {
|
|
530
541
|
var needsCurrency = true,
|
|
531
542
|
needsValue = true,
|
|
532
543
|
ga4CommerceEventParameters = {},
|
|
@@ -637,7 +648,7 @@ CommerceHandler.prototype.logCommerceEvent = function (event) {
|
|
|
637
648
|
);
|
|
638
649
|
};
|
|
639
650
|
|
|
640
|
-
CommerceHandler.prototype.sendCommerceEventToGA4 = function
|
|
651
|
+
CommerceHandler.prototype.sendCommerceEventToGA4 = function(
|
|
641
652
|
eventName,
|
|
642
653
|
eventAttributes
|
|
643
654
|
) {
|
|
@@ -653,7 +664,7 @@ CommerceHandler.prototype.sendCommerceEventToGA4 = function (
|
|
|
653
664
|
// Google previously had a CheckoutOption event, and now this has been split into 2 GA4 events - add_shipping_info and add_payment_info
|
|
654
665
|
// Since MP still uses CheckoutOption, we must map this to the 2 events using custom flags. To prevent any data loss from customers
|
|
655
666
|
// migrating from UA to GA4, we will set a default `set_checkout_option` which matches Firebase's data model.
|
|
656
|
-
CommerceHandler.prototype.logCheckoutOptionEvent = function
|
|
667
|
+
CommerceHandler.prototype.logCheckoutOptionEvent = function(
|
|
657
668
|
event,
|
|
658
669
|
affiliation
|
|
659
670
|
) {
|
|
@@ -697,17 +708,22 @@ CommerceHandler.prototype.logCheckoutOptionEvent = function (
|
|
|
697
708
|
return false;
|
|
698
709
|
}
|
|
699
710
|
|
|
711
|
+
ga4CommerceEventParameters = this.common.mergeObjects(
|
|
712
|
+
ga4CommerceEventParameters,
|
|
713
|
+
this.common.limitEventAttributes(event.EventAttributes)
|
|
714
|
+
);
|
|
715
|
+
|
|
700
716
|
return this.sendCommerceEventToGA4(
|
|
701
717
|
mapGA4EcommerceEventName(event),
|
|
702
718
|
ga4CommerceEventParameters
|
|
703
719
|
);
|
|
704
720
|
};
|
|
705
721
|
|
|
706
|
-
CommerceHandler.prototype.logPromotionEvent = function
|
|
722
|
+
CommerceHandler.prototype.logPromotionEvent = function(event) {
|
|
707
723
|
var self = this;
|
|
708
724
|
try {
|
|
709
725
|
var ga4CommerceEventParameters;
|
|
710
|
-
event.PromotionAction.PromotionList.forEach(function
|
|
726
|
+
event.PromotionAction.PromotionList.forEach(function(promotion) {
|
|
711
727
|
ga4CommerceEventParameters = buildPromotion(promotion);
|
|
712
728
|
|
|
713
729
|
ga4CommerceEventParameters = self.common.mergeObjects(
|
|
@@ -731,11 +747,11 @@ CommerceHandler.prototype.logPromotionEvent = function (event) {
|
|
|
731
747
|
}
|
|
732
748
|
};
|
|
733
749
|
|
|
734
|
-
CommerceHandler.prototype.logImpressionEvent = function
|
|
750
|
+
CommerceHandler.prototype.logImpressionEvent = function(event, affiliation) {
|
|
735
751
|
var self = this;
|
|
736
752
|
try {
|
|
737
753
|
var ga4CommerceEventParameters;
|
|
738
|
-
event.ProductImpressions.forEach(function
|
|
754
|
+
event.ProductImpressions.forEach(function(impression) {
|
|
739
755
|
ga4CommerceEventParameters = parseImpression(
|
|
740
756
|
impression,
|
|
741
757
|
affiliation
|
|
@@ -762,7 +778,7 @@ CommerceHandler.prototype.logImpressionEvent = function (event, affiliation) {
|
|
|
762
778
|
}
|
|
763
779
|
};
|
|
764
780
|
|
|
765
|
-
CommerceHandler.prototype.logViewCart = function
|
|
781
|
+
CommerceHandler.prototype.logViewCart = function(event, affiliation) {
|
|
766
782
|
var ga4CommerceEventParameters = buildViewCart(event, affiliation);
|
|
767
783
|
ga4CommerceEventParameters = this.common.mergeObjects(
|
|
768
784
|
ga4CommerceEventParameters,
|
|
@@ -980,7 +996,7 @@ function parsePromotion(_promotion) {
|
|
|
980
996
|
function buildProductsList(products, affiliation) {
|
|
981
997
|
var productsList = [];
|
|
982
998
|
|
|
983
|
-
products.forEach(function
|
|
999
|
+
products.forEach(function(product) {
|
|
984
1000
|
productsList.push(parseProduct(product, affiliation));
|
|
985
1001
|
});
|
|
986
1002
|
|
|
@@ -1051,13 +1067,14 @@ function EventHandler(common) {
|
|
|
1051
1067
|
}
|
|
1052
1068
|
|
|
1053
1069
|
// TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5715
|
|
1054
|
-
EventHandler.prototype.sendEventToGA4 = function
|
|
1070
|
+
EventHandler.prototype.sendEventToGA4 = function(eventName, eventAttributes) {
|
|
1055
1071
|
var standardizedEventName;
|
|
1056
1072
|
var standardizedAttributes;
|
|
1057
1073
|
if (this.common.forwarderSettings.enableDataCleansing) {
|
|
1058
1074
|
standardizedEventName = this.common.standardizeName(eventName);
|
|
1059
|
-
standardizedAttributes =
|
|
1060
|
-
|
|
1075
|
+
standardizedAttributes = this.common.standardizeParameters(
|
|
1076
|
+
eventAttributes
|
|
1077
|
+
);
|
|
1061
1078
|
} else {
|
|
1062
1079
|
standardizedEventName = eventName;
|
|
1063
1080
|
standardizedAttributes = eventAttributes;
|
|
@@ -1068,8 +1085,7 @@ EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
|
|
|
1068
1085
|
);
|
|
1069
1086
|
|
|
1070
1087
|
if (this.common.forwarderSettings.measurementId) {
|
|
1071
|
-
standardizedAttributes.send_to =
|
|
1072
|
-
this.common.forwarderSettings.measurementId;
|
|
1088
|
+
standardizedAttributes.send_to = this.common.forwarderSettings.measurementId;
|
|
1073
1089
|
}
|
|
1074
1090
|
|
|
1075
1091
|
gtag(
|
|
@@ -1079,7 +1095,7 @@ EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
|
|
|
1079
1095
|
);
|
|
1080
1096
|
};
|
|
1081
1097
|
|
|
1082
|
-
EventHandler.prototype.logEvent = function
|
|
1098
|
+
EventHandler.prototype.logEvent = function(event) {
|
|
1083
1099
|
var eventConsentState = this.common.getEventConsentState(
|
|
1084
1100
|
event.ConsentState
|
|
1085
1101
|
);
|
|
@@ -1087,11 +1103,11 @@ EventHandler.prototype.logEvent = function (event) {
|
|
|
1087
1103
|
this.sendEventToGA4(event.EventName, event.EventAttributes);
|
|
1088
1104
|
};
|
|
1089
1105
|
|
|
1090
|
-
EventHandler.prototype.logError = function
|
|
1106
|
+
EventHandler.prototype.logError = function() {
|
|
1091
1107
|
console.warn('Google Analytics 4 does not support error events.');
|
|
1092
1108
|
};
|
|
1093
1109
|
|
|
1094
|
-
EventHandler.prototype.logPageView = function
|
|
1110
|
+
EventHandler.prototype.logPageView = function(event) {
|
|
1095
1111
|
var TITLE = 'GA4.Title';
|
|
1096
1112
|
var LOCATION = 'GA4.Location';
|
|
1097
1113
|
var REFERRER = 'GA4.Referrer';
|
|
@@ -1168,7 +1184,7 @@ For more userIdentity types, see http://docs.mparticle.com/developers/sdk/javasc
|
|
|
1168
1184
|
function IdentityHandler(common) {
|
|
1169
1185
|
this.common = common || {};
|
|
1170
1186
|
}
|
|
1171
|
-
IdentityHandler.prototype.onUserIdentified = function
|
|
1187
|
+
IdentityHandler.prototype.onUserIdentified = function(mParticleUser) {
|
|
1172
1188
|
var userId = this.common.getUserId(
|
|
1173
1189
|
mParticleUser,
|
|
1174
1190
|
this.common.forwarderSettings.externalUserIdentityType,
|
|
@@ -1180,19 +1196,19 @@ IdentityHandler.prototype.onUserIdentified = function (mParticleUser) {
|
|
|
1180
1196
|
user_id: userId,
|
|
1181
1197
|
});
|
|
1182
1198
|
};
|
|
1183
|
-
IdentityHandler.prototype.onIdentifyComplete = function
|
|
1199
|
+
IdentityHandler.prototype.onIdentifyComplete = function(
|
|
1184
1200
|
mParticleUser,
|
|
1185
1201
|
identityApiRequest
|
|
1186
1202
|
) {};
|
|
1187
|
-
IdentityHandler.prototype.onLoginComplete = function
|
|
1203
|
+
IdentityHandler.prototype.onLoginComplete = function(
|
|
1188
1204
|
mParticleUser,
|
|
1189
1205
|
identityApiRequest
|
|
1190
1206
|
) {};
|
|
1191
|
-
IdentityHandler.prototype.onLogoutComplete = function
|
|
1207
|
+
IdentityHandler.prototype.onLogoutComplete = function(
|
|
1192
1208
|
mParticleUser,
|
|
1193
1209
|
identityApiRequest
|
|
1194
1210
|
) {};
|
|
1195
|
-
IdentityHandler.prototype.onModifyComplete = function
|
|
1211
|
+
IdentityHandler.prototype.onModifyComplete = function(
|
|
1196
1212
|
mParticleUser,
|
|
1197
1213
|
identityApiRequest
|
|
1198
1214
|
) {};
|
|
@@ -1201,7 +1217,7 @@ IdentityHandler.prototype.onModifyComplete = function (
|
|
|
1201
1217
|
kits is only reachable via the onSetUserIdentity method below. We recommend
|
|
1202
1218
|
filling out `onSetUserIdentity` for maximum compatibility
|
|
1203
1219
|
*/
|
|
1204
|
-
IdentityHandler.prototype.onSetUserIdentity = function
|
|
1220
|
+
IdentityHandler.prototype.onSetUserIdentity = function(
|
|
1205
1221
|
forwarderSettings,
|
|
1206
1222
|
id,
|
|
1207
1223
|
type
|
|
@@ -1222,7 +1238,7 @@ var initialization = {
|
|
|
1222
1238
|
userIdentities example: { 1: 'customerId', 2: 'facebookId', 7: 'emailid@email.com' }
|
|
1223
1239
|
additional identityTypes can be found at https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101
|
|
1224
1240
|
*/
|
|
1225
|
-
initForwarder: function
|
|
1241
|
+
initForwarder: function(
|
|
1226
1242
|
forwarderSettings,
|
|
1227
1243
|
testMode,
|
|
1228
1244
|
userAttributes,
|
|
@@ -1266,7 +1282,7 @@ var initialization = {
|
|
|
1266
1282
|
|
|
1267
1283
|
window.dataLayer = window.dataLayer || [];
|
|
1268
1284
|
|
|
1269
|
-
window.gtag = function
|
|
1285
|
+
window.gtag = function() {
|
|
1270
1286
|
window.dataLayer.push(arguments);
|
|
1271
1287
|
};
|
|
1272
1288
|
gtag('js', new Date());
|
|
@@ -1285,7 +1301,7 @@ var initialization = {
|
|
|
1285
1301
|
}
|
|
1286
1302
|
gtag('config', measurementId, configSettings);
|
|
1287
1303
|
|
|
1288
|
-
gtag('get', measurementId, 'client_id', function
|
|
1304
|
+
gtag('get', measurementId, 'client_id', function(clientId) {
|
|
1289
1305
|
setClientId(clientId, initialization.moduleId);
|
|
1290
1306
|
});
|
|
1291
1307
|
|
|
@@ -1300,7 +1316,7 @@ var initialization = {
|
|
|
1300
1316
|
document.getElementsByTagName('body')[0]
|
|
1301
1317
|
).appendChild(clientScript);
|
|
1302
1318
|
|
|
1303
|
-
clientScript.onload = function
|
|
1319
|
+
clientScript.onload = function() {
|
|
1304
1320
|
isInitialized = true;
|
|
1305
1321
|
|
|
1306
1322
|
if (window.dataLayer && gtag && eventQueue.length > 0) {
|
|
@@ -1314,23 +1330,21 @@ var initialization = {
|
|
|
1314
1330
|
isInitialized = true;
|
|
1315
1331
|
}
|
|
1316
1332
|
|
|
1317
|
-
common.consentPayloadDefaults =
|
|
1318
|
-
common.consentHandler.getConsentSettings();
|
|
1333
|
+
common.consentPayloadDefaults = common.consentHandler.getConsentSettings();
|
|
1319
1334
|
var defaultConsentPayload = common.cloneObject(
|
|
1320
1335
|
common.consentPayloadDefaults
|
|
1321
1336
|
);
|
|
1322
1337
|
var updatedConsentState = common.consentHandler.getUserConsentState();
|
|
1323
|
-
var updatedDefaultConsentPayload =
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
);
|
|
1338
|
+
var updatedDefaultConsentPayload = common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
1339
|
+
updatedConsentState,
|
|
1340
|
+
common.consentMappings
|
|
1341
|
+
);
|
|
1328
1342
|
|
|
1329
1343
|
// If a default consent payload exists (as selected in the mParticle UI), set it as the default
|
|
1330
1344
|
if (!common.isEmpty(defaultConsentPayload)) {
|
|
1331
1345
|
common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
|
|
1332
|
-
|
|
1333
|
-
|
|
1346
|
+
// If a default consent payload does not exist, but the user currently has updated their consent,
|
|
1347
|
+
// send that as the default because a default must be sent
|
|
1334
1348
|
} else if (!common.isEmpty(updatedDefaultConsentPayload)) {
|
|
1335
1349
|
common.sendDefaultConsentPayloadToGoogle(
|
|
1336
1350
|
updatedDefaultConsentPayload
|
|
@@ -1361,12 +1375,8 @@ function parseSettingsString(settingsString) {
|
|
|
1361
1375
|
var initialization_1 = initialization;
|
|
1362
1376
|
|
|
1363
1377
|
var sessionHandler = {
|
|
1364
|
-
onSessionStart: function(event) {
|
|
1365
|
-
|
|
1366
|
-
},
|
|
1367
|
-
onSessionEnd: function(event) {
|
|
1368
|
-
|
|
1369
|
-
}
|
|
1378
|
+
onSessionStart: function(event) {},
|
|
1379
|
+
onSessionEnd: function(event) {},
|
|
1370
1380
|
};
|
|
1371
1381
|
|
|
1372
1382
|
var sessionHandler_1 = sessionHandler;
|
|
@@ -1375,7 +1385,7 @@ function UserAttributeHandler(common) {
|
|
|
1375
1385
|
this.common = common || {};
|
|
1376
1386
|
}
|
|
1377
1387
|
|
|
1378
|
-
UserAttributeHandler.prototype.sendUserPropertiesToGA4 = function
|
|
1388
|
+
UserAttributeHandler.prototype.sendUserPropertiesToGA4 = function(
|
|
1379
1389
|
userAttributes
|
|
1380
1390
|
) {
|
|
1381
1391
|
gtag(
|
|
@@ -1389,13 +1399,13 @@ UserAttributeHandler.prototype.sendUserPropertiesToGA4 = function (
|
|
|
1389
1399
|
// In the future if mParticleUser is ever required for an implementation of any of the below APIs, see https://github.com/mparticle-integrations/mparticle-javascript-integration-example/blob/master/src/user-attribute-handler.js
|
|
1390
1400
|
// for previous function signatures
|
|
1391
1401
|
|
|
1392
|
-
UserAttributeHandler.prototype.onRemoveUserAttribute = function
|
|
1402
|
+
UserAttributeHandler.prototype.onRemoveUserAttribute = function(key) {
|
|
1393
1403
|
var userAttributes = {};
|
|
1394
1404
|
userAttributes[key] = null;
|
|
1395
1405
|
this.sendUserPropertiesToGA4(userAttributes);
|
|
1396
1406
|
};
|
|
1397
1407
|
|
|
1398
|
-
UserAttributeHandler.prototype.onSetUserAttribute = function
|
|
1408
|
+
UserAttributeHandler.prototype.onSetUserAttribute = function(key, value) {
|
|
1399
1409
|
var userAttributes = {};
|
|
1400
1410
|
userAttributes[key] = value;
|
|
1401
1411
|
this.sendUserPropertiesToGA4(userAttributes);
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-google-analytics-4-client-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "3.1.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",
|
|
7
7
|
"browser": "dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist/
|
|
9
|
+
"dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "ENVIRONMENT=production rollup --config rollup.config.js",
|
|
@@ -17,14 +17,22 @@
|
|
|
17
17
|
"testEndToEnd": "ENVIRONMENT=testEndToEnd rollup --config rollup.config.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"
|
|
18
18
|
},
|
|
19
19
|
"publishConfig": {
|
|
20
|
-
"access": "public"
|
|
20
|
+
"access": "public",
|
|
21
|
+
"provenance": true,
|
|
22
|
+
"registry": "https://registry.npmjs.org"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/mParticle/mparticle-web-sdk",
|
|
27
|
+
"directory": "kits/google-analytics-4/packages/GA4Client"
|
|
21
28
|
},
|
|
22
|
-
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-google-analytics-4/tree/master/packages/GA4Client",
|
|
23
29
|
"devDependencies": {
|
|
24
30
|
"@mparticle/web-kit-wrapper": "^1.0.5",
|
|
25
|
-
"@semantic-release/changelog": "^
|
|
26
|
-
"@semantic-release/exec": "^
|
|
27
|
-
"@semantic-release/git": "^
|
|
31
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
32
|
+
"@semantic-release/exec": "^6.0.3",
|
|
33
|
+
"@semantic-release/git": "^10.0.1",
|
|
34
|
+
"@semantic-release/npm": "^13.1.2",
|
|
35
|
+
"semantic-release": "^24.2.0",
|
|
28
36
|
"chai": "^4.2.0",
|
|
29
37
|
"eslint": "^7.25.0",
|
|
30
38
|
"eslint-config-prettier": "8.3.0",
|
|
@@ -45,7 +53,7 @@
|
|
|
45
53
|
"watchify": "^3.11.0"
|
|
46
54
|
},
|
|
47
55
|
"dependencies": {
|
|
48
|
-
"@mparticle/web-sdk": "^
|
|
56
|
+
"@mparticle/web-sdk": "^3.0.0"
|
|
49
57
|
},
|
|
50
58
|
"license": "Apache-2.0"
|
|
51
59
|
}
|