@mparticle/web-sdk 2.14.1 → 2.15.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 +30 -18
- package/dist/mparticle.esm.js +30 -18
- package/dist/mparticle.js +145 -84
- package/package.json +1 -1
- package/src/cookieSyncManager.js +7 -6
- package/src/events.js +14 -0
- package/src/forwarders.js +4 -5
- package/src/mp-instance.js +152 -97
- package/src/mparticle-instance-manager.js +6 -0
- package/src/persistence.js +7 -2
- package/src/sdkRuntimeModels.ts +1 -0
- package/src/store.js +3 -0
- package/CHANGELOG.md +0 -563
package/src/mp-instance.js
CHANGED
|
@@ -87,6 +87,7 @@ export default function mParticleInstance(instanceName) {
|
|
|
87
87
|
this.Identity = this._Identity.IdentityAPI;
|
|
88
88
|
this.generateHash = this._Helpers.generateHash;
|
|
89
89
|
this.getDeviceId = this._Persistence.getDeviceId;
|
|
90
|
+
|
|
90
91
|
if (typeof window !== 'undefined') {
|
|
91
92
|
if (window.mParticle && window.mParticle.config) {
|
|
92
93
|
if (window.mParticle.config.hasOwnProperty('rq')) {
|
|
@@ -143,9 +144,13 @@ export default function mParticleInstance(instanceName) {
|
|
|
143
144
|
* @method reset
|
|
144
145
|
*/
|
|
145
146
|
this.reset = function(instance) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
try {
|
|
148
|
+
instance._Persistence.resetPersistence();
|
|
149
|
+
if (instance._Store) {
|
|
150
|
+
delete instance._Store;
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error('Cannot reset mParticle', error);
|
|
149
154
|
}
|
|
150
155
|
};
|
|
151
156
|
|
|
@@ -177,7 +182,7 @@ export default function mParticleInstance(instanceName) {
|
|
|
177
182
|
* @param {Function} function A function to be called after mParticle is initialized
|
|
178
183
|
*/
|
|
179
184
|
this.ready = function(f) {
|
|
180
|
-
if (self.
|
|
185
|
+
if (self.isInitialized() && typeof f === 'function') {
|
|
181
186
|
f();
|
|
182
187
|
} else {
|
|
183
188
|
self._preInit.readyQueue.push(f);
|
|
@@ -197,9 +202,36 @@ export default function mParticleInstance(instanceName) {
|
|
|
197
202
|
* @param {String} version version number
|
|
198
203
|
*/
|
|
199
204
|
this.setAppVersion = function(version) {
|
|
205
|
+
var queued = queueIfNotInitialized(function() {
|
|
206
|
+
self.setAppVersion(version);
|
|
207
|
+
}, self);
|
|
208
|
+
|
|
209
|
+
if (queued) return;
|
|
210
|
+
|
|
200
211
|
self._Store.SDKConfig.appVersion = version;
|
|
201
212
|
self._Persistence.update();
|
|
202
213
|
};
|
|
214
|
+
/**
|
|
215
|
+
* Sets the device id
|
|
216
|
+
* @method setDeviceId
|
|
217
|
+
* @param {String} name device ID (UUIDv4-formatted string)
|
|
218
|
+
*/
|
|
219
|
+
this.setDeviceId = function(guid) {
|
|
220
|
+
var queued = queueIfNotInitialized(function() {
|
|
221
|
+
self.setDeviceId(guid);
|
|
222
|
+
}, self);
|
|
223
|
+
if (queued) return;
|
|
224
|
+
this._Persistence.setDeviceId(guid);
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Returns a boolean for whether or not the SDKhas been fully initialized
|
|
228
|
+
* @method isInitialized
|
|
229
|
+
* @return {Boolean} a boolean for whether or not the SDK has been fully initialized
|
|
230
|
+
*/
|
|
231
|
+
this.isInitialized = function() {
|
|
232
|
+
return self._Store ? self._Store.isInitialized : false;
|
|
233
|
+
};
|
|
234
|
+
|
|
203
235
|
/**
|
|
204
236
|
* Gets the app name
|
|
205
237
|
* @method getAppName
|
|
@@ -214,6 +246,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
214
246
|
* @param {String} name App Name
|
|
215
247
|
*/
|
|
216
248
|
this.setAppName = function(name) {
|
|
249
|
+
var queued = queueIfNotInitialized(function() {
|
|
250
|
+
self.setAppName(name);
|
|
251
|
+
}, self);
|
|
252
|
+
|
|
253
|
+
if (queued) return;
|
|
254
|
+
|
|
217
255
|
self._Store.SDKConfig.appName = name;
|
|
218
256
|
};
|
|
219
257
|
/**
|
|
@@ -254,6 +292,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
254
292
|
* @param {Number} longitude longitude digit
|
|
255
293
|
*/
|
|
256
294
|
this.setPosition = function(lat, lng) {
|
|
295
|
+
var queued = queueIfNotInitialized(function() {
|
|
296
|
+
self.setPosition(lat, lng);
|
|
297
|
+
}, self);
|
|
298
|
+
|
|
299
|
+
if (queued) return;
|
|
300
|
+
|
|
257
301
|
self._SessionManager.resetSessionTimer();
|
|
258
302
|
if (typeof lat === 'number' && typeof lng === 'number') {
|
|
259
303
|
self._Store.currentPosition = {
|
|
@@ -288,12 +332,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
288
332
|
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
289
333
|
*/
|
|
290
334
|
this.logBaseEvent = function(event, eventOptions) {
|
|
291
|
-
|
|
292
|
-
self.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
335
|
+
var queued = queueIfNotInitialized(function() {
|
|
336
|
+
self.logBaseEvent(event, eventOptions);
|
|
337
|
+
}, self);
|
|
338
|
+
|
|
339
|
+
if (queued) return;
|
|
340
|
+
|
|
297
341
|
self._SessionManager.resetSessionTimer();
|
|
298
342
|
if (typeof event.name !== 'string') {
|
|
299
343
|
self.Logger.error(Messages.ErrorMessages.EventNameInvalidType);
|
|
@@ -327,18 +371,18 @@ export default function mParticleInstance(instanceName) {
|
|
|
327
371
|
customFlags,
|
|
328
372
|
eventOptions
|
|
329
373
|
) {
|
|
330
|
-
|
|
331
|
-
self.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
374
|
+
var queued = queueIfNotInitialized(function() {
|
|
375
|
+
self.logEvent(
|
|
376
|
+
eventName,
|
|
377
|
+
eventType,
|
|
378
|
+
eventInfo,
|
|
379
|
+
customFlags,
|
|
380
|
+
eventOptions
|
|
381
|
+
);
|
|
382
|
+
}, self);
|
|
383
|
+
|
|
384
|
+
if (queued) return;
|
|
385
|
+
|
|
342
386
|
self._SessionManager.resetSessionTimer();
|
|
343
387
|
if (typeof eventName !== 'string') {
|
|
344
388
|
self.Logger.error(Messages.ErrorMessages.EventNameInvalidType);
|
|
@@ -383,12 +427,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
383
427
|
* @param {Object} [attrs] Custom attrs to be passed along with the error event; values must be string, number, or boolean
|
|
384
428
|
*/
|
|
385
429
|
this.logError = function(error, attrs) {
|
|
386
|
-
|
|
387
|
-
self.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
430
|
+
var queued = queueIfNotInitialized(function() {
|
|
431
|
+
self.logError(error, attrs);
|
|
432
|
+
}, self);
|
|
433
|
+
|
|
434
|
+
if (queued) return;
|
|
435
|
+
|
|
392
436
|
self._SessionManager.resetSessionTimer();
|
|
393
437
|
if (!error) {
|
|
394
438
|
return;
|
|
@@ -463,12 +507,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
463
507
|
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
464
508
|
*/
|
|
465
509
|
this.logPageView = function(eventName, attrs, customFlags, eventOptions) {
|
|
466
|
-
|
|
467
|
-
self.
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
510
|
+
var queued = queueIfNotInitialized(function() {
|
|
511
|
+
self.logPageView(eventName, attrs, customFlags, eventOptions);
|
|
512
|
+
}, self);
|
|
513
|
+
|
|
514
|
+
if (queued) return;
|
|
515
|
+
|
|
472
516
|
self._SessionManager.resetSessionTimer();
|
|
473
517
|
|
|
474
518
|
if (self._Helpers.canLog()) {
|
|
@@ -640,12 +684,11 @@ export default function mParticleInstance(instanceName) {
|
|
|
640
684
|
* @param {String} code The currency code
|
|
641
685
|
*/
|
|
642
686
|
setCurrencyCode: function(code) {
|
|
643
|
-
|
|
644
|
-
self.
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
}
|
|
687
|
+
var queued = queueIfNotInitialized(function() {
|
|
688
|
+
self.eCommerce.setCurrencyCode(code);
|
|
689
|
+
}, self);
|
|
690
|
+
|
|
691
|
+
if (queued) return;
|
|
649
692
|
|
|
650
693
|
if (typeof code !== 'string') {
|
|
651
694
|
self.Logger.error('Code must be a string');
|
|
@@ -763,6 +806,7 @@ export default function mParticleInstance(instanceName) {
|
|
|
763
806
|
self.Logger.warning(
|
|
764
807
|
'mParticle.logCheckout is deprecated, please use mParticle.logProductAction instead'
|
|
765
808
|
);
|
|
809
|
+
|
|
766
810
|
if (!self._Store.isInitialized) {
|
|
767
811
|
self.ready(function() {
|
|
768
812
|
self.eCommerce.logCheckout(
|
|
@@ -772,8 +816,10 @@ export default function mParticleInstance(instanceName) {
|
|
|
772
816
|
customFlags
|
|
773
817
|
);
|
|
774
818
|
});
|
|
819
|
+
|
|
775
820
|
return;
|
|
776
821
|
}
|
|
822
|
+
|
|
777
823
|
self._SessionManager.resetSessionTimer();
|
|
778
824
|
self._Events.logCheckoutEvent(step, option, attrs, customFlags);
|
|
779
825
|
},
|
|
@@ -796,19 +842,19 @@ export default function mParticleInstance(instanceName) {
|
|
|
796
842
|
transactionAttributes,
|
|
797
843
|
eventOptions
|
|
798
844
|
) {
|
|
799
|
-
|
|
800
|
-
self.
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
845
|
+
var queued = queueIfNotInitialized(function() {
|
|
846
|
+
self.eCommerce.logProductAction(
|
|
847
|
+
productActionType,
|
|
848
|
+
product,
|
|
849
|
+
attrs,
|
|
850
|
+
customFlags,
|
|
851
|
+
transactionAttributes,
|
|
852
|
+
eventOptions
|
|
853
|
+
);
|
|
854
|
+
}, self);
|
|
855
|
+
|
|
856
|
+
if (queued) return;
|
|
857
|
+
|
|
812
858
|
self._SessionManager.resetSessionTimer();
|
|
813
859
|
self._Events.logProductActionEvent(
|
|
814
860
|
productActionType,
|
|
@@ -881,18 +927,18 @@ export default function mParticleInstance(instanceName) {
|
|
|
881
927
|
customFlags,
|
|
882
928
|
eventOptions
|
|
883
929
|
) {
|
|
884
|
-
|
|
885
|
-
self.
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
930
|
+
var queued = queueIfNotInitialized(function() {
|
|
931
|
+
self.eCommerce.logPromotion(
|
|
932
|
+
type,
|
|
933
|
+
promotion,
|
|
934
|
+
attrs,
|
|
935
|
+
customFlags,
|
|
936
|
+
eventOptions
|
|
937
|
+
);
|
|
938
|
+
}, self);
|
|
939
|
+
|
|
940
|
+
if (queued) return;
|
|
941
|
+
|
|
896
942
|
self._SessionManager.resetSessionTimer();
|
|
897
943
|
self._Events.logPromotionEvent(
|
|
898
944
|
type,
|
|
@@ -912,17 +958,17 @@ export default function mParticleInstance(instanceName) {
|
|
|
912
958
|
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
913
959
|
*/
|
|
914
960
|
logImpression: function(impression, attrs, customFlags, eventOptions) {
|
|
915
|
-
|
|
916
|
-
self.
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
961
|
+
var queued = queueIfNotInitialized(function() {
|
|
962
|
+
self.eCommerce.logImpression(
|
|
963
|
+
impression,
|
|
964
|
+
attrs,
|
|
965
|
+
customFlags,
|
|
966
|
+
eventOptions
|
|
967
|
+
);
|
|
968
|
+
}, self);
|
|
969
|
+
|
|
970
|
+
if (queued) return;
|
|
971
|
+
|
|
926
972
|
self._SessionManager.resetSessionTimer();
|
|
927
973
|
self._Events.logImpressionEvent(
|
|
928
974
|
impression,
|
|
@@ -983,12 +1029,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
983
1029
|
* @param {String or Number} value value for session attribute
|
|
984
1030
|
*/
|
|
985
1031
|
this.setSessionAttribute = function(key, value) {
|
|
986
|
-
|
|
987
|
-
self.
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1032
|
+
var queued = queueIfNotInitialized(function() {
|
|
1033
|
+
self.setSessionAttribute(key, value);
|
|
1034
|
+
}, self);
|
|
1035
|
+
|
|
1036
|
+
if (queued) return;
|
|
1037
|
+
|
|
992
1038
|
// Logs to cookie
|
|
993
1039
|
// And logs to in-memory object
|
|
994
1040
|
// Example: mParticle.setSessionAttribute('location', '33431');
|
|
@@ -1034,12 +1080,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
1034
1080
|
* @param {Boolean} isOptingOut boolean to opt out or not. When set to true, opt out of logging.
|
|
1035
1081
|
*/
|
|
1036
1082
|
this.setOptOut = function(isOptingOut) {
|
|
1037
|
-
|
|
1038
|
-
self.
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1083
|
+
var queued = queueIfNotInitialized(function() {
|
|
1084
|
+
self.setOptOut(isOptingOut);
|
|
1085
|
+
}, self);
|
|
1086
|
+
|
|
1087
|
+
if (queued) return;
|
|
1088
|
+
|
|
1043
1089
|
self._SessionManager.resetSessionTimer();
|
|
1044
1090
|
self._Store.isEnabled = !isOptingOut;
|
|
1045
1091
|
|
|
@@ -1072,12 +1118,11 @@ export default function mParticleInstance(instanceName) {
|
|
|
1072
1118
|
* also pass a null or empty map here to remove all of the attributes.
|
|
1073
1119
|
*/
|
|
1074
1120
|
this.setIntegrationAttribute = function(integrationId, attrs) {
|
|
1075
|
-
|
|
1076
|
-
self.
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1121
|
+
var queued = queueIfNotInitialized(function() {
|
|
1122
|
+
self.setIntegrationAttribute(integrationId, attrs);
|
|
1123
|
+
}, self);
|
|
1124
|
+
|
|
1125
|
+
if (queued) return;
|
|
1081
1126
|
|
|
1082
1127
|
if (typeof integrationId !== 'number') {
|
|
1083
1128
|
self.Logger.error('integrationId must be a number');
|
|
@@ -1295,6 +1340,9 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
|
|
|
1295
1340
|
mpInstance._APIClient.prepareForwardingStats
|
|
1296
1341
|
);
|
|
1297
1342
|
|
|
1343
|
+
mpInstance._SessionManager.initialize();
|
|
1344
|
+
mpInstance._Events.logAST();
|
|
1345
|
+
|
|
1298
1346
|
// Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
|
|
1299
1347
|
if (
|
|
1300
1348
|
!mpInstance._Store.identifyCalled &&
|
|
@@ -1331,9 +1379,6 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
|
|
|
1331
1379
|
},
|
|
1332
1380
|
});
|
|
1333
1381
|
}
|
|
1334
|
-
|
|
1335
|
-
mpInstance._SessionManager.initialize();
|
|
1336
|
-
mpInstance._Events.logAST();
|
|
1337
1382
|
}
|
|
1338
1383
|
|
|
1339
1384
|
mpInstance._Store.isInitialized = true;
|
|
@@ -1464,3 +1509,13 @@ function processPreloadedItem(readyQueueItem, mpInstance) {
|
|
|
1464
1509
|
}
|
|
1465
1510
|
}
|
|
1466
1511
|
}
|
|
1512
|
+
|
|
1513
|
+
function queueIfNotInitialized(func, self) {
|
|
1514
|
+
if (!self.isInitialized()) {
|
|
1515
|
+
self.ready(function() {
|
|
1516
|
+
func();
|
|
1517
|
+
});
|
|
1518
|
+
return true;
|
|
1519
|
+
}
|
|
1520
|
+
return false;
|
|
1521
|
+
}
|
|
@@ -97,6 +97,12 @@ function mParticle() {
|
|
|
97
97
|
this.getDeviceId = function() {
|
|
98
98
|
return self.getInstance().getDeviceId();
|
|
99
99
|
};
|
|
100
|
+
this.setDeviceId = function(guid) {
|
|
101
|
+
return self.getInstance().setDeviceId(guid);
|
|
102
|
+
};
|
|
103
|
+
this.isInitialized = function() {
|
|
104
|
+
return self.getInstance().isInitialized();
|
|
105
|
+
};
|
|
100
106
|
this.startNewSession = function() {
|
|
101
107
|
self.getInstance().startNewSession();
|
|
102
108
|
};
|
package/src/persistence.js
CHANGED
|
@@ -457,8 +457,8 @@ export default function _Persistence(mpInstance) {
|
|
|
457
457
|
for (i = 0, l = cookies.length; i < l; i++) {
|
|
458
458
|
try {
|
|
459
459
|
parts = cookies[i].split('=');
|
|
460
|
-
name =
|
|
461
|
-
cookie =
|
|
460
|
+
name = parts.shift();
|
|
461
|
+
cookie = parts.join('=');
|
|
462
462
|
} catch (e) {
|
|
463
463
|
mpInstance.Logger.verbose(
|
|
464
464
|
'Unable to parse cookie: ' + name + '. Skipping.'
|
|
@@ -1148,6 +1148,11 @@ export default function _Persistence(mpInstance) {
|
|
|
1148
1148
|
return mpInstance._Store.deviceId;
|
|
1149
1149
|
};
|
|
1150
1150
|
|
|
1151
|
+
this.setDeviceId = function(guid) {
|
|
1152
|
+
mpInstance._Store.deviceId = guid;
|
|
1153
|
+
self.update();
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1151
1156
|
this.resetPersistence = function() {
|
|
1152
1157
|
removeLocalStorage(StorageNames.localStorageName);
|
|
1153
1158
|
removeLocalStorage(StorageNames.localStorageNameV3);
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -156,6 +156,7 @@ export interface SDKConfig {
|
|
|
156
156
|
minWebviewBridgeVersion: number;
|
|
157
157
|
isIOS?: boolean;
|
|
158
158
|
identifyRequest: { [key: string]: {[key: string]: string} };
|
|
159
|
+
identityCallback: (result) => void;
|
|
159
160
|
requestConfig: boolean;
|
|
160
161
|
dataPlanOptions: KitBlockerOptions // when the user provides their own data plan
|
|
161
162
|
dataPlanResult?: DataPlanResult // when the data plan comes from the server via /config
|
package/src/store.js
CHANGED
|
@@ -74,6 +74,9 @@ export default function Store(config, mpInstance) {
|
|
|
74
74
|
this.SDKConfig = createSDKConfig(config);
|
|
75
75
|
// Set configuration to default settings
|
|
76
76
|
if (config) {
|
|
77
|
+
if (config.deviceId) {
|
|
78
|
+
this.deviceId = config.deviceId;
|
|
79
|
+
}
|
|
77
80
|
if (config.hasOwnProperty('isDevelopmentMode')) {
|
|
78
81
|
this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean(
|
|
79
82
|
config.isDevelopmentMode
|