@mparticle/web-google-analytics-4-client-kit 1.5.1 → 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
|
) {
|
|
@@ -708,11 +719,11 @@ CommerceHandler.prototype.logCheckoutOptionEvent = function (
|
|
|
708
719
|
);
|
|
709
720
|
};
|
|
710
721
|
|
|
711
|
-
CommerceHandler.prototype.logPromotionEvent = function
|
|
722
|
+
CommerceHandler.prototype.logPromotionEvent = function(event) {
|
|
712
723
|
var self = this;
|
|
713
724
|
try {
|
|
714
725
|
var ga4CommerceEventParameters;
|
|
715
|
-
event.PromotionAction.PromotionList.forEach(function
|
|
726
|
+
event.PromotionAction.PromotionList.forEach(function(promotion) {
|
|
716
727
|
ga4CommerceEventParameters = buildPromotion(promotion);
|
|
717
728
|
|
|
718
729
|
ga4CommerceEventParameters = self.common.mergeObjects(
|
|
@@ -736,11 +747,11 @@ CommerceHandler.prototype.logPromotionEvent = function (event) {
|
|
|
736
747
|
}
|
|
737
748
|
};
|
|
738
749
|
|
|
739
|
-
CommerceHandler.prototype.logImpressionEvent = function
|
|
750
|
+
CommerceHandler.prototype.logImpressionEvent = function(event, affiliation) {
|
|
740
751
|
var self = this;
|
|
741
752
|
try {
|
|
742
753
|
var ga4CommerceEventParameters;
|
|
743
|
-
event.ProductImpressions.forEach(function
|
|
754
|
+
event.ProductImpressions.forEach(function(impression) {
|
|
744
755
|
ga4CommerceEventParameters = parseImpression(
|
|
745
756
|
impression,
|
|
746
757
|
affiliation
|
|
@@ -767,7 +778,7 @@ CommerceHandler.prototype.logImpressionEvent = function (event, affiliation) {
|
|
|
767
778
|
}
|
|
768
779
|
};
|
|
769
780
|
|
|
770
|
-
CommerceHandler.prototype.logViewCart = function
|
|
781
|
+
CommerceHandler.prototype.logViewCart = function(event, affiliation) {
|
|
771
782
|
var ga4CommerceEventParameters = buildViewCart(event, affiliation);
|
|
772
783
|
ga4CommerceEventParameters = this.common.mergeObjects(
|
|
773
784
|
ga4CommerceEventParameters,
|
|
@@ -985,7 +996,7 @@ function parsePromotion(_promotion) {
|
|
|
985
996
|
function buildProductsList(products, affiliation) {
|
|
986
997
|
var productsList = [];
|
|
987
998
|
|
|
988
|
-
products.forEach(function
|
|
999
|
+
products.forEach(function(product) {
|
|
989
1000
|
productsList.push(parseProduct(product, affiliation));
|
|
990
1001
|
});
|
|
991
1002
|
|
|
@@ -1056,13 +1067,14 @@ function EventHandler(common) {
|
|
|
1056
1067
|
}
|
|
1057
1068
|
|
|
1058
1069
|
// TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5715
|
|
1059
|
-
EventHandler.prototype.sendEventToGA4 = function
|
|
1070
|
+
EventHandler.prototype.sendEventToGA4 = function(eventName, eventAttributes) {
|
|
1060
1071
|
var standardizedEventName;
|
|
1061
1072
|
var standardizedAttributes;
|
|
1062
1073
|
if (this.common.forwarderSettings.enableDataCleansing) {
|
|
1063
1074
|
standardizedEventName = this.common.standardizeName(eventName);
|
|
1064
|
-
standardizedAttributes =
|
|
1065
|
-
|
|
1075
|
+
standardizedAttributes = this.common.standardizeParameters(
|
|
1076
|
+
eventAttributes
|
|
1077
|
+
);
|
|
1066
1078
|
} else {
|
|
1067
1079
|
standardizedEventName = eventName;
|
|
1068
1080
|
standardizedAttributes = eventAttributes;
|
|
@@ -1073,8 +1085,7 @@ EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
|
|
|
1073
1085
|
);
|
|
1074
1086
|
|
|
1075
1087
|
if (this.common.forwarderSettings.measurementId) {
|
|
1076
|
-
standardizedAttributes.send_to =
|
|
1077
|
-
this.common.forwarderSettings.measurementId;
|
|
1088
|
+
standardizedAttributes.send_to = this.common.forwarderSettings.measurementId;
|
|
1078
1089
|
}
|
|
1079
1090
|
|
|
1080
1091
|
gtag(
|
|
@@ -1084,7 +1095,7 @@ EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
|
|
|
1084
1095
|
);
|
|
1085
1096
|
};
|
|
1086
1097
|
|
|
1087
|
-
EventHandler.prototype.logEvent = function
|
|
1098
|
+
EventHandler.prototype.logEvent = function(event) {
|
|
1088
1099
|
var eventConsentState = this.common.getEventConsentState(
|
|
1089
1100
|
event.ConsentState
|
|
1090
1101
|
);
|
|
@@ -1092,11 +1103,11 @@ EventHandler.prototype.logEvent = function (event) {
|
|
|
1092
1103
|
this.sendEventToGA4(event.EventName, event.EventAttributes);
|
|
1093
1104
|
};
|
|
1094
1105
|
|
|
1095
|
-
EventHandler.prototype.logError = function
|
|
1106
|
+
EventHandler.prototype.logError = function() {
|
|
1096
1107
|
console.warn('Google Analytics 4 does not support error events.');
|
|
1097
1108
|
};
|
|
1098
1109
|
|
|
1099
|
-
EventHandler.prototype.logPageView = function
|
|
1110
|
+
EventHandler.prototype.logPageView = function(event) {
|
|
1100
1111
|
var TITLE = 'GA4.Title';
|
|
1101
1112
|
var LOCATION = 'GA4.Location';
|
|
1102
1113
|
var REFERRER = 'GA4.Referrer';
|
|
@@ -1173,7 +1184,7 @@ For more userIdentity types, see http://docs.mparticle.com/developers/sdk/javasc
|
|
|
1173
1184
|
function IdentityHandler(common) {
|
|
1174
1185
|
this.common = common || {};
|
|
1175
1186
|
}
|
|
1176
|
-
IdentityHandler.prototype.onUserIdentified = function
|
|
1187
|
+
IdentityHandler.prototype.onUserIdentified = function(mParticleUser) {
|
|
1177
1188
|
var userId = this.common.getUserId(
|
|
1178
1189
|
mParticleUser,
|
|
1179
1190
|
this.common.forwarderSettings.externalUserIdentityType,
|
|
@@ -1185,19 +1196,19 @@ IdentityHandler.prototype.onUserIdentified = function (mParticleUser) {
|
|
|
1185
1196
|
user_id: userId,
|
|
1186
1197
|
});
|
|
1187
1198
|
};
|
|
1188
|
-
IdentityHandler.prototype.onIdentifyComplete = function
|
|
1199
|
+
IdentityHandler.prototype.onIdentifyComplete = function(
|
|
1189
1200
|
mParticleUser,
|
|
1190
1201
|
identityApiRequest
|
|
1191
1202
|
) {};
|
|
1192
|
-
IdentityHandler.prototype.onLoginComplete = function
|
|
1203
|
+
IdentityHandler.prototype.onLoginComplete = function(
|
|
1193
1204
|
mParticleUser,
|
|
1194
1205
|
identityApiRequest
|
|
1195
1206
|
) {};
|
|
1196
|
-
IdentityHandler.prototype.onLogoutComplete = function
|
|
1207
|
+
IdentityHandler.prototype.onLogoutComplete = function(
|
|
1197
1208
|
mParticleUser,
|
|
1198
1209
|
identityApiRequest
|
|
1199
1210
|
) {};
|
|
1200
|
-
IdentityHandler.prototype.onModifyComplete = function
|
|
1211
|
+
IdentityHandler.prototype.onModifyComplete = function(
|
|
1201
1212
|
mParticleUser,
|
|
1202
1213
|
identityApiRequest
|
|
1203
1214
|
) {};
|
|
@@ -1206,7 +1217,7 @@ IdentityHandler.prototype.onModifyComplete = function (
|
|
|
1206
1217
|
kits is only reachable via the onSetUserIdentity method below. We recommend
|
|
1207
1218
|
filling out `onSetUserIdentity` for maximum compatibility
|
|
1208
1219
|
*/
|
|
1209
|
-
IdentityHandler.prototype.onSetUserIdentity = function
|
|
1220
|
+
IdentityHandler.prototype.onSetUserIdentity = function(
|
|
1210
1221
|
forwarderSettings,
|
|
1211
1222
|
id,
|
|
1212
1223
|
type
|
|
@@ -1227,7 +1238,7 @@ var initialization = {
|
|
|
1227
1238
|
userIdentities example: { 1: 'customerId', 2: 'facebookId', 7: 'emailid@email.com' }
|
|
1228
1239
|
additional identityTypes can be found at https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101
|
|
1229
1240
|
*/
|
|
1230
|
-
initForwarder: function
|
|
1241
|
+
initForwarder: function(
|
|
1231
1242
|
forwarderSettings,
|
|
1232
1243
|
testMode,
|
|
1233
1244
|
userAttributes,
|
|
@@ -1271,7 +1282,7 @@ var initialization = {
|
|
|
1271
1282
|
|
|
1272
1283
|
window.dataLayer = window.dataLayer || [];
|
|
1273
1284
|
|
|
1274
|
-
window.gtag = function
|
|
1285
|
+
window.gtag = function() {
|
|
1275
1286
|
window.dataLayer.push(arguments);
|
|
1276
1287
|
};
|
|
1277
1288
|
gtag('js', new Date());
|
|
@@ -1290,7 +1301,7 @@ var initialization = {
|
|
|
1290
1301
|
}
|
|
1291
1302
|
gtag('config', measurementId, configSettings);
|
|
1292
1303
|
|
|
1293
|
-
gtag('get', measurementId, 'client_id', function
|
|
1304
|
+
gtag('get', measurementId, 'client_id', function(clientId) {
|
|
1294
1305
|
setClientId(clientId, initialization.moduleId);
|
|
1295
1306
|
});
|
|
1296
1307
|
|
|
@@ -1305,7 +1316,7 @@ var initialization = {
|
|
|
1305
1316
|
document.getElementsByTagName('body')[0]
|
|
1306
1317
|
).appendChild(clientScript);
|
|
1307
1318
|
|
|
1308
|
-
clientScript.onload = function
|
|
1319
|
+
clientScript.onload = function() {
|
|
1309
1320
|
isInitialized = true;
|
|
1310
1321
|
|
|
1311
1322
|
if (window.dataLayer && gtag && eventQueue.length > 0) {
|
|
@@ -1319,23 +1330,21 @@ var initialization = {
|
|
|
1319
1330
|
isInitialized = true;
|
|
1320
1331
|
}
|
|
1321
1332
|
|
|
1322
|
-
common.consentPayloadDefaults =
|
|
1323
|
-
common.consentHandler.getConsentSettings();
|
|
1333
|
+
common.consentPayloadDefaults = common.consentHandler.getConsentSettings();
|
|
1324
1334
|
var defaultConsentPayload = common.cloneObject(
|
|
1325
1335
|
common.consentPayloadDefaults
|
|
1326
1336
|
);
|
|
1327
1337
|
var updatedConsentState = common.consentHandler.getUserConsentState();
|
|
1328
|
-
var updatedDefaultConsentPayload =
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
);
|
|
1338
|
+
var updatedDefaultConsentPayload = common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
1339
|
+
updatedConsentState,
|
|
1340
|
+
common.consentMappings
|
|
1341
|
+
);
|
|
1333
1342
|
|
|
1334
1343
|
// If a default consent payload exists (as selected in the mParticle UI), set it as the default
|
|
1335
1344
|
if (!common.isEmpty(defaultConsentPayload)) {
|
|
1336
1345
|
common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
|
|
1337
|
-
|
|
1338
|
-
|
|
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
|
|
1339
1348
|
} else if (!common.isEmpty(updatedDefaultConsentPayload)) {
|
|
1340
1349
|
common.sendDefaultConsentPayloadToGoogle(
|
|
1341
1350
|
updatedDefaultConsentPayload
|
|
@@ -1366,12 +1375,8 @@ function parseSettingsString(settingsString) {
|
|
|
1366
1375
|
var initialization_1 = initialization;
|
|
1367
1376
|
|
|
1368
1377
|
var sessionHandler = {
|
|
1369
|
-
onSessionStart: function(event) {
|
|
1370
|
-
|
|
1371
|
-
},
|
|
1372
|
-
onSessionEnd: function(event) {
|
|
1373
|
-
|
|
1374
|
-
}
|
|
1378
|
+
onSessionStart: function(event) {},
|
|
1379
|
+
onSessionEnd: function(event) {},
|
|
1375
1380
|
};
|
|
1376
1381
|
|
|
1377
1382
|
var sessionHandler_1 = sessionHandler;
|
|
@@ -1380,7 +1385,7 @@ function UserAttributeHandler(common) {
|
|
|
1380
1385
|
this.common = common || {};
|
|
1381
1386
|
}
|
|
1382
1387
|
|
|
1383
|
-
UserAttributeHandler.prototype.sendUserPropertiesToGA4 = function
|
|
1388
|
+
UserAttributeHandler.prototype.sendUserPropertiesToGA4 = function(
|
|
1384
1389
|
userAttributes
|
|
1385
1390
|
) {
|
|
1386
1391
|
gtag(
|
|
@@ -1394,13 +1399,13 @@ UserAttributeHandler.prototype.sendUserPropertiesToGA4 = function (
|
|
|
1394
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
|
|
1395
1400
|
// for previous function signatures
|
|
1396
1401
|
|
|
1397
|
-
UserAttributeHandler.prototype.onRemoveUserAttribute = function
|
|
1402
|
+
UserAttributeHandler.prototype.onRemoveUserAttribute = function(key) {
|
|
1398
1403
|
var userAttributes = {};
|
|
1399
1404
|
userAttributes[key] = null;
|
|
1400
1405
|
this.sendUserPropertiesToGA4(userAttributes);
|
|
1401
1406
|
};
|
|
1402
1407
|
|
|
1403
|
-
UserAttributeHandler.prototype.onSetUserAttribute = function
|
|
1408
|
+
UserAttributeHandler.prototype.onSetUserAttribute = function(key, value) {
|
|
1404
1409
|
var userAttributes = {};
|
|
1405
1410
|
userAttributes[key] = value;
|
|
1406
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",
|
|
@@ -21,7 +21,11 @@
|
|
|
21
21
|
"provenance": true,
|
|
22
22
|
"registry": "https://registry.npmjs.org"
|
|
23
23
|
},
|
|
24
|
-
"repository":
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/mParticle/mparticle-web-sdk",
|
|
27
|
+
"directory": "kits/google-analytics-4/packages/GA4Client"
|
|
28
|
+
},
|
|
25
29
|
"devDependencies": {
|
|
26
30
|
"@mparticle/web-kit-wrapper": "^1.0.5",
|
|
27
31
|
"@semantic-release/changelog": "^6.0.3",
|
|
@@ -49,7 +53,7 @@
|
|
|
49
53
|
"watchify": "^3.11.0"
|
|
50
54
|
},
|
|
51
55
|
"dependencies": {
|
|
52
|
-
"@mparticle/web-sdk": "^
|
|
56
|
+
"@mparticle/web-sdk": "^3.0.0"
|
|
53
57
|
},
|
|
54
58
|
"license": "Apache-2.0"
|
|
55
59
|
}
|