@mparticle/web-sdk 2.79.0 → 2.79.2
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 +21 -10
- package/dist/mparticle.esm.js +21 -10
- package/dist/mparticle.js +198 -65
- package/dist/types/src/ecommerce.interfaces.d.ts +8 -7
- package/dist/types/src/events.d.ts +3 -18
- package/dist/types/src/events.interfaces.d.ts +2 -2
- package/dist/types/src/helpers.d.ts +3 -54
- package/dist/types/src/pageViewTracker.d.ts +14 -1
- package/dist/types/src/polyfill.d.ts +13 -14
- package/dist/types/src/sdkRuntimeModels.d.ts +10 -3
- package/dist/types/src/store.d.ts +1 -0
- package/package.json +1 -1
- package/src/ecommerce.interfaces.ts +12 -8
- package/src/events.interfaces.ts +3 -3
- package/src/{events.js → events.ts} +152 -82
- package/src/{helpers.js → helpers.ts} +117 -63
- package/src/mp-instance.ts +32 -2
- package/src/pageViewTracker.ts +162 -47
- package/src/{polyfill.js → polyfill.ts} +36 -36
- package/src/sdkRuntimeModels.ts +19 -3
- package/src/store.ts +1 -0
package/dist/mparticle.js
CHANGED
|
@@ -134,7 +134,7 @@ var mParticle = (function () {
|
|
|
134
134
|
}
|
|
135
135
|
k = 0;
|
|
136
136
|
while (k < len) {
|
|
137
|
-
var kValue;
|
|
137
|
+
var kValue = void 0;
|
|
138
138
|
if (k in O) {
|
|
139
139
|
kValue = O[k];
|
|
140
140
|
callback.call(T, kValue, k, O);
|
|
@@ -161,7 +161,8 @@ var mParticle = (function () {
|
|
|
161
161
|
A = new Array(len);
|
|
162
162
|
k = 0;
|
|
163
163
|
while (k < len) {
|
|
164
|
-
var kValue,
|
|
164
|
+
var kValue = void 0,
|
|
165
|
+
mappedValue = void 0;
|
|
165
166
|
if (k in O) {
|
|
166
167
|
kValue = O[k];
|
|
167
168
|
mappedValue = callback.call(T, kValue, k, O);
|
|
@@ -203,7 +204,7 @@ var mParticle = (function () {
|
|
|
203
204
|
Base64: Base64$1
|
|
204
205
|
};
|
|
205
206
|
|
|
206
|
-
var version = "2.79.
|
|
207
|
+
var version = "2.79.2";
|
|
207
208
|
|
|
208
209
|
var Constants = {
|
|
209
210
|
sdkVersion: version,
|
|
@@ -3858,6 +3859,33 @@ var mParticle = (function () {
|
|
|
3858
3859
|
}();
|
|
3859
3860
|
|
|
3860
3861
|
var StorageNames$1 = Constants.StorageNames;
|
|
3862
|
+
function appendFilteredUserIdentity(filteredUserIdentities, identity, userIdentityType) {
|
|
3863
|
+
if (userIdentityType === Types.IdentityType.CustomerId) {
|
|
3864
|
+
filteredUserIdentities.unshift(identity);
|
|
3865
|
+
} else {
|
|
3866
|
+
filteredUserIdentities.push(identity);
|
|
3867
|
+
}
|
|
3868
|
+
}
|
|
3869
|
+
function buildFilteredUserIdentities(userIdentitiesObject, filterList, inArray) {
|
|
3870
|
+
var filteredUserIdentities = [];
|
|
3871
|
+
if (!userIdentitiesObject || !Object.keys(userIdentitiesObject).length) {
|
|
3872
|
+
return filteredUserIdentities;
|
|
3873
|
+
}
|
|
3874
|
+
for (var userIdentityName in userIdentitiesObject) {
|
|
3875
|
+
if (!userIdentitiesObject.hasOwnProperty(userIdentityName)) {
|
|
3876
|
+
continue;
|
|
3877
|
+
}
|
|
3878
|
+
var userIdentityType = Types.IdentityType.getIdentityType(userIdentityName);
|
|
3879
|
+
if (inArray(filterList, userIdentityType)) {
|
|
3880
|
+
continue;
|
|
3881
|
+
}
|
|
3882
|
+
appendFilteredUserIdentity(filteredUserIdentities, {
|
|
3883
|
+
Type: userIdentityType,
|
|
3884
|
+
Identity: userIdentitiesObject[userIdentityName]
|
|
3885
|
+
}, userIdentityType);
|
|
3886
|
+
}
|
|
3887
|
+
return filteredUserIdentities;
|
|
3888
|
+
}
|
|
3861
3889
|
function Helpers(mpInstance) {
|
|
3862
3890
|
var self = this;
|
|
3863
3891
|
this.canLog = function () {
|
|
@@ -3960,26 +3988,7 @@ var mParticle = (function () {
|
|
|
3960
3988
|
return xhr;
|
|
3961
3989
|
};
|
|
3962
3990
|
this.filterUserIdentities = function (userIdentitiesObject, filterList) {
|
|
3963
|
-
|
|
3964
|
-
if (userIdentitiesObject && Object.keys(userIdentitiesObject).length) {
|
|
3965
|
-
for (var userIdentityName in userIdentitiesObject) {
|
|
3966
|
-
if (userIdentitiesObject.hasOwnProperty(userIdentityName)) {
|
|
3967
|
-
var userIdentityType = Types.IdentityType.getIdentityType(userIdentityName);
|
|
3968
|
-
if (!self.inArray(filterList, userIdentityType)) {
|
|
3969
|
-
var identity = {
|
|
3970
|
-
Type: userIdentityType,
|
|
3971
|
-
Identity: userIdentitiesObject[userIdentityName]
|
|
3972
|
-
};
|
|
3973
|
-
if (userIdentityType === Types.IdentityType.CustomerId) {
|
|
3974
|
-
filteredUserIdentities.unshift(identity);
|
|
3975
|
-
} else {
|
|
3976
|
-
filteredUserIdentities.push(identity);
|
|
3977
|
-
}
|
|
3978
|
-
}
|
|
3979
|
-
}
|
|
3980
|
-
}
|
|
3981
|
-
}
|
|
3982
|
-
return filteredUserIdentities;
|
|
3991
|
+
return buildFilteredUserIdentities(userIdentitiesObject, filterList, self.inArray);
|
|
3983
3992
|
};
|
|
3984
3993
|
this.filterUserIdentitiesForForwarders = KitFilterHelper.filterUserIdentities;
|
|
3985
3994
|
this.filterUserAttributes = KitFilterHelper.filterUserAttributes;
|
|
@@ -4028,7 +4037,6 @@ var mParticle = (function () {
|
|
|
4028
4037
|
return StorageNames$1.currentStorageName;
|
|
4029
4038
|
}
|
|
4030
4039
|
};
|
|
4031
|
-
|
|
4032
4040
|
// TODO: Refactor SDK to directly use these methods
|
|
4033
4041
|
// https://go.mparticle.com/work/SQDSDKS-5239
|
|
4034
4042
|
// Utility Functions
|
|
@@ -4041,7 +4049,6 @@ var mParticle = (function () {
|
|
|
4041
4049
|
this.parseStringOrNumber = parseStringOrNumber;
|
|
4042
4050
|
this.generateHash = generateHash;
|
|
4043
4051
|
this.generateUniqueId = generateUniqueId;
|
|
4044
|
-
|
|
4045
4052
|
// Imported Validators
|
|
4046
4053
|
this.Validators = Validators;
|
|
4047
4054
|
}
|
|
@@ -6502,7 +6509,6 @@ var mParticle = (function () {
|
|
|
6502
6509
|
};
|
|
6503
6510
|
this.logCommerceEvent = function (commerceEvent, attrs, options) {
|
|
6504
6511
|
mpInstance.Logger.verbose(Messages$3.InformationMessages.StartingLogCommerceEvent);
|
|
6505
|
-
|
|
6506
6512
|
// If a developer typos the ProductActionType, the event category will be
|
|
6507
6513
|
// null, resulting in kit forwarding errors on the server.
|
|
6508
6514
|
// The check for `ProductAction` is required to denote that these are
|
|
@@ -6511,23 +6517,21 @@ var mParticle = (function () {
|
|
|
6511
6517
|
mpInstance.Logger.error('Commerce event not sent. The mParticle.ProductActionType you passed was invalid. Re-check your code.');
|
|
6512
6518
|
return;
|
|
6513
6519
|
}
|
|
6514
|
-
|
|
6520
|
+
var sanitizedAttrs = mpInstance._Helpers.sanitizeAttributes(attrs, commerceEvent.EventName);
|
|
6515
6521
|
if (mpInstance._Helpers.canLog()) {
|
|
6516
6522
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
6517
6523
|
// Don't send shopping cart to parent sdks
|
|
6518
6524
|
commerceEvent.ShoppingCart = {};
|
|
6519
6525
|
}
|
|
6520
|
-
if (
|
|
6521
|
-
commerceEvent.EventAttributes =
|
|
6526
|
+
if (sanitizedAttrs) {
|
|
6527
|
+
commerceEvent.EventAttributes = sanitizedAttrs;
|
|
6522
6528
|
}
|
|
6523
|
-
|
|
6524
6529
|
// When no transaction total (Revenue) was provided, derive it from
|
|
6525
6530
|
// the products, shipping, and tax.
|
|
6526
6531
|
if (commerceEvent.ProductAction) {
|
|
6527
6532
|
mpInstance._Ecommerce.calculateProductActionTotalAmount(commerceEvent.ProductAction);
|
|
6528
6533
|
}
|
|
6529
6534
|
mpInstance._APIClient.sendEventToServer(commerceEvent, options);
|
|
6530
|
-
|
|
6531
6535
|
// https://go.mparticle.com/work/SQDSDKS-6038
|
|
6532
6536
|
mpInstance._Persistence.update();
|
|
6533
6537
|
} else {
|
|
@@ -6551,11 +6555,9 @@ var mParticle = (function () {
|
|
|
6551
6555
|
data: typeof data === 'function' ? data(element) : data,
|
|
6552
6556
|
eventType: eventType || Types.EventType.Other
|
|
6553
6557
|
});
|
|
6554
|
-
|
|
6555
6558
|
// TODO: Handle middle-clicks and special keys (ctrl, alt, etc)
|
|
6556
6559
|
if (element.href && element.target !== '_blank' || element.submit) {
|
|
6557
6560
|
// Give xmlhttprequest enough time to execute before navigating a link or submitting form
|
|
6558
|
-
|
|
6559
6561
|
if (e.preventDefault) {
|
|
6560
6562
|
e.preventDefault();
|
|
6561
6563
|
} else {
|
|
@@ -6570,7 +6572,6 @@ var mParticle = (function () {
|
|
|
6570
6572
|
mpInstance.Logger.error("Can't bind event, selector is required");
|
|
6571
6573
|
return;
|
|
6572
6574
|
}
|
|
6573
|
-
|
|
6574
6575
|
// Handle a css selector string or a dom element
|
|
6575
6576
|
if (typeof selector === 'string') {
|
|
6576
6577
|
elements = document.querySelectorAll(selector);
|
|
@@ -11172,10 +11173,19 @@ var mParticle = (function () {
|
|
|
11172
11173
|
}();
|
|
11173
11174
|
|
|
11174
11175
|
var WRAPPED_MARKER = '__mpApvWrapped__';
|
|
11176
|
+
// window key under which the single active tracker is stored.
|
|
11177
|
+
// Survives module re-evaluation (Next.js re-executes the bundle on every SPA
|
|
11178
|
+
// navigation, resetting all module-level state, but window persists for the
|
|
11179
|
+
// lifetime of the tab).
|
|
11180
|
+
var WIN_TRACKER_KEY = '__mpApvTracker__';
|
|
11181
|
+
// Guards the initial page view so repeated mParticle.init() calls from SPA
|
|
11182
|
+
// re-renders don't fire duplicate logPageView() events for the same page.
|
|
11183
|
+
var WIN_INIT_PV_KEY = '__mpApvInitPVLogged__';
|
|
11175
11184
|
var PageViewTracker = /** @class */function () {
|
|
11176
11185
|
function PageViewTracker(mpInstance) {
|
|
11177
11186
|
this.lastPath = null;
|
|
11178
|
-
this.
|
|
11187
|
+
this._isActive = false;
|
|
11188
|
+
this.pendingNavigations = [];
|
|
11179
11189
|
this.originalPushState = null;
|
|
11180
11190
|
this.originalReplaceState = null;
|
|
11181
11191
|
this.pushStateWrapper = null;
|
|
@@ -11183,31 +11193,91 @@ var mParticle = (function () {
|
|
|
11183
11193
|
this.popStateListener = null;
|
|
11184
11194
|
this.mpInstance = mpInstance;
|
|
11185
11195
|
}
|
|
11196
|
+
PageViewTracker.hasInitialPageViewFired = function () {
|
|
11197
|
+
return !!window[WIN_INIT_PV_KEY];
|
|
11198
|
+
};
|
|
11199
|
+
PageViewTracker.markInitialPageViewFired = function () {
|
|
11200
|
+
window[WIN_INIT_PV_KEY] = true;
|
|
11201
|
+
};
|
|
11202
|
+
// Tears down any window-registered tracker that differs from instanceTracker
|
|
11203
|
+
// (e.g. left by a previous module load), then clears both APV window flags.
|
|
11204
|
+
// Call from _resetForTests after tearing down the instance-level tracker.
|
|
11205
|
+
PageViewTracker.resetWindowState = function (instanceTracker) {
|
|
11206
|
+
var windowTracker = getWindowTracker();
|
|
11207
|
+
if (windowTracker && windowTracker !== instanceTracker) {
|
|
11208
|
+
windowTracker.teardown();
|
|
11209
|
+
}
|
|
11210
|
+
if (typeof window !== 'undefined') {
|
|
11211
|
+
delete window[WIN_INIT_PV_KEY];
|
|
11212
|
+
}
|
|
11213
|
+
setWindowTracker(undefined);
|
|
11214
|
+
};
|
|
11215
|
+
Object.defineProperty(PageViewTracker.prototype, "isActive", {
|
|
11216
|
+
get: function get() {
|
|
11217
|
+
return this._isActive;
|
|
11218
|
+
},
|
|
11219
|
+
enumerable: false,
|
|
11220
|
+
configurable: true
|
|
11221
|
+
});
|
|
11186
11222
|
PageViewTracker.prototype.isSupportedEnvironment = function () {
|
|
11187
11223
|
return typeof window !== 'undefined' && typeof window.history !== 'undefined' && typeof window.history.pushState === 'function' && typeof window.addEventListener === 'function';
|
|
11188
11224
|
};
|
|
11189
11225
|
PageViewTracker.prototype.init = function () {
|
|
11226
|
+
var _this = this;
|
|
11190
11227
|
this.mpInstance.Logger.verbose('mParticle APV: [init] PageViewTracker Init');
|
|
11191
11228
|
if (!this.isSupportedEnvironment()) {
|
|
11192
11229
|
this.mpInstance.Logger.verbose('mParticle APV: [init] unsupported environment (no History API), not starting');
|
|
11193
11230
|
return;
|
|
11194
11231
|
}
|
|
11195
|
-
|
|
11232
|
+
// Tear down any tracker left over from a previous module load.
|
|
11233
|
+
// window[WIN_TRACKER_KEY] outlives module re-evaluation; this is the
|
|
11234
|
+
// only way to reach a tracker instance in a dead module scope.
|
|
11235
|
+
// Transfer any pending navigations first so a route change that queued a
|
|
11236
|
+
// deferred fire before module re-evaluation occurs is not silently dropped.
|
|
11237
|
+
var prev = getWindowTracker();
|
|
11238
|
+
var inheritedPaths = [];
|
|
11239
|
+
if (prev && prev !== this) {
|
|
11240
|
+
this.mpInstance.Logger.verbose('mParticle APV: [init] found stale tracker from previous module load — transferring pending navigations and tearing down');
|
|
11241
|
+
inheritedPaths = prev.takePendingNavigations();
|
|
11242
|
+
prev.teardown();
|
|
11243
|
+
}
|
|
11244
|
+
if (this._isActive) {
|
|
11196
11245
|
this.mpInstance.Logger.verbose('mParticle APV: [init] starting (teardown-first for idempotency)');
|
|
11246
|
+
// Preserve pending navigations through the self-teardown so a route
|
|
11247
|
+
// change queued before mParticle.init() was called again is not lost.
|
|
11248
|
+
inheritedPaths = __spreadArray(__spreadArray([], inheritedPaths, true), this.takePendingNavigations(), true);
|
|
11197
11249
|
this.teardown();
|
|
11198
11250
|
}
|
|
11199
|
-
this.
|
|
11251
|
+
this._isActive = true;
|
|
11200
11252
|
this.lastPath = this.getCurrentKey();
|
|
11201
11253
|
this.mpInstance.Logger.verbose("mParticle APV: [init] seeded lastPath: ".concat(this.lastPath));
|
|
11202
11254
|
this.patchHistoryMethods();
|
|
11203
11255
|
this.addNavigationListeners();
|
|
11256
|
+
setWindowTracker(this);
|
|
11204
11257
|
this.mpInstance.Logger.verbose('mParticle APV: [init] patched pushState/replaceState + listening for popstate');
|
|
11258
|
+
// Re-fire navigations that the stale tracker had queued but not yet flushed
|
|
11259
|
+
// when module re-evaluation occurred. Title is read at flush time so the
|
|
11260
|
+
// router's post-navigation render commit still has a chance to update it.
|
|
11261
|
+
inheritedPaths.forEach(function (path) {
|
|
11262
|
+
var timeoutId = setTimeout(function () {
|
|
11263
|
+
_this.pendingNavigations = _this.pendingNavigations.filter(function (p) {
|
|
11264
|
+
return p.timeoutId !== timeoutId;
|
|
11265
|
+
});
|
|
11266
|
+
if (!_this._isActive) return;
|
|
11267
|
+
_this.mpInstance._SessionManager.resetSessionTimer();
|
|
11268
|
+
_this.firePageView(path);
|
|
11269
|
+
}, 0);
|
|
11270
|
+
_this.pendingNavigations.push({
|
|
11271
|
+
path: path,
|
|
11272
|
+
timeoutId: timeoutId
|
|
11273
|
+
});
|
|
11274
|
+
});
|
|
11205
11275
|
};
|
|
11206
11276
|
PageViewTracker.prototype.patchHistoryMethods = function () {
|
|
11207
11277
|
var self = this;
|
|
11208
11278
|
var installed = window.history.pushState;
|
|
11209
11279
|
if (installed[WRAPPED_MARKER]) {
|
|
11210
|
-
this.mpInstance.Logger.verbose('mParticle APV: [patch] history already wrapped, skipping to avoid double-wrap');
|
|
11280
|
+
this.mpInstance.Logger.verbose('mParticle APV: [patch] history already wrapped, skipping to avoid double-wrap — STACKED WRAPPER DETECTED');
|
|
11211
11281
|
return;
|
|
11212
11282
|
}
|
|
11213
11283
|
var originalPushState = window.history.pushState;
|
|
@@ -11220,7 +11290,9 @@ var mParticle = (function () {
|
|
|
11220
11290
|
args[_i] = arguments[_i];
|
|
11221
11291
|
}
|
|
11222
11292
|
var result = originalPushState.apply(this, args);
|
|
11223
|
-
self.
|
|
11293
|
+
if (self._isActive) {
|
|
11294
|
+
self.safeHandleNavigation('pushState');
|
|
11295
|
+
}
|
|
11224
11296
|
return result;
|
|
11225
11297
|
};
|
|
11226
11298
|
var replaceStateWrapper = function replaceStateWrapper() {
|
|
@@ -11229,7 +11301,9 @@ var mParticle = (function () {
|
|
|
11229
11301
|
args[_i] = arguments[_i];
|
|
11230
11302
|
}
|
|
11231
11303
|
var result = originalReplaceState.apply(this, args);
|
|
11232
|
-
self.
|
|
11304
|
+
if (self._isActive) {
|
|
11305
|
+
self.safeHandleNavigation('replaceState');
|
|
11306
|
+
}
|
|
11233
11307
|
return result;
|
|
11234
11308
|
};
|
|
11235
11309
|
Object.defineProperty(pushStateWrapper, WRAPPED_MARKER, {
|
|
@@ -11296,14 +11370,21 @@ var mParticle = (function () {
|
|
|
11296
11370
|
// later (in the deferred flush) so the router's post-navigation render
|
|
11297
11371
|
// commit has a chance to update document.title first.
|
|
11298
11372
|
var capturedPath = candidatePath;
|
|
11299
|
-
setTimeout(function () {
|
|
11300
|
-
|
|
11373
|
+
var timeoutId = setTimeout(function () {
|
|
11374
|
+
_this.pendingNavigations = _this.pendingNavigations.filter(function (p) {
|
|
11375
|
+
return p.timeoutId !== timeoutId;
|
|
11376
|
+
});
|
|
11377
|
+
if (!_this._isActive) {
|
|
11301
11378
|
_this.mpInstance.Logger.verbose('mParticle APV: [defer] fire aborted, tracker inactive (torn down before flush)');
|
|
11302
11379
|
return;
|
|
11303
11380
|
}
|
|
11304
11381
|
_this.mpInstance._SessionManager.resetSessionTimer();
|
|
11305
11382
|
_this.firePageView(capturedPath);
|
|
11306
11383
|
}, 0);
|
|
11384
|
+
this.pendingNavigations.push({
|
|
11385
|
+
path: capturedPath,
|
|
11386
|
+
timeoutId: timeoutId
|
|
11387
|
+
});
|
|
11307
11388
|
};
|
|
11308
11389
|
// Mirrors the event shape of the public mParticle.logPageView(), but carries
|
|
11309
11390
|
// the captured SPA path rather than reading the live location.
|
|
@@ -11321,37 +11402,67 @@ var mParticle = (function () {
|
|
|
11321
11402
|
eventType: EventType.Unknown
|
|
11322
11403
|
});
|
|
11323
11404
|
};
|
|
11405
|
+
// Cancels pending deferred fires and returns their captured paths so a
|
|
11406
|
+
// successor tracker can re-schedule them. Call before teardown() during
|
|
11407
|
+
// module-replacement handoff.
|
|
11408
|
+
PageViewTracker.prototype.takePendingNavigations = function () {
|
|
11409
|
+
var paths = this.pendingNavigations.map(function (p) {
|
|
11410
|
+
return p.path;
|
|
11411
|
+
});
|
|
11412
|
+
this.pendingNavigations.forEach(function (p) {
|
|
11413
|
+
return clearTimeout(p.timeoutId);
|
|
11414
|
+
});
|
|
11415
|
+
this.pendingNavigations = [];
|
|
11416
|
+
return paths;
|
|
11417
|
+
};
|
|
11418
|
+
PageViewTracker.prototype.restoreHistoryMethod = function (methodName, original, wrapper) {
|
|
11419
|
+
if (!original) return;
|
|
11420
|
+
var stillOurs = wrapper !== null && window.history[methodName] === wrapper;
|
|
11421
|
+
if (stillOurs) {
|
|
11422
|
+
window.history[methodName] = original;
|
|
11423
|
+
this.mpInstance.Logger.verbose("mParticle APV: [teardown] restored original ".concat(methodName));
|
|
11424
|
+
} else {
|
|
11425
|
+
this.mpInstance.Logger.verbose("mParticle APV: [teardown] ".concat(methodName, " no longer ours; leaving in place, gating callback to no-op"));
|
|
11426
|
+
}
|
|
11427
|
+
};
|
|
11324
11428
|
PageViewTracker.prototype.teardown = function () {
|
|
11429
|
+
// Cancel any pending deferred fires (e.g. when the feature flag is
|
|
11430
|
+
// disabled on re-init). For module-replacement, call takePendingNavigations()
|
|
11431
|
+
// before teardown() instead so paths are transferred, not discarded.
|
|
11432
|
+
this.pendingNavigations.forEach(function (p) {
|
|
11433
|
+
return clearTimeout(p.timeoutId);
|
|
11434
|
+
});
|
|
11435
|
+
this.pendingNavigations = [];
|
|
11325
11436
|
if (this.popStateListener) {
|
|
11326
11437
|
window.removeEventListener('popstate', this.popStateListener);
|
|
11327
11438
|
this.popStateListener = null;
|
|
11328
11439
|
}
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
|
|
11332
|
-
|
|
11333
|
-
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
this.pushStateWrapper = null;
|
|
11339
|
-
}
|
|
11340
|
-
var replaceStateStillOurs = this.replaceStateWrapper !== null && window.history.replaceState === this.replaceStateWrapper;
|
|
11341
|
-
if (this.originalReplaceState) {
|
|
11342
|
-
if (replaceStateStillOurs) {
|
|
11343
|
-
window.history.replaceState = this.originalReplaceState;
|
|
11344
|
-
this.mpInstance.Logger.verbose('mParticle APV: [teardown] restored original replaceState');
|
|
11345
|
-
} else {
|
|
11346
|
-
this.mpInstance.Logger.verbose('mParticle APV: [teardown] replaceState no longer ours; leaving in place, gating callback to no-op');
|
|
11347
|
-
}
|
|
11348
|
-
this.originalReplaceState = null;
|
|
11349
|
-
this.replaceStateWrapper = null;
|
|
11440
|
+
this.restoreHistoryMethod('pushState', this.originalPushState, this.pushStateWrapper);
|
|
11441
|
+
this.originalPushState = null;
|
|
11442
|
+
this.pushStateWrapper = null;
|
|
11443
|
+
this.restoreHistoryMethod('replaceState', this.originalReplaceState, this.replaceStateWrapper);
|
|
11444
|
+
this.originalReplaceState = null;
|
|
11445
|
+
this.replaceStateWrapper = null;
|
|
11446
|
+
this._isActive = false;
|
|
11447
|
+
if (getWindowTracker() === this) {
|
|
11448
|
+
setWindowTracker(undefined);
|
|
11350
11449
|
}
|
|
11351
|
-
this.isActive = false;
|
|
11352
11450
|
};
|
|
11353
11451
|
return PageViewTracker;
|
|
11354
11452
|
}();
|
|
11453
|
+
function getWindowTracker() {
|
|
11454
|
+
if (typeof window === 'undefined') return undefined;
|
|
11455
|
+
return window[WIN_TRACKER_KEY];
|
|
11456
|
+
}
|
|
11457
|
+
function setWindowTracker(tracker) {
|
|
11458
|
+
if (typeof window === 'undefined') return;
|
|
11459
|
+
var win = window;
|
|
11460
|
+
if (tracker) {
|
|
11461
|
+
win[WIN_TRACKER_KEY] = tracker;
|
|
11462
|
+
} else {
|
|
11463
|
+
delete win[WIN_TRACKER_KEY];
|
|
11464
|
+
}
|
|
11465
|
+
}
|
|
11355
11466
|
|
|
11356
11467
|
var Messages = Constants.Messages,
|
|
11357
11468
|
HTTPCodes = Constants.HTTPCodes,
|
|
@@ -11505,6 +11616,12 @@ var mParticle = (function () {
|
|
|
11505
11616
|
instance._Store = new Store(config, instance);
|
|
11506
11617
|
instance._Store.isLocalStorageAvailable = instance._Persistence.determineLocalStorageAvailability(window.localStorage);
|
|
11507
11618
|
instance._Events.stopTracking();
|
|
11619
|
+
var instanceTracker = instance._PageViewTracker;
|
|
11620
|
+
if (instanceTracker) {
|
|
11621
|
+
instanceTracker.teardown();
|
|
11622
|
+
instance._PageViewTracker = undefined;
|
|
11623
|
+
}
|
|
11624
|
+
PageViewTracker.resetWindowState(instanceTracker);
|
|
11508
11625
|
if (!keepPersistence) {
|
|
11509
11626
|
instance._Persistence.resetPersistence();
|
|
11510
11627
|
}
|
|
@@ -12431,13 +12548,29 @@ var mParticle = (function () {
|
|
|
12431
12548
|
// Logs a session start or session end event accordingly
|
|
12432
12549
|
mpInstance._SessionManager.initialize();
|
|
12433
12550
|
mpInstance._Events.logAST();
|
|
12551
|
+
// Note: APV uses window-level singletons (WIN_TRACKER_KEY, WIN_INIT_PV_KEY)
|
|
12552
|
+
// that assume a single active SDK instance. Multiple-instance support is
|
|
12553
|
+
// out of scope
|
|
12434
12554
|
if (getFeatureFlag(AutoLogPageView)) {
|
|
12435
|
-
mpInstance._Events.logPageView();
|
|
12436
12555
|
if (!mpInstance._PageViewTracker) {
|
|
12556
|
+
mpInstance.Logger.verbose('mParticle APV: [sdk-init] creating new PageViewTracker for this instance');
|
|
12437
12557
|
mpInstance._PageViewTracker = new PageViewTracker(mpInstance);
|
|
12558
|
+
// Fire the initial page view once per page load (hard navigation).
|
|
12559
|
+
// The flag survives module re-evaluation so repeated init() calls
|
|
12560
|
+
// from SPA re-renders don't fire duplicate logPageView() events.
|
|
12561
|
+
if (PageViewTracker.hasInitialPageViewFired()) {
|
|
12562
|
+
mpInstance.Logger.verbose('mParticle APV: [sdk-init] initial page view already logged this page load, skipping');
|
|
12563
|
+
} else {
|
|
12564
|
+
PageViewTracker.markInitialPageViewFired();
|
|
12565
|
+
mpInstance._Events.logPageView();
|
|
12566
|
+
}
|
|
12567
|
+
} else {
|
|
12568
|
+
mpInstance.Logger.verbose('mParticle APV: [sdk-init] tracker already on this instance, skipping logPageView');
|
|
12438
12569
|
}
|
|
12439
12570
|
mpInstance._PageViewTracker.init();
|
|
12440
12571
|
} else if (mpInstance._PageViewTracker) {
|
|
12572
|
+
// AutoLogPageView was disabled on re-init: tear down the active tracker
|
|
12573
|
+
// so it stops listening. Re-created if the flag is re-enabled later.
|
|
12441
12574
|
mpInstance._PageViewTracker.teardown();
|
|
12442
12575
|
}
|
|
12443
12576
|
processIdentityCallback(mpInstance, currentUser, currentUserMPID, currentUserIdentities);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ProductAction, Product, Promotion, CommerceEvent } from '@mparticle/event-models';
|
|
2
2
|
import { SDKEventAttrs, SDKEventOptions, TransactionAttributes } from '@mparticle/web-sdk';
|
|
3
3
|
import { valueof } from './utils';
|
|
4
|
-
import { ProductActionType, PromotionActionType
|
|
5
|
-
import { SDKEvent, SDKEventCustomFlags, SDKImpression, SDKProduct,
|
|
4
|
+
import { ProductActionType, PromotionActionType } from './types';
|
|
5
|
+
import { SDKEvent, SDKEventCustomFlags, SDKImpression, SDKProduct, SDKProductAction, SDKPromotion } from './sdkRuntimeModels';
|
|
6
6
|
interface IECommerceShared {
|
|
7
7
|
createProduct(name: string, sku: string | number, price: string | number, quantity?: string | number, variant?: string, category?: string, brand?: string, position?: number, couponCode?: string, attributes?: SDKEventAttrs): SDKProduct | null;
|
|
8
8
|
createImpression(name: string, product: Product): SDKImpression | null;
|
|
@@ -17,7 +17,7 @@ export interface SDKCart {
|
|
|
17
17
|
}
|
|
18
18
|
export interface SDKECommerceAPI extends IECommerceShared {
|
|
19
19
|
logCheckout(step: number, option?: string, attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags): void;
|
|
20
|
-
logImpression(impression:
|
|
20
|
+
logImpression(impression: SDKImpression | SDKImpression[], attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, eventOptions?: SDKEventOptions): void;
|
|
21
21
|
logProductAction(productActionType: valueof<typeof ProductActionType>, product: SDKProduct | SDKProduct[], attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, transactionAttributes?: TransactionAttributes, eventOptions?: SDKEventOptions): void;
|
|
22
22
|
logPromotion(type: valueof<typeof PromotionActionType>, promotion: SDKPromotion, attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, eventOptions?: SDKEventOptions): void;
|
|
23
23
|
setCurrencyCode(code: string): void;
|
|
@@ -57,11 +57,12 @@ interface ExtractedTransactionId {
|
|
|
57
57
|
'Transaction ID'?: string;
|
|
58
58
|
}
|
|
59
59
|
export interface IECommerce extends IECommerceShared {
|
|
60
|
-
buildProductList(event: SDKEvent, product:
|
|
60
|
+
buildProductList(event: SDKEvent, product: SDKProduct | SDKProduct[]): SDKProduct[];
|
|
61
61
|
convertProductActionToEventType(productActionType: valueof<typeof ProductActionType>): // https://go.mparticle.com/work/SQDSDKS-4801
|
|
62
|
-
|
|
63
|
-
convertPromotionActionToEventType(promotionActionType: valueof<typeof PromotionActionType>):
|
|
64
|
-
|
|
62
|
+
number | null;
|
|
63
|
+
convertPromotionActionToEventType(promotionActionType: valueof<typeof PromotionActionType>): number | null;
|
|
64
|
+
calculateProductActionTotalAmount(productAction: SDKProductAction): SDKProductAction;
|
|
65
|
+
convertTransactionAttributesToProductAction(transactionAttributes: TransactionAttributes, productAction: SDKProductAction): void;
|
|
65
66
|
createCommerceEventObject(customFlags: SDKEventCustomFlags, options?: SDKEventOptions): SDKEvent | null;
|
|
66
67
|
expandProductAction(commerceEvent: CommerceEvent): SDKEvent[];
|
|
67
68
|
expandProductImpression(commerceEvent: CommerceEvent): SDKEvent[];
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
logEvent: (event: any, options: any) => void;
|
|
5
|
-
startTracking: (callback: any) => void;
|
|
6
|
-
stopTracking: () => void;
|
|
7
|
-
logOptOut: () => void;
|
|
8
|
-
logAST: () => void;
|
|
9
|
-
logPageView: () => void;
|
|
10
|
-
logCheckoutEvent: (step: any, option: any, attrs: any, customFlags: any) => void;
|
|
11
|
-
logProductActionEvent: (productActionType: any, product: any, customAttrs: any, customFlags: any, transactionAttributes: any, options: any) => void;
|
|
12
|
-
logPurchaseEvent: (transactionAttributes: any, product: any, attrs: any, customFlags: any) => void;
|
|
13
|
-
logRefundEvent: (transactionAttributes: any, product: any, attrs: any, customFlags: any) => void;
|
|
14
|
-
logPromotionEvent: (promotionType: any, promotion: any, attrs: any, customFlags: any, eventOptions: any) => void;
|
|
15
|
-
logImpressionEvent: (impression: any, attrs: any, customFlags: any, options: any) => void;
|
|
16
|
-
logCommerceEvent: (commerceEvent: any, attrs: any, options: any) => void;
|
|
17
|
-
addEventHandler: (domEvent: any, selector: any, eventName: any, data: any, eventType: any) => void;
|
|
18
|
-
}
|
|
1
|
+
import { IEvents } from './events.interfaces';
|
|
2
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
3
|
+
export default function Events(this: IEvents, mpInstance: IMParticleWebSDKInstance): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Callback, SDKEventAttrs, SDKEventOptions, TransactionAttributes } from '@mparticle/web-sdk';
|
|
2
|
-
import { BaseEvent, SDKEvent, SDKEventCustomFlags,
|
|
2
|
+
import { BaseEvent, SDKEvent, SDKEventCustomFlags, SDKImpression, SDKProduct, SDKPromotion } from './sdkRuntimeModels';
|
|
3
3
|
import { valueof } from './utils';
|
|
4
4
|
import { EventType, ProductActionType, PromotionActionType } from './types';
|
|
5
5
|
type EventHandlerFunction<T> = (element: HTMLLinkElement | HTMLFormElement) => T;
|
|
@@ -9,7 +9,7 @@ export interface IEvents {
|
|
|
9
9
|
logCheckoutEvent(step: number, option?: string, attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags): void;
|
|
10
10
|
logCommerceEvent(commerceEvent: SDKEvent, attrs?: SDKEventAttrs, options?: SDKEventOptions): void;
|
|
11
11
|
logEvent(event: BaseEvent, eventOptions?: SDKEventOptions): void;
|
|
12
|
-
logImpressionEvent(impression:
|
|
12
|
+
logImpressionEvent(impression: SDKImpression | SDKImpression[], attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, eventOptions?: SDKEventOptions): void;
|
|
13
13
|
logOptOut(): void;
|
|
14
14
|
logPageView(): void;
|
|
15
15
|
logProductActionEvent(productActionType: valueof<typeof ProductActionType>, product: SDKProduct | SDKProduct[], attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, transactionAttributes?: TransactionAttributes, eventOptions?: SDKEventOptions): void;
|
|
@@ -1,54 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
canLog: () => boolean;
|
|
5
|
-
getFeatureFlag: (feature: any) => any;
|
|
6
|
-
invokeCallback: (callback: any, code: any, body: any, mParticleUser: any, previousMpid: any) => void;
|
|
7
|
-
invokeAliasCallback: (callback: any, code: any, message: any) => void;
|
|
8
|
-
extend: typeof utils.extend;
|
|
9
|
-
createServiceUrl: (secureServiceUrl: any, devToken: any) => string;
|
|
10
|
-
createXHR: (cb: any) => any;
|
|
11
|
-
filterUserIdentities: (userIdentitiesObject: any, filterList: any) => {
|
|
12
|
-
Type: any;
|
|
13
|
-
Identity: any;
|
|
14
|
-
}[];
|
|
15
|
-
filterUserIdentitiesForForwarders: (userIdentities: utils.Dictionary<string>, filterList: number[]) => utils.Dictionary<string>;
|
|
16
|
-
filterUserAttributes: (userAttributes: utils.Dictionary<string>, filterList: number[]) => utils.Dictionary<string>;
|
|
17
|
-
isEventType: (type: any) => boolean;
|
|
18
|
-
sanitizeAttributes: (attrs: any, name: any) => {};
|
|
19
|
-
isDelayedByIntegration: (delayedIntegrations: any, timeoutStart: any, now: any) => boolean;
|
|
20
|
-
createMainStorageName: (workspaceToken: any) => string;
|
|
21
|
-
converted: (s: string) => string;
|
|
22
|
-
findKeyInObject: (obj: any, key: string) => string;
|
|
23
|
-
parseNumber: (value: string | number) => number;
|
|
24
|
-
inArray: (items: any[], name: any) => boolean;
|
|
25
|
-
isObject: (value: any) => boolean;
|
|
26
|
-
decoded: (s: string) => string;
|
|
27
|
-
parseStringOrNumber: (value: string | number) => string | number;
|
|
28
|
-
generateHash: typeof utils.generateHash;
|
|
29
|
-
generateUniqueId: (a?: string) => string;
|
|
30
|
-
Validators: {
|
|
31
|
-
isNumber: (value: any) => boolean;
|
|
32
|
-
isFunction: (fn: any) => boolean;
|
|
33
|
-
isStringOrNumber: (value: any) => boolean;
|
|
34
|
-
isValidAttributeValue: (value: any) => boolean;
|
|
35
|
-
isValidKeyValue: (key: any) => boolean;
|
|
36
|
-
removeFalsyIdentityValues: (identityApiData: import("@mparticle/web-sdk").IdentityApiData, logger: any) => import("@mparticle/web-sdk").IdentityApiData;
|
|
37
|
-
validateIdentities: (identityApiData: import("@mparticle/web-sdk").IdentityApiData, method?: import("./identity.interfaces").IdentityAPIMethod) => {
|
|
38
|
-
valid: boolean;
|
|
39
|
-
error?: utils.valueof<{
|
|
40
|
-
readonly ModifyIdentityRequestUserIdentitiesPresent: "identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again";
|
|
41
|
-
readonly IdentityRequesetInvalidKey: "There is an invalid key on your identityRequest object. It can only contain a `userIdentities` object and a `onUserAlias` function. Request not sent to server. Please fix and try again.";
|
|
42
|
-
readonly OnUserAliasType: "The onUserAlias value must be a function.";
|
|
43
|
-
readonly UserIdentities: "The userIdentities key must be an object with keys of identityTypes and values of strings. Request not sent to server. Please fix and try again.";
|
|
44
|
-
readonly UserIdentitiesInvalidKey: "There is an invalid identity key on your `userIdentities` object within the identityRequest. Request not sent to server. Please fix and try again.";
|
|
45
|
-
readonly UserIdentitiesInvalidValues: "All user identity values must be strings or null. Request not sent to server. Please fix and try again.";
|
|
46
|
-
readonly AliasMissingMpid: "Alias Request must contain both a destinationMpid and a sourceMpid";
|
|
47
|
-
readonly AliasNonUniqueMpid: "Alias Request's destinationMpid and sourceMpid must be unique";
|
|
48
|
-
readonly AliasMissingTime: "Alias Request must have both a startTime and an endTime";
|
|
49
|
-
readonly AliasStartBeforeEndTime: "Alias Request's endTime must be later than its startTime";
|
|
50
|
-
}>;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
import * as utils from './utils';
|
|
1
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
2
|
+
import { SDKHelpersApi } from './sdkRuntimeModels';
|
|
3
|
+
export default function Helpers(this: SDKHelpersApi, mpInstance: IMParticleWebSDKInstance): void;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
2
|
+
export declare const WIN_TRACKER_KEY = "__mpApvTracker__";
|
|
3
|
+
export declare const WIN_INIT_PV_KEY: "__mpApvInitPVLogged__";
|
|
4
|
+
export type WindowWithApvFlags = Window & {
|
|
5
|
+
[WIN_TRACKER_KEY]?: PageViewTracker;
|
|
6
|
+
[WIN_INIT_PV_KEY]?: boolean;
|
|
7
|
+
};
|
|
2
8
|
export declare class PageViewTracker {
|
|
9
|
+
static hasInitialPageViewFired(): boolean;
|
|
10
|
+
static markInitialPageViewFired(): void;
|
|
11
|
+
static resetWindowState(instanceTracker?: PageViewTracker): void;
|
|
3
12
|
mpInstance: IMParticleWebSDKInstance;
|
|
4
13
|
private lastPath;
|
|
5
|
-
private
|
|
14
|
+
private _isActive;
|
|
15
|
+
get isActive(): boolean;
|
|
16
|
+
private pendingNavigations;
|
|
6
17
|
private originalPushState;
|
|
7
18
|
private originalReplaceState;
|
|
8
19
|
private pushStateWrapper;
|
|
@@ -17,5 +28,7 @@ export declare class PageViewTracker {
|
|
|
17
28
|
private getCurrentKey;
|
|
18
29
|
private handleNavigation;
|
|
19
30
|
private firePageView;
|
|
31
|
+
takePendingNavigations(): string[];
|
|
32
|
+
private restoreHistoryMethod;
|
|
20
33
|
teardown(): void;
|
|
21
34
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
declare const _default: {
|
|
2
|
+
forEach: (callback: any, thisArg: any) => void;
|
|
3
|
+
map: (callback: any, thisArg: any) => any;
|
|
4
|
+
filter: (fun: any) => any[];
|
|
5
|
+
isArray: (arg: unknown) => boolean;
|
|
6
|
+
Base64: {
|
|
7
|
+
_keyStr: string;
|
|
8
|
+
encode: (input: string) => string;
|
|
9
|
+
_encode: (input: string) => string;
|
|
10
|
+
decode: (input: string) => string;
|
|
11
|
+
_decode: (input: string) => string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
8
14
|
export default _default;
|
|
9
|
-
declare namespace Base64 {
|
|
10
|
-
let _keyStr: string;
|
|
11
|
-
function encode(input: any): string;
|
|
12
|
-
function _encode(input: any): string;
|
|
13
|
-
function decode(input: any): string;
|
|
14
|
-
function _decode(input: any): string;
|
|
15
|
-
}
|