@mparticle/web-sdk 2.47.0 → 2.48.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.
- package/dist/mparticle.common.js +68 -237
- package/dist/mparticle.esm.js +68 -237
- package/dist/mparticle.js +53 -234
- package/package.json +2 -2
- package/src/constants.ts +7 -4
- package/src/helpers.js +0 -10
- package/src/identity-user-interfaces.ts +2 -2
- package/src/identity.interfaces.ts +1 -1
- package/src/identity.js +29 -138
- package/src/mp-instance.ts +35 -26
- package/src/mparticle-instance-manager.ts +7 -1
- package/src/persistence.interfaces.ts +0 -5
- package/src/persistence.js +1 -165
- package/src/sdkRuntimeModels.ts +1 -1
- package/src/sessionManager.ts +1 -1
- package/src/store.ts +0 -4
- package/src/types.ts +4 -0
- package/src/utils.ts +16 -9
package/src/identity.js
CHANGED
|
@@ -1215,7 +1215,7 @@ export default function Identity(mpInstance) {
|
|
|
1215
1215
|
mpInstance.Logger.warning(
|
|
1216
1216
|
'Deprecated function Identity.getCurrentUser().getCart() will be removed in future releases'
|
|
1217
1217
|
);
|
|
1218
|
-
return self.mParticleUserCart(
|
|
1218
|
+
return self.mParticleUserCart();
|
|
1219
1219
|
},
|
|
1220
1220
|
|
|
1221
1221
|
/**
|
|
@@ -1286,133 +1286,37 @@ export default function Identity(mpInstance) {
|
|
|
1286
1286
|
* @class mParticle.Identity.getCurrentUser().getCart()
|
|
1287
1287
|
* @deprecated
|
|
1288
1288
|
*/
|
|
1289
|
-
this.mParticleUserCart = function(
|
|
1289
|
+
this.mParticleUserCart = function() {
|
|
1290
1290
|
return {
|
|
1291
1291
|
/**
|
|
1292
1292
|
* Adds a cart product to the user cart
|
|
1293
1293
|
* @method add
|
|
1294
|
-
* @param {Object} product the product
|
|
1295
|
-
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
|
|
1296
1294
|
* @deprecated
|
|
1297
1295
|
*/
|
|
1298
|
-
add: function(
|
|
1296
|
+
add: function() {
|
|
1299
1297
|
mpInstance.Logger.warning(
|
|
1300
|
-
|
|
1298
|
+
generateDeprecationMessage(
|
|
1299
|
+
'Identity.getCurrentUser().getCart().add()',
|
|
1300
|
+
true,
|
|
1301
|
+
'eCommerce.logProductAction()',
|
|
1302
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
1303
|
+
)
|
|
1301
1304
|
);
|
|
1302
|
-
var allProducts, userProducts, arrayCopy;
|
|
1303
|
-
|
|
1304
|
-
arrayCopy = Array.isArray(product)
|
|
1305
|
-
? product.slice()
|
|
1306
|
-
: [product];
|
|
1307
|
-
arrayCopy.forEach(function(product) {
|
|
1308
|
-
product.Attributes = mpInstance._Helpers.sanitizeAttributes(
|
|
1309
|
-
product.Attributes
|
|
1310
|
-
);
|
|
1311
|
-
});
|
|
1312
|
-
|
|
1313
|
-
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
1314
|
-
mpInstance._NativeSdkHelpers.sendToNative(
|
|
1315
|
-
Constants.NativeSdkPaths.AddToCart,
|
|
1316
|
-
JSON.stringify(arrayCopy)
|
|
1317
|
-
);
|
|
1318
|
-
} else {
|
|
1319
|
-
mpInstance._SessionManager.resetSessionTimer();
|
|
1320
|
-
|
|
1321
|
-
userProducts = mpInstance._Persistence.getUserProductsFromLS(
|
|
1322
|
-
mpid
|
|
1323
|
-
);
|
|
1324
|
-
|
|
1325
|
-
userProducts = userProducts.concat(arrayCopy);
|
|
1326
|
-
|
|
1327
|
-
if (logEvent === true) {
|
|
1328
|
-
mpInstance._Events.logProductActionEvent(
|
|
1329
|
-
Types.ProductActionType.AddToCart,
|
|
1330
|
-
arrayCopy
|
|
1331
|
-
);
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
var productsForMemory = {};
|
|
1335
|
-
productsForMemory[mpid] = { cp: userProducts };
|
|
1336
|
-
|
|
1337
|
-
if (
|
|
1338
|
-
userProducts.length >
|
|
1339
|
-
mpInstance._Store.SDKConfig.maxProducts
|
|
1340
|
-
) {
|
|
1341
|
-
mpInstance.Logger.verbose(
|
|
1342
|
-
'The cart contains ' +
|
|
1343
|
-
userProducts.length +
|
|
1344
|
-
' items. Only ' +
|
|
1345
|
-
mpInstance._Store.SDKConfig.maxProducts +
|
|
1346
|
-
' can currently be saved in cookies.'
|
|
1347
|
-
);
|
|
1348
|
-
userProducts = userProducts.slice(
|
|
1349
|
-
-mpInstance._Store.SDKConfig.maxProducts
|
|
1350
|
-
);
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
|
|
1354
|
-
allProducts[mpid].cp = userProducts;
|
|
1355
|
-
|
|
1356
|
-
mpInstance._Persistence.setCartProducts(allProducts);
|
|
1357
|
-
}
|
|
1358
1305
|
},
|
|
1359
1306
|
/**
|
|
1360
1307
|
* Removes a cart product from the current user cart
|
|
1361
1308
|
* @method remove
|
|
1362
|
-
* @param {Object} product the product
|
|
1363
|
-
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
|
|
1364
1309
|
* @deprecated
|
|
1365
1310
|
*/
|
|
1366
|
-
remove: function(
|
|
1311
|
+
remove: function() {
|
|
1367
1312
|
mpInstance.Logger.warning(
|
|
1368
|
-
|
|
1313
|
+
generateDeprecationMessage(
|
|
1314
|
+
'Identity.getCurrentUser().getCart().remove()',
|
|
1315
|
+
true,
|
|
1316
|
+
'eCommerce.logProductAction()',
|
|
1317
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
1318
|
+
)
|
|
1369
1319
|
);
|
|
1370
|
-
var allProducts,
|
|
1371
|
-
userProducts,
|
|
1372
|
-
cartIndex = -1,
|
|
1373
|
-
cartItem = null;
|
|
1374
|
-
|
|
1375
|
-
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
1376
|
-
mpInstance._NativeSdkHelpers.sendToNative(
|
|
1377
|
-
Constants.NativeSdkPaths.RemoveFromCart,
|
|
1378
|
-
JSON.stringify(product)
|
|
1379
|
-
);
|
|
1380
|
-
} else {
|
|
1381
|
-
mpInstance._SessionManager.resetSessionTimer();
|
|
1382
|
-
|
|
1383
|
-
userProducts = mpInstance._Persistence.getUserProductsFromLS(
|
|
1384
|
-
mpid
|
|
1385
|
-
);
|
|
1386
|
-
|
|
1387
|
-
if (userProducts) {
|
|
1388
|
-
userProducts.forEach(function(cartProduct, i) {
|
|
1389
|
-
if (cartProduct.Sku === product.Sku) {
|
|
1390
|
-
cartIndex = i;
|
|
1391
|
-
cartItem = cartProduct;
|
|
1392
|
-
}
|
|
1393
|
-
});
|
|
1394
|
-
|
|
1395
|
-
if (cartIndex > -1) {
|
|
1396
|
-
userProducts.splice(cartIndex, 1);
|
|
1397
|
-
|
|
1398
|
-
if (logEvent === true) {
|
|
1399
|
-
mpInstance._Events.logProductActionEvent(
|
|
1400
|
-
Types.ProductActionType.RemoveFromCart,
|
|
1401
|
-
cartItem
|
|
1402
|
-
);
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
var productsForMemory = {};
|
|
1408
|
-
productsForMemory[mpid] = { cp: userProducts };
|
|
1409
|
-
|
|
1410
|
-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
|
|
1411
|
-
|
|
1412
|
-
allProducts[mpid].cp = userProducts;
|
|
1413
|
-
|
|
1414
|
-
mpInstance._Persistence.setCartProducts(allProducts);
|
|
1415
|
-
}
|
|
1416
1320
|
},
|
|
1417
1321
|
/**
|
|
1418
1322
|
* Clears the user's cart
|
|
@@ -1421,31 +1325,13 @@ export default function Identity(mpInstance) {
|
|
|
1421
1325
|
*/
|
|
1422
1326
|
clear: function() {
|
|
1423
1327
|
mpInstance.Logger.warning(
|
|
1424
|
-
|
|
1328
|
+
generateDeprecationMessage(
|
|
1329
|
+
'Identity.getCurrentUser().getCart().clear()',
|
|
1330
|
+
true,
|
|
1331
|
+
'',
|
|
1332
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
1333
|
+
)
|
|
1425
1334
|
);
|
|
1426
|
-
|
|
1427
|
-
var allProducts;
|
|
1428
|
-
|
|
1429
|
-
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
1430
|
-
mpInstance._NativeSdkHelpers.sendToNative(
|
|
1431
|
-
Constants.NativeSdkPaths.ClearCart
|
|
1432
|
-
);
|
|
1433
|
-
} else {
|
|
1434
|
-
mpInstance._SessionManager.resetSessionTimer();
|
|
1435
|
-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
|
|
1436
|
-
|
|
1437
|
-
if (
|
|
1438
|
-
allProducts &&
|
|
1439
|
-
allProducts[mpid] &&
|
|
1440
|
-
allProducts[mpid].cp
|
|
1441
|
-
) {
|
|
1442
|
-
allProducts[mpid].cp = [];
|
|
1443
|
-
|
|
1444
|
-
allProducts[mpid].cp = [];
|
|
1445
|
-
|
|
1446
|
-
mpInstance._Persistence.setCartProducts(allProducts);
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
1335
|
},
|
|
1450
1336
|
/**
|
|
1451
1337
|
* Returns all cart products
|
|
@@ -1455,9 +1341,14 @@ export default function Identity(mpInstance) {
|
|
|
1455
1341
|
*/
|
|
1456
1342
|
getCartProducts: function() {
|
|
1457
1343
|
mpInstance.Logger.warning(
|
|
1458
|
-
|
|
1344
|
+
generateDeprecationMessage(
|
|
1345
|
+
'Identity.getCurrentUser().getCart().getCartProducts()',
|
|
1346
|
+
true,
|
|
1347
|
+
'eCommerce.logProductAction()',
|
|
1348
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
1349
|
+
)
|
|
1459
1350
|
);
|
|
1460
|
-
return
|
|
1351
|
+
return [];
|
|
1461
1352
|
},
|
|
1462
1353
|
};
|
|
1463
1354
|
};
|
package/src/mp-instance.ts
CHANGED
|
@@ -36,7 +36,7 @@ import Consent, { IConsent } from './consent';
|
|
|
36
36
|
import KitBlocker from './kitBlocking';
|
|
37
37
|
import ConfigAPIClient, { IKitConfigs } from './configAPIClient';
|
|
38
38
|
import IdentityAPIClient from './identityApiClient';
|
|
39
|
-
import { isFunction, parseConfig, valueof } from './utils';
|
|
39
|
+
import { isFunction, parseConfig, valueof, generateDeprecationMessage } from './utils';
|
|
40
40
|
import { DisabledVault, LocalStorageVault } from './vault';
|
|
41
41
|
import { removeExpiredIdentityCacheDates } from './identity-utils';
|
|
42
42
|
import IntegrationCapture from './integrationCapture';
|
|
@@ -89,6 +89,8 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
|
|
|
89
89
|
_instanceName: string;
|
|
90
90
|
_preInit: IPreInit;
|
|
91
91
|
_timeOnSiteTimer: ForegroundTimer;
|
|
92
|
+
setLauncherInstanceGuid: () => void;
|
|
93
|
+
captureTiming(metricName: string);
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
const { Messages, HTTPCodes, FeatureFlags, CaptureIntegrationSpecificIdsV2Modes } = Constants;
|
|
@@ -706,16 +708,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
|
|
|
706
708
|
*/
|
|
707
709
|
add: function(product, logEventBoolean) {
|
|
708
710
|
self.Logger.warning(
|
|
709
|
-
|
|
711
|
+
generateDeprecationMessage(
|
|
712
|
+
'eCommerce.Cart.add()',
|
|
713
|
+
true,
|
|
714
|
+
'eCommerce.logProductAction()',
|
|
715
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
716
|
+
)
|
|
710
717
|
);
|
|
711
|
-
let mpid;
|
|
712
|
-
const currentUser = self.Identity.getCurrentUser();
|
|
713
|
-
if (currentUser) {
|
|
714
|
-
mpid = currentUser.getMPID();
|
|
715
|
-
}
|
|
716
|
-
self._Identity
|
|
717
|
-
.mParticleUserCart(mpid)
|
|
718
|
-
.add(product, logEventBoolean);
|
|
719
718
|
},
|
|
720
719
|
/**
|
|
721
720
|
* Removes a product from the cart
|
|
@@ -726,16 +725,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
|
|
|
726
725
|
*/
|
|
727
726
|
remove: function(product, logEventBoolean) {
|
|
728
727
|
self.Logger.warning(
|
|
729
|
-
|
|
728
|
+
generateDeprecationMessage(
|
|
729
|
+
'eCommerce.Cart.remove()',
|
|
730
|
+
true,
|
|
731
|
+
'eCommerce.logProductAction()',
|
|
732
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
733
|
+
)
|
|
730
734
|
);
|
|
731
|
-
let mpid;
|
|
732
|
-
const currentUser = self.Identity.getCurrentUser();
|
|
733
|
-
if (currentUser) {
|
|
734
|
-
mpid = currentUser.getMPID();
|
|
735
|
-
}
|
|
736
|
-
self._Identity
|
|
737
|
-
.mParticleUserCart(mpid)
|
|
738
|
-
.remove(product, logEventBoolean);
|
|
739
735
|
},
|
|
740
736
|
/**
|
|
741
737
|
* Clears the cart
|
|
@@ -744,14 +740,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
|
|
|
744
740
|
*/
|
|
745
741
|
clear: function() {
|
|
746
742
|
self.Logger.warning(
|
|
747
|
-
|
|
743
|
+
generateDeprecationMessage(
|
|
744
|
+
'eCommerce.Cart.clear()',
|
|
745
|
+
true,
|
|
746
|
+
'',
|
|
747
|
+
'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
|
|
748
|
+
)
|
|
748
749
|
);
|
|
749
|
-
let mpid;
|
|
750
|
-
const currentUser = self.Identity.getCurrentUser();
|
|
751
|
-
if (currentUser) {
|
|
752
|
-
mpid = currentUser.getMPID();
|
|
753
|
-
}
|
|
754
|
-
self._Identity.mParticleUserCart(mpid).clear();
|
|
755
750
|
},
|
|
756
751
|
},
|
|
757
752
|
/**
|
|
@@ -1348,6 +1343,20 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
|
|
|
1348
1343
|
};
|
|
1349
1344
|
}
|
|
1350
1345
|
};
|
|
1346
|
+
|
|
1347
|
+
const launcherInstanceGuidKey = Constants.Rokt.LauncherInstanceGuidKey;
|
|
1348
|
+
this.setLauncherInstanceGuid = function() {
|
|
1349
|
+
if (!window[launcherInstanceGuidKey]
|
|
1350
|
+
|| typeof window[launcherInstanceGuidKey] !== 'string') {
|
|
1351
|
+
window[launcherInstanceGuidKey] = self._Helpers.generateUniqueId();
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
this.captureTiming = function(metricsName) {
|
|
1356
|
+
if (typeof window !== 'undefined' && window.performance?.mark) {
|
|
1357
|
+
window.performance.mark(metricsName);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1351
1360
|
}
|
|
1352
1361
|
|
|
1353
1362
|
// Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Polyfill from './polyfill';
|
|
2
|
-
import { CommerceEventType, EventType, IdentityType, ProductActionType, PromotionActionType } from './types';
|
|
2
|
+
import { CommerceEventType, EventType, IdentityType, PerformanceMarkType, ProductActionType, PromotionActionType } from './types';
|
|
3
3
|
import Constants from './constants';
|
|
4
4
|
import mParticleInstance, { IMParticleWebSDKInstance } from './mp-instance.js';
|
|
5
5
|
import _BatchValidator from './mockBatchCreator';
|
|
@@ -77,9 +77,15 @@ function mParticleInstanceManager(this: IMParticleInstanceManager) {
|
|
|
77
77
|
self._instances[instanceName] = client;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
client.captureTiming(PerformanceMarkType.SdkStart);
|
|
81
|
+
client.setLauncherInstanceGuid();
|
|
80
82
|
client.init(apiKey, config, instanceName);
|
|
81
83
|
};
|
|
82
84
|
|
|
85
|
+
this.captureTiming = function(metricsName) {
|
|
86
|
+
self.getInstance().captureTiming(metricsName);
|
|
87
|
+
}
|
|
88
|
+
|
|
83
89
|
this.getInstance = function getInstance(instanceName) {
|
|
84
90
|
let client: IMParticleWebSDKInstance;
|
|
85
91
|
if (!instanceName) {
|
|
@@ -99,11 +99,8 @@ export interface IPersistence {
|
|
|
99
99
|
useLocalStorage(): boolean;
|
|
100
100
|
initializeStorage(): void;
|
|
101
101
|
update(): void;
|
|
102
|
-
storeProductsInMemory(products: Product[], mpid: MPID): void;
|
|
103
102
|
storeDataInMemory(obj: IPersistenceMinified, currentMPID: MPID): void;
|
|
104
103
|
determineLocalStorageAvailability(storage: Storage): boolean;
|
|
105
|
-
getUserProductsFromLS(mpid: MPID): Product[];
|
|
106
|
-
getAllUserProductsFromLS(): Product[];
|
|
107
104
|
setLocalStorage(): void;
|
|
108
105
|
getLocalStorage(): IPersistenceMinified | null;
|
|
109
106
|
expireCookies(cookieName: string): void;
|
|
@@ -120,8 +117,6 @@ export interface IPersistence {
|
|
|
120
117
|
decodePersistence(persistenceString: string): string;
|
|
121
118
|
getCookieDomain(): string;
|
|
122
119
|
getDomain(doc: string, locationHostname: string): string;
|
|
123
|
-
getCartProducts(mpid: MPID): Product[];
|
|
124
|
-
setCartProducts(allProducts: Product[]): void;
|
|
125
120
|
saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDates): void;
|
|
126
121
|
savePersistence(persistance: IPersistenceMinified): void;
|
|
127
122
|
getPersistence(): IPersistenceMinified;
|
package/src/persistence.js
CHANGED
|
@@ -90,35 +90,6 @@ export default function _Persistence(mpInstance) {
|
|
|
90
90
|
self.storeDataInMemory(cookies);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
// https://go.mparticle.com/work/SQDSDKS-6048
|
|
94
|
-
try {
|
|
95
|
-
if (mpInstance._Store.isLocalStorageAvailable) {
|
|
96
|
-
var encodedProducts = localStorage.getItem(
|
|
97
|
-
mpInstance._Store.prodStorageName
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
if (encodedProducts) {
|
|
101
|
-
var decodedProducts = JSON.parse(
|
|
102
|
-
Base64.decode(encodedProducts)
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
if (mpInstance._Store.mpid) {
|
|
106
|
-
self.storeProductsInMemory(
|
|
107
|
-
decodedProducts,
|
|
108
|
-
mpInstance._Store.mpid
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
} catch (e) {
|
|
113
|
-
if (mpInstance._Store.isLocalStorageAvailable) {
|
|
114
|
-
localStorage.removeItem(mpInstance._Store.prodStorageName);
|
|
115
|
-
}
|
|
116
|
-
mpInstance._Store.cartProducts = [];
|
|
117
|
-
mpInstance.Logger.error(
|
|
118
|
-
'Error loading products in initialization: ' + e
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
93
|
// https://go.mparticle.com/work/SQDSDKS-6046
|
|
123
94
|
// Stores all non-current user MPID information into the store
|
|
124
95
|
for (var key in allData) {
|
|
@@ -158,21 +129,6 @@ export default function _Persistence(mpInstance) {
|
|
|
158
129
|
}
|
|
159
130
|
};
|
|
160
131
|
|
|
161
|
-
this.storeProductsInMemory = function(products, mpid) {
|
|
162
|
-
if (products) {
|
|
163
|
-
try {
|
|
164
|
-
mpInstance._Store.cartProducts =
|
|
165
|
-
products[mpid] && products[mpid].cp
|
|
166
|
-
? products[mpid].cp
|
|
167
|
-
: [];
|
|
168
|
-
} catch (e) {
|
|
169
|
-
mpInstance.Logger.error(
|
|
170
|
-
Messages.ErrorMessages.CookieParseError
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
132
|
// https://go.mparticle.com/work/SQDSDKS-6045
|
|
177
133
|
this.storeDataInMemory = function(obj, currentMPID) {
|
|
178
134
|
try {
|
|
@@ -275,64 +231,6 @@ export default function _Persistence(mpInstance) {
|
|
|
275
231
|
}
|
|
276
232
|
};
|
|
277
233
|
|
|
278
|
-
this.getUserProductsFromLS = function(mpid) {
|
|
279
|
-
if (!mpInstance._Store.isLocalStorageAvailable) {
|
|
280
|
-
return [];
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
var decodedProducts,
|
|
284
|
-
userProducts,
|
|
285
|
-
parsedProducts,
|
|
286
|
-
encodedProducts = localStorage.getItem(
|
|
287
|
-
mpInstance._Store.prodStorageName
|
|
288
|
-
);
|
|
289
|
-
if (encodedProducts) {
|
|
290
|
-
decodedProducts = Base64.decode(encodedProducts);
|
|
291
|
-
}
|
|
292
|
-
// if there is an MPID, we are retrieving the user's products, which is an array
|
|
293
|
-
if (mpid) {
|
|
294
|
-
try {
|
|
295
|
-
if (decodedProducts) {
|
|
296
|
-
parsedProducts = JSON.parse(decodedProducts);
|
|
297
|
-
}
|
|
298
|
-
if (
|
|
299
|
-
decodedProducts &&
|
|
300
|
-
parsedProducts[mpid] &&
|
|
301
|
-
parsedProducts[mpid].cp &&
|
|
302
|
-
Array.isArray(parsedProducts[mpid].cp)
|
|
303
|
-
) {
|
|
304
|
-
userProducts = parsedProducts[mpid].cp;
|
|
305
|
-
} else {
|
|
306
|
-
userProducts = [];
|
|
307
|
-
}
|
|
308
|
-
return userProducts;
|
|
309
|
-
} catch (e) {
|
|
310
|
-
return [];
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
return [];
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
this.getAllUserProductsFromLS = function() {
|
|
318
|
-
var decodedProducts,
|
|
319
|
-
encodedProducts = localStorage.getItem(
|
|
320
|
-
mpInstance._Store.prodStorageName
|
|
321
|
-
),
|
|
322
|
-
parsedDecodedProducts;
|
|
323
|
-
if (encodedProducts) {
|
|
324
|
-
decodedProducts = Base64.decode(encodedProducts);
|
|
325
|
-
}
|
|
326
|
-
// returns an object with keys of MPID and values of array of products
|
|
327
|
-
try {
|
|
328
|
-
parsedDecodedProducts = JSON.parse(decodedProducts);
|
|
329
|
-
} catch (e) {
|
|
330
|
-
parsedDecodedProducts = {};
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
return parsedDecodedProducts;
|
|
334
|
-
};
|
|
335
|
-
|
|
336
234
|
// https://go.mparticle.com/work/SQDSDKS-6021
|
|
337
235
|
this.setLocalStorage = function() {
|
|
338
236
|
if (!mpInstance._Store.isLocalStorageAvailable) {
|
|
@@ -340,30 +238,9 @@ export default function _Persistence(mpInstance) {
|
|
|
340
238
|
}
|
|
341
239
|
|
|
342
240
|
var key = mpInstance._Store.storageName,
|
|
343
|
-
allLocalStorageProducts = self.getAllUserProductsFromLS(),
|
|
344
241
|
localStorageData = self.getLocalStorage() || {},
|
|
345
242
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
346
|
-
mpid = currentUser ? currentUser.getMPID() : null
|
|
347
|
-
currentUserProducts = {
|
|
348
|
-
cp: allLocalStorageProducts[mpid]
|
|
349
|
-
? allLocalStorageProducts[mpid].cp
|
|
350
|
-
: [],
|
|
351
|
-
};
|
|
352
|
-
if (mpid) {
|
|
353
|
-
allLocalStorageProducts = allLocalStorageProducts || {};
|
|
354
|
-
allLocalStorageProducts[mpid] = currentUserProducts;
|
|
355
|
-
try {
|
|
356
|
-
window.localStorage.setItem(
|
|
357
|
-
encodeURIComponent(mpInstance._Store.prodStorageName),
|
|
358
|
-
Base64.encode(JSON.stringify(allLocalStorageProducts))
|
|
359
|
-
);
|
|
360
|
-
} catch (e) {
|
|
361
|
-
mpInstance.Logger.error(
|
|
362
|
-
'Error with setting products on localStorage.'
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
243
|
+
mpid = currentUser ? currentUser.getMPID() : null;
|
|
367
244
|
if (!mpInstance._Store.SDKConfig.useCookieStorage) {
|
|
368
245
|
localStorageData.gs = localStorageData.gs || {};
|
|
369
246
|
|
|
@@ -900,42 +777,6 @@ export default function _Persistence(mpInstance) {
|
|
|
900
777
|
return '';
|
|
901
778
|
};
|
|
902
779
|
|
|
903
|
-
this.getCartProducts = function(mpid) {
|
|
904
|
-
var allCartProducts,
|
|
905
|
-
cartProductsString = localStorage.getItem(
|
|
906
|
-
mpInstance._Store.prodStorageName
|
|
907
|
-
);
|
|
908
|
-
if (cartProductsString) {
|
|
909
|
-
allCartProducts = JSON.parse(Base64.decode(cartProductsString));
|
|
910
|
-
if (
|
|
911
|
-
allCartProducts &&
|
|
912
|
-
allCartProducts[mpid] &&
|
|
913
|
-
allCartProducts[mpid].cp
|
|
914
|
-
) {
|
|
915
|
-
return allCartProducts[mpid].cp;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
return [];
|
|
920
|
-
};
|
|
921
|
-
|
|
922
|
-
this.setCartProducts = function(allProducts) {
|
|
923
|
-
if (!mpInstance._Store.isLocalStorageAvailable) {
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
try {
|
|
928
|
-
window.localStorage.setItem(
|
|
929
|
-
encodeURIComponent(mpInstance._Store.prodStorageName),
|
|
930
|
-
Base64.encode(JSON.stringify(allProducts))
|
|
931
|
-
);
|
|
932
|
-
} catch (e) {
|
|
933
|
-
mpInstance.Logger.error(
|
|
934
|
-
'Error with setting products on localStorage.'
|
|
935
|
-
);
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
|
|
939
780
|
this.saveUserCookieSyncDatesToPersistence = function(mpid, csd) {
|
|
940
781
|
if (csd) {
|
|
941
782
|
var persistence = self.getPersistence();
|
|
@@ -1111,7 +952,6 @@ export default function _Persistence(mpInstance) {
|
|
|
1111
952
|
removeLocalStorage(StorageNames.localStorageName);
|
|
1112
953
|
removeLocalStorage(StorageNames.localStorageNameV3);
|
|
1113
954
|
removeLocalStorage(StorageNames.localStorageNameV4);
|
|
1114
|
-
removeLocalStorage(mpInstance._Store.prodStorageName);
|
|
1115
955
|
removeLocalStorage(mpInstance._Store.storageName);
|
|
1116
956
|
removeLocalStorage(StorageNames.localStorageProductsV4);
|
|
1117
957
|
|
|
@@ -1119,7 +959,6 @@ export default function _Persistence(mpInstance) {
|
|
|
1119
959
|
self.expireCookies(StorageNames.cookieNameV2);
|
|
1120
960
|
self.expireCookies(StorageNames.cookieNameV3);
|
|
1121
961
|
self.expireCookies(StorageNames.cookieNameV4);
|
|
1122
|
-
self.expireCookies(mpInstance._Store.prodStorageName);
|
|
1123
962
|
self.expireCookies(mpInstance._Store.storageName);
|
|
1124
963
|
|
|
1125
964
|
if (mParticle._isTestEnv) {
|
|
@@ -1130,9 +969,6 @@ export default function _Persistence(mpInstance) {
|
|
|
1130
969
|
self.expireCookies(
|
|
1131
970
|
mpInstance._Helpers.createMainStorageName(testWorkspaceToken)
|
|
1132
971
|
);
|
|
1133
|
-
removeLocalStorage(
|
|
1134
|
-
mpInstance._Helpers.createProductStorageName(testWorkspaceToken)
|
|
1135
|
-
);
|
|
1136
972
|
}
|
|
1137
973
|
};
|
|
1138
974
|
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -228,6 +228,7 @@ export interface MParticleWebSDK {
|
|
|
228
228
|
generateHash(value: string): string;
|
|
229
229
|
setIntegrationAttribute(integrationModuleId: number, attrs: IntegrationAttribute): void;
|
|
230
230
|
getIntegrationAttributes(integrationModuleId: number): IntegrationAttribute;
|
|
231
|
+
captureTiming(metricName: string): void;
|
|
231
232
|
}
|
|
232
233
|
|
|
233
234
|
// https://go.mparticle.com/work/SQDSDKS-4805
|
|
@@ -319,7 +320,6 @@ export interface DataPlanConfig {
|
|
|
319
320
|
export interface SDKHelpersApi {
|
|
320
321
|
canLog?(): boolean;
|
|
321
322
|
createMainStorageName?(workspaceToken: string): string;
|
|
322
|
-
createProductStorageName?(workspaceToken: string): string;
|
|
323
323
|
createServiceUrl(url: string, devToken?: string): string;
|
|
324
324
|
createXHR?(cb: () => void): XMLHttpRequest;
|
|
325
325
|
extend?(...args: any[]);
|
package/src/sessionManager.ts
CHANGED
package/src/store.ts
CHANGED
|
@@ -194,7 +194,6 @@ export interface IStore {
|
|
|
194
194
|
requireDelay: boolean;
|
|
195
195
|
isLocalStorageAvailable: boolean | null;
|
|
196
196
|
storageName: string | null;
|
|
197
|
-
prodStorageName: string | null;
|
|
198
197
|
activeForwarders: ConfiguredKit[];
|
|
199
198
|
kits: Dictionary<MPForwarder>;
|
|
200
199
|
sideloadedKits: MPForwarder[];
|
|
@@ -247,7 +246,6 @@ export default function Store(
|
|
|
247
246
|
) {
|
|
248
247
|
const {
|
|
249
248
|
createMainStorageName,
|
|
250
|
-
createProductStorageName,
|
|
251
249
|
} = mpInstance._Helpers;
|
|
252
250
|
|
|
253
251
|
const { isWebviewEnabled } = mpInstance._NativeSdkHelpers;
|
|
@@ -287,7 +285,6 @@ export default function Store(
|
|
|
287
285
|
requireDelay: true,
|
|
288
286
|
isLocalStorageAvailable: null,
|
|
289
287
|
storageName: null,
|
|
290
|
-
prodStorageName: null,
|
|
291
288
|
activeForwarders: [],
|
|
292
289
|
kits: {},
|
|
293
290
|
sideloadedKits: [],
|
|
@@ -762,7 +759,6 @@ export default function Store(
|
|
|
762
759
|
}
|
|
763
760
|
// add a new function to apply items to the store that require config to be returned
|
|
764
761
|
this.storageName = createMainStorageName(workspaceToken);
|
|
765
|
-
this.prodStorageName = createProductStorageName(workspaceToken);
|
|
766
762
|
|
|
767
763
|
this.SDKConfig.requiredWebviewBridgeName =
|
|
768
764
|
requiredWebviewBridgeName || workspaceToken;
|
package/src/types.ts
CHANGED