@mparticle/web-sdk 2.19.0 → 2.19.1
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.
- package/dist/mparticle.common.js +49 -16
- package/dist/mparticle.esm.js +49 -16
- package/dist/mparticle.js +81 -41
- package/package.json +1 -1
- package/src/apiClient.ts +1 -1
- package/src/{consent.js → consent.ts} +228 -72
- package/src/cookieSyncManager.js +40 -0
- package/src/mockBatchCreator.ts +3 -0
- package/src/sdkRuntimeModels.ts +4 -3
- package/src/sdkToEventsApiConverter.ts +1 -1
- package/src/serverModel.ts +34 -32
- package/src/store.ts +5 -4
- package/src/consent.interfaces.ts +0 -89
package/dist/mparticle.js
CHANGED
|
@@ -725,7 +725,7 @@ var mParticle = (function () {
|
|
|
725
725
|
Environment: Environment
|
|
726
726
|
};
|
|
727
727
|
|
|
728
|
-
var version = "2.19.
|
|
728
|
+
var version = "2.19.1";
|
|
729
729
|
|
|
730
730
|
var Constants = {
|
|
731
731
|
sdkVersion: version,
|
|
@@ -2679,7 +2679,7 @@ var mParticle = (function () {
|
|
|
2679
2679
|
if (xhr) {
|
|
2680
2680
|
try {
|
|
2681
2681
|
xhr.open('post', mpInstance._Helpers.createServiceUrl(mpInstance._Store.SDKConfig.v2SecureServiceUrl, mpInstance._Store.devToken) + '/Events');
|
|
2682
|
-
xhr.send(JSON.stringify(mpInstance._ServerModel.
|
|
2682
|
+
xhr.send(JSON.stringify(mpInstance._ServerModel.convertEventToV2DTO(event)));
|
|
2683
2683
|
} catch (e) {
|
|
2684
2684
|
mpInstance.Logger.error('Error sending event to mParticle servers. ' + e);
|
|
2685
2685
|
}
|
|
@@ -3435,33 +3435,43 @@ var mParticle = (function () {
|
|
|
3435
3435
|
|
|
3436
3436
|
var Messages$7 = Constants.Messages;
|
|
3437
3437
|
function cookieSyncManager(mpInstance) {
|
|
3438
|
-
var self = this;
|
|
3438
|
+
var self = this; // Public
|
|
3439
3439
|
|
|
3440
3440
|
this.attemptCookieSync = function (previousMPID, mpid, mpidIsNotInCookies) {
|
|
3441
|
-
|
|
3441
|
+
// TODO: These should move inside the for loop
|
|
3442
|
+
var pixelConfig, lastSyncDateForModule, url, redirect, urlWithRedirect, requiresConsent; // TODO: Make this exit quicker instead of nested
|
|
3442
3443
|
|
|
3443
3444
|
if (mpid && !mpInstance._Store.webviewBridgeEnabled) {
|
|
3444
3445
|
mpInstance._Store.pixelConfigurations.forEach(function (pixelSettings) {
|
|
3445
3446
|
// set requiresConsent to false to start each additional pixel configuration
|
|
3446
3447
|
// set to true only if filteringConsenRuleValues.values.length exists
|
|
3447
|
-
requiresConsent = false;
|
|
3448
|
+
requiresConsent = false; // TODO: Replace with isEmpty
|
|
3448
3449
|
|
|
3449
3450
|
if (pixelSettings.filteringConsentRuleValues && pixelSettings.filteringConsentRuleValues.values && pixelSettings.filteringConsentRuleValues.values.length) {
|
|
3450
3451
|
requiresConsent = true;
|
|
3451
3452
|
}
|
|
3452
3453
|
|
|
3453
3454
|
pixelConfig = {
|
|
3455
|
+
// Kit Module ID
|
|
3454
3456
|
moduleId: pixelSettings.moduleId,
|
|
3457
|
+
// Tells you how often we should do a cookie sync (in days)
|
|
3455
3458
|
frequencyCap: pixelSettings.frequencyCap,
|
|
3459
|
+
// Url for cookie sync pixel
|
|
3456
3460
|
pixelUrl: self.replaceAmp(pixelSettings.pixelUrl),
|
|
3461
|
+
// TODO: Document requirements for redirectUrl
|
|
3457
3462
|
redirectUrl: pixelSettings.redirectUrl ? self.replaceAmp(pixelSettings.redirectUrl) : null,
|
|
3463
|
+
// Filtering rules as defined in UI
|
|
3458
3464
|
filteringConsentRuleValues: pixelSettings.filteringConsentRuleValues
|
|
3459
|
-
};
|
|
3465
|
+
}; // TODO: combine replaceMPID and replaceAmp into sanitizeUrl function
|
|
3466
|
+
|
|
3460
3467
|
url = self.replaceMPID(pixelConfig.pixelUrl, mpid);
|
|
3461
3468
|
redirect = pixelConfig.redirectUrl ? self.replaceMPID(pixelConfig.redirectUrl, mpid) : '';
|
|
3462
|
-
urlWithRedirect = url + encodeURIComponent(redirect);
|
|
3469
|
+
urlWithRedirect = url + encodeURIComponent(redirect); // TODO: Refactor so that Persistence is only called once
|
|
3470
|
+
// outside of the loop
|
|
3471
|
+
|
|
3472
|
+
var persistence = mpInstance._Persistence.getPersistence(); // TODO: Is there a historic reason for checking for previousMPID?
|
|
3473
|
+
// it does not appear to be passed in anywhere
|
|
3463
3474
|
|
|
3464
|
-
var persistence = mpInstance._Persistence.getPersistence();
|
|
3465
3475
|
|
|
3466
3476
|
if (previousMPID && previousMPID !== mpid) {
|
|
3467
3477
|
if (persistence && persistence[mpid]) {
|
|
@@ -3474,6 +3484,8 @@ var mParticle = (function () {
|
|
|
3474
3484
|
|
|
3475
3485
|
return;
|
|
3476
3486
|
} else {
|
|
3487
|
+
// TODO: Refactor to check for the inverse and exit early
|
|
3488
|
+
// rather than nesting
|
|
3477
3489
|
if (persistence[mpid]) {
|
|
3478
3490
|
if (!persistence[mpid].csd) {
|
|
3479
3491
|
persistence[mpid].csd = {};
|
|
@@ -3483,7 +3495,12 @@ var mParticle = (function () {
|
|
|
3483
3495
|
|
|
3484
3496
|
if (lastSyncDateForModule) {
|
|
3485
3497
|
// Check to see if we need to refresh cookieSync
|
|
3486
|
-
if (
|
|
3498
|
+
if ( // TODO: Turn this into a convenience method for readability?
|
|
3499
|
+
// We use similar comparisons elsewhere in the SDK,
|
|
3500
|
+
// so perhaps we can make a time comparison convenience method
|
|
3501
|
+
new Date().getTime() > new Date(lastSyncDateForModule).getTime() + pixelConfig.frequencyCap * // TODO: Turn these numbers into a constant so
|
|
3502
|
+
// we can remember what this number is for
|
|
3503
|
+
60 * 1000 * 60 * 24) {
|
|
3487
3504
|
self.performCookieSync(urlWithRedirect, pixelConfig.moduleId, mpid, persistence[mpid].csd, pixelConfig.filteringConsentRuleValues, mpidIsNotInCookies, requiresConsent);
|
|
3488
3505
|
}
|
|
3489
3506
|
} else {
|
|
@@ -3493,29 +3510,40 @@ var mParticle = (function () {
|
|
|
3493
3510
|
}
|
|
3494
3511
|
});
|
|
3495
3512
|
}
|
|
3496
|
-
};
|
|
3513
|
+
}; // Private
|
|
3514
|
+
|
|
3497
3515
|
|
|
3498
3516
|
this.replaceMPID = function (string, mpid) {
|
|
3499
3517
|
return string.replace('%%mpid%%', mpid);
|
|
3500
|
-
};
|
|
3518
|
+
}; // Private
|
|
3519
|
+
// TODO: Rename function to replaceAmpWithAmpersand
|
|
3520
|
+
|
|
3501
3521
|
|
|
3502
3522
|
this.replaceAmp = function (string) {
|
|
3503
3523
|
return string.replace(/&/g, '&');
|
|
3504
|
-
};
|
|
3524
|
+
}; // Private
|
|
3525
|
+
|
|
3505
3526
|
|
|
3506
3527
|
this.performCookieSync = function (url, moduleId, mpid, cookieSyncDates, filteringConsentRuleValues, mpidIsNotInCookies, requiresConsent) {
|
|
3507
3528
|
// if MPID is new to cookies, we should not try to perform the cookie sync
|
|
3508
3529
|
// because a cookie sync can only occur once a user either consents or doesn't
|
|
3509
3530
|
// we should not check if its enabled if the user has a blank consent
|
|
3531
|
+
// TODO: We should do this check outside of this function
|
|
3510
3532
|
if (requiresConsent && mpidIsNotInCookies) {
|
|
3511
3533
|
return;
|
|
3512
|
-
}
|
|
3534
|
+
} // TODO: Refactor so that check is made outside of the function.
|
|
3535
|
+
// Cache or store the boolean so that it only gets called once per
|
|
3536
|
+
// cookie sync attempt per module.
|
|
3537
|
+
// Currently, attemptCookieSync is called as a loop and therefore this
|
|
3538
|
+
// function polls the user object and consent multiple times.
|
|
3539
|
+
|
|
3513
3540
|
|
|
3514
3541
|
if (mpInstance._Consent.isEnabledForUserConsent(filteringConsentRuleValues, mpInstance.Identity.getCurrentUser())) {
|
|
3515
3542
|
var img = document.createElement('img');
|
|
3516
3543
|
mpInstance.Logger.verbose(Messages$7.InformationMessages.CookieSync);
|
|
3517
3544
|
|
|
3518
3545
|
img.onload = function () {
|
|
3546
|
+
// TODO: Break this out into a convenience method so we can unit test
|
|
3519
3547
|
cookieSyncDates[moduleId.toString()] = new Date().getTime();
|
|
3520
3548
|
|
|
3521
3549
|
mpInstance._Persistence.saveUserCookieSyncDatesToPersistence(mpid, cookieSyncDates);
|
|
@@ -6585,7 +6613,7 @@ var mParticle = (function () {
|
|
|
6585
6613
|
}
|
|
6586
6614
|
}
|
|
6587
6615
|
|
|
6588
|
-
function
|
|
6616
|
+
function convertProductToV2DTO(product) {
|
|
6589
6617
|
return {
|
|
6590
6618
|
id: parseStringOrNumber(product.Sku),
|
|
6591
6619
|
nm: parseStringOrNumber(product.Name),
|
|
@@ -6601,13 +6629,13 @@ var mParticle = (function () {
|
|
|
6601
6629
|
};
|
|
6602
6630
|
}
|
|
6603
6631
|
|
|
6604
|
-
function
|
|
6632
|
+
function convertProductListToV2DTO(productList) {
|
|
6605
6633
|
if (!productList) {
|
|
6606
6634
|
return [];
|
|
6607
6635
|
}
|
|
6608
6636
|
|
|
6609
6637
|
return productList.map(function (product) {
|
|
6610
|
-
return
|
|
6638
|
+
return convertProductToV2DTO(product);
|
|
6611
6639
|
});
|
|
6612
6640
|
}
|
|
6613
6641
|
|
|
@@ -6661,7 +6689,7 @@ var mParticle = (function () {
|
|
|
6661
6689
|
event.UserIdentities = validUserIdentities;
|
|
6662
6690
|
};
|
|
6663
6691
|
|
|
6664
|
-
this.
|
|
6692
|
+
this.convertToConsentStateV2DTO = function (state) {
|
|
6665
6693
|
if (!state) {
|
|
6666
6694
|
return null;
|
|
6667
6695
|
}
|
|
@@ -6801,7 +6829,7 @@ var mParticle = (function () {
|
|
|
6801
6829
|
return null;
|
|
6802
6830
|
};
|
|
6803
6831
|
|
|
6804
|
-
this.
|
|
6832
|
+
this.convertEventToV2DTO = function (event) {
|
|
6805
6833
|
var dto = {
|
|
6806
6834
|
n: event.EventName,
|
|
6807
6835
|
et: event.EventCategory,
|
|
@@ -6835,7 +6863,7 @@ var mParticle = (function () {
|
|
|
6835
6863
|
}
|
|
6836
6864
|
}
|
|
6837
6865
|
|
|
6838
|
-
var consent = self.
|
|
6866
|
+
var consent = self.convertToConsentStateV2DTO(event.ConsentState);
|
|
6839
6867
|
|
|
6840
6868
|
if (consent) {
|
|
6841
6869
|
dto.con = consent;
|
|
@@ -6860,7 +6888,7 @@ var mParticle = (function () {
|
|
|
6860
6888
|
|
|
6861
6889
|
if (event.ShoppingCart) {
|
|
6862
6890
|
dto.sc = {
|
|
6863
|
-
pl:
|
|
6891
|
+
pl: convertProductListToV2DTO(event.ShoppingCart.ProductList)
|
|
6864
6892
|
};
|
|
6865
6893
|
}
|
|
6866
6894
|
|
|
@@ -6869,7 +6897,7 @@ var mParticle = (function () {
|
|
|
6869
6897
|
an: event.ProductAction.ProductActionType,
|
|
6870
6898
|
cs: mpInstance._Helpers.parseNumber(event.ProductAction.CheckoutStep),
|
|
6871
6899
|
co: event.ProductAction.CheckoutOptions,
|
|
6872
|
-
pl:
|
|
6900
|
+
pl: convertProductListToV2DTO(event.ProductAction.ProductList),
|
|
6873
6901
|
ti: event.ProductAction.TransactionId,
|
|
6874
6902
|
ta: event.ProductAction.Affiliation,
|
|
6875
6903
|
tcc: event.ProductAction.CouponCode,
|
|
@@ -6893,7 +6921,7 @@ var mParticle = (function () {
|
|
|
6893
6921
|
dto.pi = event.ProductImpressions.map(function (impression) {
|
|
6894
6922
|
return {
|
|
6895
6923
|
pil: impression.ProductImpressionList,
|
|
6896
|
-
pl:
|
|
6924
|
+
pl: convertProductListToV2DTO(impression.ProductList)
|
|
6897
6925
|
};
|
|
6898
6926
|
});
|
|
6899
6927
|
}
|
|
@@ -8241,9 +8269,11 @@ var mParticle = (function () {
|
|
|
8241
8269
|
};
|
|
8242
8270
|
}
|
|
8243
8271
|
|
|
8272
|
+
var CCPAPurpose = 'data_sale_opt_out';
|
|
8244
8273
|
function Consent(mpInstance) {
|
|
8245
|
-
var self = this;
|
|
8246
|
-
|
|
8274
|
+
var self = this; // this function is called when consent is required to
|
|
8275
|
+
// determine if a cookie sync should happen, or a
|
|
8276
|
+
// forwarder should be initialized
|
|
8247
8277
|
|
|
8248
8278
|
this.isEnabledForUserConsent = function (consentRules, user) {
|
|
8249
8279
|
if (!consentRules || !consentRules.values || !consentRules.values.length) {
|
|
@@ -8254,16 +8284,15 @@ var mParticle = (function () {
|
|
|
8254
8284
|
return false;
|
|
8255
8285
|
}
|
|
8256
8286
|
|
|
8257
|
-
var purposeHashes = {}
|
|
8258
|
-
|
|
8259
|
-
|
|
8287
|
+
var purposeHashes = {};
|
|
8288
|
+
var consentState = user.getConsentState();
|
|
8289
|
+
var purposeHash;
|
|
8260
8290
|
|
|
8261
8291
|
if (consentState) {
|
|
8262
8292
|
// the server hashes consent purposes in the following way:
|
|
8263
8293
|
// GDPR - '1' + purpose name
|
|
8264
8294
|
// CCPA - '2data_sale_opt_out' (there is only 1 purpose of data_sale_opt_out for CCPA)
|
|
8265
8295
|
var GDPRConsentHashPrefix = '1';
|
|
8266
|
-
var CCPAPurpose = 'data_sale_opt_out';
|
|
8267
8296
|
var CCPAHashString = '2' + CCPAPurpose;
|
|
8268
8297
|
var gdprConsentState = consentState.getGDPRConsentState();
|
|
8269
8298
|
|
|
@@ -8291,6 +8320,8 @@ var mParticle = (function () {
|
|
|
8291
8320
|
if (purposeHashes.hasOwnProperty(consentPurposeHash)) {
|
|
8292
8321
|
return purposeHashes[consentPurposeHash] === hasConsented;
|
|
8293
8322
|
}
|
|
8323
|
+
|
|
8324
|
+
return false;
|
|
8294
8325
|
});
|
|
8295
8326
|
return consentRules.includeOnMatch === isMatch;
|
|
8296
8327
|
};
|
|
@@ -8332,6 +8363,8 @@ var mParticle = (function () {
|
|
|
8332
8363
|
|
|
8333
8364
|
this.ConsentSerialization = {
|
|
8334
8365
|
toMinifiedJsonObject: function toMinifiedJsonObject(state) {
|
|
8366
|
+
var _a;
|
|
8367
|
+
|
|
8335
8368
|
var jsonObject = {};
|
|
8336
8369
|
|
|
8337
8370
|
if (state) {
|
|
@@ -8371,8 +8404,7 @@ var mParticle = (function () {
|
|
|
8371
8404
|
var ccpaConsentState = state.getCCPAConsentState();
|
|
8372
8405
|
|
|
8373
8406
|
if (ccpaConsentState) {
|
|
8374
|
-
jsonObject.ccpa = {};
|
|
8375
|
-
jsonObject.ccpa[CCPAPurpose] = {};
|
|
8407
|
+
jsonObject.ccpa = (_a = {}, _a[CCPAPurpose] = {}, _a);
|
|
8376
8408
|
|
|
8377
8409
|
if (typeof ccpaConsentState.Consented === 'boolean') {
|
|
8378
8410
|
jsonObject.ccpa[CCPAPurpose].c = ccpaConsentState.Consented;
|
|
@@ -8419,15 +8451,18 @@ var mParticle = (function () {
|
|
|
8419
8451
|
|
|
8420
8452
|
return state;
|
|
8421
8453
|
}
|
|
8422
|
-
};
|
|
8454
|
+
}; // TODO: Refactor this method into a constructor
|
|
8423
8455
|
|
|
8424
8456
|
this.createConsentState = function (consentState) {
|
|
8425
8457
|
var gdpr = {};
|
|
8426
8458
|
var ccpa = {};
|
|
8427
8459
|
|
|
8428
8460
|
if (consentState) {
|
|
8429
|
-
|
|
8430
|
-
|
|
8461
|
+
var consentStateCopy = self.createConsentState();
|
|
8462
|
+
consentStateCopy.setGDPRConsentState(consentState.getGDPRConsentState());
|
|
8463
|
+
consentStateCopy.setCCPAConsentState(consentState.getCCPAConsentState()); // TODO: Remove casting once `removeCCPAState` is removed;
|
|
8464
|
+
|
|
8465
|
+
return consentStateCopy;
|
|
8431
8466
|
}
|
|
8432
8467
|
|
|
8433
8468
|
function canonicalizeForDeduplication(purpose) {
|
|
@@ -8446,7 +8481,7 @@ var mParticle = (function () {
|
|
|
8446
8481
|
/**
|
|
8447
8482
|
* Invoke these methods on a consent state object.
|
|
8448
8483
|
* <p>
|
|
8449
|
-
* Usage:
|
|
8484
|
+
* Usage: const consent = mParticle.Consent.createConsentState()
|
|
8450
8485
|
* <br>
|
|
8451
8486
|
* consent.setGDPRCoonsentState()
|
|
8452
8487
|
*
|
|
@@ -8470,7 +8505,7 @@ var mParticle = (function () {
|
|
|
8470
8505
|
return this;
|
|
8471
8506
|
}
|
|
8472
8507
|
|
|
8473
|
-
if (!
|
|
8508
|
+
if (!isObject(gdprConsent)) {
|
|
8474
8509
|
mpInstance.Logger.error('Invoked with a bad or empty consent object.');
|
|
8475
8510
|
return this;
|
|
8476
8511
|
}
|
|
@@ -8487,12 +8522,12 @@ var mParticle = (function () {
|
|
|
8487
8522
|
function setGDPRConsentState(gdprConsentState) {
|
|
8488
8523
|
if (!gdprConsentState) {
|
|
8489
8524
|
gdpr = {};
|
|
8490
|
-
} else if (
|
|
8525
|
+
} else if (isObject(gdprConsentState)) {
|
|
8491
8526
|
gdpr = {};
|
|
8492
8527
|
|
|
8493
8528
|
for (var purpose in gdprConsentState) {
|
|
8494
8529
|
if (gdprConsentState.hasOwnProperty(purpose)) {
|
|
8495
|
-
addGDPRConsentState(purpose, gdprConsentState[purpose]);
|
|
8530
|
+
this.addGDPRConsentState(purpose, gdprConsentState[purpose]);
|
|
8496
8531
|
}
|
|
8497
8532
|
}
|
|
8498
8533
|
}
|
|
@@ -8526,7 +8561,7 @@ var mParticle = (function () {
|
|
|
8526
8561
|
|
|
8527
8562
|
|
|
8528
8563
|
function getGDPRConsentState() {
|
|
8529
|
-
return
|
|
8564
|
+
return Object.assign({}, gdpr);
|
|
8530
8565
|
}
|
|
8531
8566
|
/**
|
|
8532
8567
|
* Sets a CCPA Consent state (has a single purpose of 'data_sale_opt_out')
|
|
@@ -8537,7 +8572,7 @@ var mParticle = (function () {
|
|
|
8537
8572
|
|
|
8538
8573
|
|
|
8539
8574
|
function setCCPAConsentState(ccpaConsent) {
|
|
8540
|
-
if (!
|
|
8575
|
+
if (!isObject(ccpaConsent)) {
|
|
8541
8576
|
mpInstance.Logger.error('Invoked with a bad or empty CCPA consent object.');
|
|
8542
8577
|
return this;
|
|
8543
8578
|
}
|
|
@@ -8571,10 +8606,12 @@ var mParticle = (function () {
|
|
|
8571
8606
|
function removeCCPAConsentState() {
|
|
8572
8607
|
delete ccpa[CCPAPurpose];
|
|
8573
8608
|
return this;
|
|
8574
|
-
}
|
|
8609
|
+
} // TODO: Can we remove this? It is deprecated.
|
|
8610
|
+
|
|
8575
8611
|
|
|
8576
8612
|
function removeCCPAState() {
|
|
8577
|
-
mpInstance.Logger.warning('removeCCPAState is deprecated and will be removed in a future release; use removeCCPAConsentState instead');
|
|
8613
|
+
mpInstance.Logger.warning('removeCCPAState is deprecated and will be removed in a future release; use removeCCPAConsentState instead'); // @ts-ignore
|
|
8614
|
+
|
|
8578
8615
|
return removeCCPAConsentState();
|
|
8579
8616
|
}
|
|
8580
8617
|
|
|
@@ -10666,6 +10703,9 @@ var mParticle = (function () {
|
|
|
10666
10703
|
// Certain Helper, Store, and Identity properties need to be mocked to be used in the `returnBatch` method
|
|
10667
10704
|
_Helpers: {
|
|
10668
10705
|
sanitizeAttributes: window.mParticle.getInstance()._Helpers.sanitizeAttributes,
|
|
10706
|
+
generateHash: function generateHash() {
|
|
10707
|
+
return 'mockHash';
|
|
10708
|
+
},
|
|
10669
10709
|
generateUniqueId: function generateUniqueId() {
|
|
10670
10710
|
return 'mockId';
|
|
10671
10711
|
},
|
package/package.json
CHANGED