@mparticle/web-sdk 2.12.9 → 2.14.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/README.md +5 -1
- package/dist/mparticle.common.js +37 -28
- package/dist/mparticle.esm.js +37 -28
- package/dist/mparticle.js +169 -134
- package/package.json +4 -4
- package/src/apiClient.js +15 -5
- package/src/cookieSyncManager.js +7 -6
- package/src/events.js +20 -11
- package/src/identity.js +1 -0
- package/src/mp-instance.js +191 -109
- package/src/mparticle-instance-manager.js +35 -13
- package/src/sdkRuntimeModels.ts +1 -0
- package/src/sdkToEventsApiConverter.ts +1 -1
- package/src/serverModel.js +3 -1
- package/CHANGELOG.md +0 -535
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.2",
|
|
4
4
|
"description": "mParticle core SDK for web applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"@semantic-release/exec": "^5.0.0",
|
|
75
75
|
"@semantic-release/git": "^9.0.0",
|
|
76
76
|
"@types/chai": "^4.2.3",
|
|
77
|
-
"@types/mocha": "^
|
|
78
|
-
"@types/node": "^
|
|
77
|
+
"@types/mocha": "^9.0.0",
|
|
78
|
+
"@types/node": "^16.0.0",
|
|
79
79
|
"babel-eslint": "^10.0.3",
|
|
80
80
|
"babel-preset-minify": "^0.5.1",
|
|
81
81
|
"browser-sync": "^2.26.3",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"cross-env": "^7.0.3",
|
|
85
85
|
"eslint": "^7.25.0",
|
|
86
86
|
"eslint-config-prettier": "8.3.0",
|
|
87
|
-
"eslint-plugin-prettier": "3.4.
|
|
87
|
+
"eslint-plugin-prettier": "3.4.1",
|
|
88
88
|
"fetch-mock": "^7.5.1",
|
|
89
89
|
"gts": "^3.1.0",
|
|
90
90
|
"karma": "^6.3.2",
|
package/src/apiClient.js
CHANGED
|
@@ -59,7 +59,12 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
this.sendEventToServer = function(event) {
|
|
62
|
+
this.sendEventToServer = function(event, _options) {
|
|
63
|
+
var defaultOptions = {
|
|
64
|
+
shouldUploadEvent: true,
|
|
65
|
+
};
|
|
66
|
+
var options = mpInstance._Helpers.extend(defaultOptions, _options);
|
|
67
|
+
|
|
63
68
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
64
69
|
mpInstance._NativeSdkHelpers.sendToNative(
|
|
65
70
|
Constants.NativeSdkPaths.LogEvent,
|
|
@@ -94,16 +99,21 @@ export default function APIClient(mpInstance, kitBlocker) {
|
|
|
94
99
|
|
|
95
100
|
this.processQueuedEvents();
|
|
96
101
|
|
|
97
|
-
if (
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
if (event && options.shouldUploadEvent) {
|
|
103
|
+
if (this.shouldEnableBatching()) {
|
|
104
|
+
this.queueEventForBatchUpload(event);
|
|
105
|
+
} else {
|
|
106
|
+
this.sendSingleEventToServer(event);
|
|
107
|
+
}
|
|
101
108
|
}
|
|
102
109
|
|
|
103
110
|
if (event && event.EventName !== Types.MessageType.AppStateTransition) {
|
|
104
111
|
if (kitBlocker && kitBlocker.kitBlockingEnabled) {
|
|
105
112
|
event = kitBlocker.createBlockedEvent(event);
|
|
106
113
|
}
|
|
114
|
+
|
|
115
|
+
// We need to check event again, because kitblocking
|
|
116
|
+
// can nullify the event
|
|
107
117
|
if (event) {
|
|
108
118
|
mpInstance._Forwarders.sendEventToForwarders(event);
|
|
109
119
|
}
|
package/src/cookieSyncManager.js
CHANGED
|
@@ -144,13 +144,14 @@ export default function cookieSyncManager(mpInstance) {
|
|
|
144
144
|
var img = document.createElement('img');
|
|
145
145
|
|
|
146
146
|
mpInstance.Logger.verbose(Messages.InformationMessages.CookieSync);
|
|
147
|
-
|
|
147
|
+
img.onload = function() {
|
|
148
|
+
cookieSyncDates[moduleId.toString()] = new Date().getTime();
|
|
149
|
+
mpInstance._Persistence.saveUserCookieSyncDatesToPersistence(
|
|
150
|
+
mpid,
|
|
151
|
+
cookieSyncDates
|
|
152
|
+
);
|
|
153
|
+
};
|
|
148
154
|
img.src = url;
|
|
149
|
-
cookieSyncDates[moduleId.toString()] = new Date().getTime();
|
|
150
|
-
mpInstance._Persistence.saveUserCookieSyncDatesToPersistence(
|
|
151
|
-
mpid,
|
|
152
|
-
cookieSyncDates
|
|
153
|
-
);
|
|
154
155
|
}
|
|
155
156
|
};
|
|
156
157
|
}
|
package/src/events.js
CHANGED
|
@@ -5,13 +5,13 @@ var Messages = Constants.Messages;
|
|
|
5
5
|
|
|
6
6
|
export default function Events(mpInstance) {
|
|
7
7
|
var self = this;
|
|
8
|
-
this.logEvent = function(event) {
|
|
8
|
+
this.logEvent = function(event, options) {
|
|
9
9
|
mpInstance.Logger.verbose(
|
|
10
10
|
Messages.InformationMessages.StartingLogEvent + ': ' + event.name
|
|
11
11
|
);
|
|
12
12
|
if (mpInstance._Helpers.canLog()) {
|
|
13
13
|
var uploadObject = mpInstance._ServerModel.createEventObject(event);
|
|
14
|
-
mpInstance._APIClient.sendEventToServer(uploadObject);
|
|
14
|
+
mpInstance._APIClient.sendEventToServer(uploadObject, options);
|
|
15
15
|
} else {
|
|
16
16
|
mpInstance.Logger.verbose(
|
|
17
17
|
Messages.InformationMessages.AbandonLogEvent
|
|
@@ -125,7 +125,8 @@ export default function Events(mpInstance) {
|
|
|
125
125
|
product,
|
|
126
126
|
customAttrs,
|
|
127
127
|
customFlags,
|
|
128
|
-
transactionAttributes
|
|
128
|
+
transactionAttributes,
|
|
129
|
+
options
|
|
129
130
|
) {
|
|
130
131
|
var event = mpInstance._Ecommerce.createCommerceEventObject(
|
|
131
132
|
customFlags
|
|
@@ -179,7 +180,7 @@ export default function Events(mpInstance) {
|
|
|
179
180
|
);
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
self.logCommerceEvent(event, customAttrs);
|
|
183
|
+
self.logCommerceEvent(event, customAttrs, options);
|
|
183
184
|
}
|
|
184
185
|
};
|
|
185
186
|
|
|
@@ -256,7 +257,8 @@ export default function Events(mpInstance) {
|
|
|
256
257
|
promotionType,
|
|
257
258
|
promotion,
|
|
258
259
|
attrs,
|
|
259
|
-
customFlags
|
|
260
|
+
customFlags,
|
|
261
|
+
eventOptions
|
|
260
262
|
) {
|
|
261
263
|
var event = mpInstance._Ecommerce.createCommerceEventObject(
|
|
262
264
|
customFlags
|
|
@@ -271,14 +273,21 @@ export default function Events(mpInstance) {
|
|
|
271
273
|
);
|
|
272
274
|
event.PromotionAction = {
|
|
273
275
|
PromotionActionType: promotionType,
|
|
274
|
-
PromotionList:
|
|
276
|
+
PromotionList: Array.isArray(promotion)
|
|
277
|
+
? promotion
|
|
278
|
+
: [promotion],
|
|
275
279
|
};
|
|
276
280
|
|
|
277
|
-
self.logCommerceEvent(event, attrs);
|
|
281
|
+
self.logCommerceEvent(event, attrs, eventOptions);
|
|
278
282
|
}
|
|
279
283
|
};
|
|
280
284
|
|
|
281
|
-
this.logImpressionEvent = function(
|
|
285
|
+
this.logImpressionEvent = function(
|
|
286
|
+
impression,
|
|
287
|
+
attrs,
|
|
288
|
+
customFlags,
|
|
289
|
+
options
|
|
290
|
+
) {
|
|
282
291
|
var event = mpInstance._Ecommerce.createCommerceEventObject(
|
|
283
292
|
customFlags
|
|
284
293
|
);
|
|
@@ -301,11 +310,11 @@ export default function Events(mpInstance) {
|
|
|
301
310
|
});
|
|
302
311
|
});
|
|
303
312
|
|
|
304
|
-
self.logCommerceEvent(event, attrs);
|
|
313
|
+
self.logCommerceEvent(event, attrs, options);
|
|
305
314
|
}
|
|
306
315
|
};
|
|
307
316
|
|
|
308
|
-
this.logCommerceEvent = function(commerceEvent, attrs) {
|
|
317
|
+
this.logCommerceEvent = function(commerceEvent, attrs, options) {
|
|
309
318
|
mpInstance.Logger.verbose(
|
|
310
319
|
Messages.InformationMessages.StartingLogCommerceEvent
|
|
311
320
|
);
|
|
@@ -325,7 +334,7 @@ export default function Events(mpInstance) {
|
|
|
325
334
|
commerceEvent.EventAttributes = attrs;
|
|
326
335
|
}
|
|
327
336
|
|
|
328
|
-
mpInstance._APIClient.sendEventToServer(commerceEvent);
|
|
337
|
+
mpInstance._APIClient.sendEventToServer(commerceEvent, options);
|
|
329
338
|
mpInstance._Persistence.update();
|
|
330
339
|
} else {
|
|
331
340
|
mpInstance.Logger.verbose(
|
package/src/identity.js
CHANGED
|
@@ -192,6 +192,7 @@ export default function Identity(mpInstance) {
|
|
|
192
192
|
source_mpid: aliasRequest.sourceMpid,
|
|
193
193
|
start_unixtime_ms: aliasRequest.startTime,
|
|
194
194
|
end_unixtime_ms: aliasRequest.endTime,
|
|
195
|
+
scope: aliasRequest.scope,
|
|
195
196
|
device_application_stamp: mpInstance._Store.deviceId,
|
|
196
197
|
},
|
|
197
198
|
};
|
package/src/mp-instance.js
CHANGED
|
@@ -143,9 +143,13 @@ export default function mParticleInstance(instanceName) {
|
|
|
143
143
|
* @method reset
|
|
144
144
|
*/
|
|
145
145
|
this.reset = function(instance) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
try {
|
|
147
|
+
instance._Persistence.resetPersistence();
|
|
148
|
+
if (instance._Store) {
|
|
149
|
+
delete instance._Store;
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error('Cannot reset mParticle', error);
|
|
149
153
|
}
|
|
150
154
|
};
|
|
151
155
|
|
|
@@ -177,7 +181,7 @@ export default function mParticleInstance(instanceName) {
|
|
|
177
181
|
* @param {Function} function A function to be called after mParticle is initialized
|
|
178
182
|
*/
|
|
179
183
|
this.ready = function(f) {
|
|
180
|
-
if (self.
|
|
184
|
+
if (self.isInitialized() && typeof f === 'function') {
|
|
181
185
|
f();
|
|
182
186
|
} else {
|
|
183
187
|
self._preInit.readyQueue.push(f);
|
|
@@ -197,6 +201,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
197
201
|
* @param {String} version version number
|
|
198
202
|
*/
|
|
199
203
|
this.setAppVersion = function(version) {
|
|
204
|
+
var queued = queueIfNotInitialized(function() {
|
|
205
|
+
self.setAppVersion(version);
|
|
206
|
+
}, self);
|
|
207
|
+
|
|
208
|
+
if (queued) return;
|
|
209
|
+
|
|
200
210
|
self._Store.SDKConfig.appVersion = version;
|
|
201
211
|
self._Persistence.update();
|
|
202
212
|
};
|
|
@@ -214,6 +224,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
214
224
|
* @param {String} name App Name
|
|
215
225
|
*/
|
|
216
226
|
this.setAppName = function(name) {
|
|
227
|
+
var queued = queueIfNotInitialized(function() {
|
|
228
|
+
self.setAppName(name);
|
|
229
|
+
}, self);
|
|
230
|
+
|
|
231
|
+
if (queued) return;
|
|
232
|
+
|
|
217
233
|
self._Store.SDKConfig.appName = name;
|
|
218
234
|
};
|
|
219
235
|
/**
|
|
@@ -254,6 +270,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
254
270
|
* @param {Number} longitude longitude digit
|
|
255
271
|
*/
|
|
256
272
|
this.setPosition = function(lat, lng) {
|
|
273
|
+
var queued = queueIfNotInitialized(function() {
|
|
274
|
+
self.setPosition(lat, lng);
|
|
275
|
+
}, self);
|
|
276
|
+
|
|
277
|
+
if (queued) return;
|
|
278
|
+
|
|
257
279
|
self._SessionManager.resetSessionTimer();
|
|
258
280
|
if (typeof lat === 'number' && typeof lng === 'number') {
|
|
259
281
|
self._Store.currentPosition = {
|
|
@@ -285,14 +307,15 @@ export default function mParticleInstance(instanceName) {
|
|
|
285
307
|
/**
|
|
286
308
|
* Logs a Base Event to mParticle's servers
|
|
287
309
|
* @param {Object} event Base Event Object
|
|
310
|
+
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
288
311
|
*/
|
|
289
|
-
this.logBaseEvent = function(event) {
|
|
290
|
-
|
|
291
|
-
self.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
312
|
+
this.logBaseEvent = function(event, eventOptions) {
|
|
313
|
+
var queued = queueIfNotInitialized(function() {
|
|
314
|
+
self.logBaseEvent(event, eventOptions);
|
|
315
|
+
}, self);
|
|
316
|
+
|
|
317
|
+
if (queued) return;
|
|
318
|
+
|
|
296
319
|
self._SessionManager.resetSessionTimer();
|
|
297
320
|
if (typeof event.name !== 'string') {
|
|
298
321
|
self.Logger.error(Messages.ErrorMessages.EventNameInvalidType);
|
|
@@ -308,7 +331,7 @@ export default function mParticleInstance(instanceName) {
|
|
|
308
331
|
return;
|
|
309
332
|
}
|
|
310
333
|
|
|
311
|
-
self._Events.logEvent(event);
|
|
334
|
+
self._Events.logEvent(event, eventOptions);
|
|
312
335
|
};
|
|
313
336
|
/**
|
|
314
337
|
* Logs an event to mParticle's servers
|
|
@@ -317,14 +340,27 @@ export default function mParticleInstance(instanceName) {
|
|
|
317
340
|
* @param {Number} [eventType] The eventType as seen [here](http://docs.mparticle.com/developers/sdk/web/event-tracking#event-type)
|
|
318
341
|
* @param {Object} [eventInfo] Attributes for the event
|
|
319
342
|
* @param {Object} [customFlags] Additional customFlags
|
|
343
|
+
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
320
344
|
*/
|
|
321
|
-
this.logEvent = function(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
345
|
+
this.logEvent = function(
|
|
346
|
+
eventName,
|
|
347
|
+
eventType,
|
|
348
|
+
eventInfo,
|
|
349
|
+
customFlags,
|
|
350
|
+
eventOptions
|
|
351
|
+
) {
|
|
352
|
+
var queued = queueIfNotInitialized(function() {
|
|
353
|
+
self.logEvent(
|
|
354
|
+
eventName,
|
|
355
|
+
eventType,
|
|
356
|
+
eventInfo,
|
|
357
|
+
customFlags,
|
|
358
|
+
eventOptions
|
|
359
|
+
);
|
|
360
|
+
}, self);
|
|
361
|
+
|
|
362
|
+
if (queued) return;
|
|
363
|
+
|
|
328
364
|
self._SessionManager.resetSessionTimer();
|
|
329
365
|
if (typeof eventName !== 'string') {
|
|
330
366
|
self.Logger.error(Messages.ErrorMessages.EventNameInvalidType);
|
|
@@ -350,13 +386,16 @@ export default function mParticleInstance(instanceName) {
|
|
|
350
386
|
return;
|
|
351
387
|
}
|
|
352
388
|
|
|
353
|
-
self._Events.logEvent(
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
389
|
+
self._Events.logEvent(
|
|
390
|
+
{
|
|
391
|
+
messageType: Types.MessageType.PageEvent,
|
|
392
|
+
name: eventName,
|
|
393
|
+
data: eventInfo,
|
|
394
|
+
eventType: eventType,
|
|
395
|
+
customFlags: customFlags,
|
|
396
|
+
},
|
|
397
|
+
eventOptions
|
|
398
|
+
);
|
|
360
399
|
};
|
|
361
400
|
/**
|
|
362
401
|
* Used to log custom errors
|
|
@@ -366,12 +405,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
366
405
|
* @param {Object} [attrs] Custom attrs to be passed along with the error event; values must be string, number, or boolean
|
|
367
406
|
*/
|
|
368
407
|
this.logError = function(error, attrs) {
|
|
369
|
-
|
|
370
|
-
self.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
408
|
+
var queued = queueIfNotInitialized(function() {
|
|
409
|
+
self.logError(error, attrs);
|
|
410
|
+
}, self);
|
|
411
|
+
|
|
412
|
+
if (queued) return;
|
|
413
|
+
|
|
375
414
|
self._SessionManager.resetSessionTimer();
|
|
376
415
|
if (!error) {
|
|
377
416
|
return;
|
|
@@ -443,14 +482,15 @@ export default function mParticleInstance(instanceName) {
|
|
|
443
482
|
* @param {String} eventName The name of the event. Defaults to 'PageView'.
|
|
444
483
|
* @param {Object} [attrs] Attributes for the event
|
|
445
484
|
* @param {Object} [customFlags] Custom flags for the event
|
|
485
|
+
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
446
486
|
*/
|
|
447
|
-
this.logPageView = function(eventName, attrs, customFlags) {
|
|
448
|
-
|
|
449
|
-
self.
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
487
|
+
this.logPageView = function(eventName, attrs, customFlags, eventOptions) {
|
|
488
|
+
var queued = queueIfNotInitialized(function() {
|
|
489
|
+
self.logPageView(eventName, attrs, customFlags, eventOptions);
|
|
490
|
+
}, self);
|
|
491
|
+
|
|
492
|
+
if (queued) return;
|
|
493
|
+
|
|
454
494
|
self._SessionManager.resetSessionTimer();
|
|
455
495
|
|
|
456
496
|
if (self._Helpers.canLog()) {
|
|
@@ -480,13 +520,16 @@ export default function mParticleInstance(instanceName) {
|
|
|
480
520
|
}
|
|
481
521
|
}
|
|
482
522
|
|
|
483
|
-
self._Events.logEvent(
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
523
|
+
self._Events.logEvent(
|
|
524
|
+
{
|
|
525
|
+
messageType: Types.MessageType.PageView,
|
|
526
|
+
name: eventName,
|
|
527
|
+
data: attrs,
|
|
528
|
+
eventType: Types.EventType.Unknown,
|
|
529
|
+
customFlags: customFlags,
|
|
530
|
+
},
|
|
531
|
+
eventOptions
|
|
532
|
+
);
|
|
490
533
|
};
|
|
491
534
|
/**
|
|
492
535
|
* Forces an upload of the batch
|
|
@@ -619,12 +662,11 @@ export default function mParticleInstance(instanceName) {
|
|
|
619
662
|
* @param {String} code The currency code
|
|
620
663
|
*/
|
|
621
664
|
setCurrencyCode: function(code) {
|
|
622
|
-
|
|
623
|
-
self.
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
}
|
|
665
|
+
var queued = queueIfNotInitialized(function() {
|
|
666
|
+
self.eCommerce.setCurrencyCode(code);
|
|
667
|
+
}, self);
|
|
668
|
+
|
|
669
|
+
if (queued) return;
|
|
628
670
|
|
|
629
671
|
if (typeof code !== 'string') {
|
|
630
672
|
self.Logger.error('Code must be a string');
|
|
@@ -742,6 +784,7 @@ export default function mParticleInstance(instanceName) {
|
|
|
742
784
|
self.Logger.warning(
|
|
743
785
|
'mParticle.logCheckout is deprecated, please use mParticle.logProductAction instead'
|
|
744
786
|
);
|
|
787
|
+
|
|
745
788
|
if (!self._Store.isInitialized) {
|
|
746
789
|
self.ready(function() {
|
|
747
790
|
self.eCommerce.logCheckout(
|
|
@@ -751,8 +794,10 @@ export default function mParticleInstance(instanceName) {
|
|
|
751
794
|
customFlags
|
|
752
795
|
);
|
|
753
796
|
});
|
|
797
|
+
|
|
754
798
|
return;
|
|
755
799
|
}
|
|
800
|
+
|
|
756
801
|
self._SessionManager.resetSessionTimer();
|
|
757
802
|
self._Events.logCheckoutEvent(step, option, attrs, customFlags);
|
|
758
803
|
},
|
|
@@ -765,33 +810,37 @@ export default function mParticleInstance(instanceName) {
|
|
|
765
810
|
* @param {Object} [attrs] attributes related to the product action
|
|
766
811
|
* @param {Object} [customFlags] Custom flags for the event
|
|
767
812
|
* @param {Object} [transactionAttributes] Transaction Attributes for the event
|
|
813
|
+
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
768
814
|
*/
|
|
769
815
|
logProductAction: function(
|
|
770
816
|
productActionType,
|
|
771
817
|
product,
|
|
772
818
|
attrs,
|
|
773
819
|
customFlags,
|
|
774
|
-
transactionAttributes
|
|
820
|
+
transactionAttributes,
|
|
821
|
+
eventOptions
|
|
775
822
|
) {
|
|
776
|
-
|
|
777
|
-
self.
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
823
|
+
var queued = queueIfNotInitialized(function() {
|
|
824
|
+
self.eCommerce.logProductAction(
|
|
825
|
+
productActionType,
|
|
826
|
+
product,
|
|
827
|
+
attrs,
|
|
828
|
+
customFlags,
|
|
829
|
+
transactionAttributes,
|
|
830
|
+
eventOptions
|
|
831
|
+
);
|
|
832
|
+
}, self);
|
|
833
|
+
|
|
834
|
+
if (queued) return;
|
|
835
|
+
|
|
788
836
|
self._SessionManager.resetSessionTimer();
|
|
789
837
|
self._Events.logProductActionEvent(
|
|
790
838
|
productActionType,
|
|
791
839
|
product,
|
|
792
840
|
attrs,
|
|
793
841
|
customFlags,
|
|
794
|
-
transactionAttributes
|
|
842
|
+
transactionAttributes,
|
|
843
|
+
eventOptions
|
|
795
844
|
);
|
|
796
845
|
},
|
|
797
846
|
/**
|
|
@@ -847,21 +896,35 @@ export default function mParticleInstance(instanceName) {
|
|
|
847
896
|
* @param {Object} promotion promotion object
|
|
848
897
|
* @param {Object} [attrs] boolean to clear the cart after logging or not
|
|
849
898
|
* @param {Object} [customFlags] Custom flags for the event
|
|
899
|
+
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
850
900
|
*/
|
|
851
|
-
logPromotion: function(
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
901
|
+
logPromotion: function(
|
|
902
|
+
type,
|
|
903
|
+
promotion,
|
|
904
|
+
attrs,
|
|
905
|
+
customFlags,
|
|
906
|
+
eventOptions
|
|
907
|
+
) {
|
|
908
|
+
var queued = queueIfNotInitialized(function() {
|
|
909
|
+
self.eCommerce.logPromotion(
|
|
910
|
+
type,
|
|
911
|
+
promotion,
|
|
912
|
+
attrs,
|
|
913
|
+
customFlags,
|
|
914
|
+
eventOptions
|
|
915
|
+
);
|
|
916
|
+
}, self);
|
|
917
|
+
|
|
918
|
+
if (queued) return;
|
|
919
|
+
|
|
863
920
|
self._SessionManager.resetSessionTimer();
|
|
864
|
-
self._Events.logPromotionEvent(
|
|
921
|
+
self._Events.logPromotionEvent(
|
|
922
|
+
type,
|
|
923
|
+
promotion,
|
|
924
|
+
attrs,
|
|
925
|
+
customFlags,
|
|
926
|
+
eventOptions
|
|
927
|
+
);
|
|
865
928
|
},
|
|
866
929
|
/**
|
|
867
930
|
* Logs a product impression
|
|
@@ -870,20 +933,27 @@ export default function mParticleInstance(instanceName) {
|
|
|
870
933
|
* @param {Object} impression product impression object
|
|
871
934
|
* @param {Object} attrs attributes related to the impression log
|
|
872
935
|
* @param {Object} [customFlags] Custom flags for the event
|
|
936
|
+
* @param {Object} [eventOptions] For Event-level Configuration Options
|
|
873
937
|
*/
|
|
874
|
-
logImpression: function(impression, attrs, customFlags) {
|
|
875
|
-
|
|
876
|
-
self.
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
938
|
+
logImpression: function(impression, attrs, customFlags, eventOptions) {
|
|
939
|
+
var queued = queueIfNotInitialized(function() {
|
|
940
|
+
self.eCommerce.logImpression(
|
|
941
|
+
impression,
|
|
942
|
+
attrs,
|
|
943
|
+
customFlags,
|
|
944
|
+
eventOptions
|
|
945
|
+
);
|
|
946
|
+
}, self);
|
|
947
|
+
|
|
948
|
+
if (queued) return;
|
|
949
|
+
|
|
885
950
|
self._SessionManager.resetSessionTimer();
|
|
886
|
-
self._Events.logImpressionEvent(
|
|
951
|
+
self._Events.logImpressionEvent(
|
|
952
|
+
impression,
|
|
953
|
+
attrs,
|
|
954
|
+
customFlags,
|
|
955
|
+
eventOptions
|
|
956
|
+
);
|
|
887
957
|
},
|
|
888
958
|
/**
|
|
889
959
|
* Logs a refund
|
|
@@ -937,12 +1007,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
937
1007
|
* @param {String or Number} value value for session attribute
|
|
938
1008
|
*/
|
|
939
1009
|
this.setSessionAttribute = function(key, value) {
|
|
940
|
-
|
|
941
|
-
self.
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
1010
|
+
var queued = queueIfNotInitialized(function() {
|
|
1011
|
+
self.setSessionAttribute(key, value);
|
|
1012
|
+
}, self);
|
|
1013
|
+
|
|
1014
|
+
if (queued) return;
|
|
1015
|
+
|
|
946
1016
|
// Logs to cookie
|
|
947
1017
|
// And logs to in-memory object
|
|
948
1018
|
// Example: mParticle.setSessionAttribute('location', '33431');
|
|
@@ -988,12 +1058,12 @@ export default function mParticleInstance(instanceName) {
|
|
|
988
1058
|
* @param {Boolean} isOptingOut boolean to opt out or not. When set to true, opt out of logging.
|
|
989
1059
|
*/
|
|
990
1060
|
this.setOptOut = function(isOptingOut) {
|
|
991
|
-
|
|
992
|
-
self.
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1061
|
+
var queued = queueIfNotInitialized(function() {
|
|
1062
|
+
self.setOptOut(isOptingOut);
|
|
1063
|
+
}, self);
|
|
1064
|
+
|
|
1065
|
+
if (queued) return;
|
|
1066
|
+
|
|
997
1067
|
self._SessionManager.resetSessionTimer();
|
|
998
1068
|
self._Store.isEnabled = !isOptingOut;
|
|
999
1069
|
|
|
@@ -1026,12 +1096,11 @@ export default function mParticleInstance(instanceName) {
|
|
|
1026
1096
|
* also pass a null or empty map here to remove all of the attributes.
|
|
1027
1097
|
*/
|
|
1028
1098
|
this.setIntegrationAttribute = function(integrationId, attrs) {
|
|
1029
|
-
|
|
1030
|
-
self.
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
}
|
|
1099
|
+
var queued = queueIfNotInitialized(function() {
|
|
1100
|
+
self.setIntegrationAttribute(integrationId, attrs);
|
|
1101
|
+
}, self);
|
|
1102
|
+
|
|
1103
|
+
if (queued) return;
|
|
1035
1104
|
|
|
1036
1105
|
if (typeof integrationId !== 'number') {
|
|
1037
1106
|
self.Logger.error('integrationId must be a number');
|
|
@@ -1117,6 +1186,9 @@ export default function mParticleInstance(instanceName) {
|
|
|
1117
1186
|
this._setIntegrationDelay = function(module, boolean) {
|
|
1118
1187
|
self._preInit.integrationDelays[module] = boolean;
|
|
1119
1188
|
};
|
|
1189
|
+
this.isInitialized = function() {
|
|
1190
|
+
return self._Store ? self._Store.isInitialized : false;
|
|
1191
|
+
};
|
|
1120
1192
|
}
|
|
1121
1193
|
|
|
1122
1194
|
// Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
|
|
@@ -1418,3 +1490,13 @@ function processPreloadedItem(readyQueueItem, mpInstance) {
|
|
|
1418
1490
|
}
|
|
1419
1491
|
}
|
|
1420
1492
|
}
|
|
1493
|
+
|
|
1494
|
+
function queueIfNotInitialized(func, self) {
|
|
1495
|
+
if (!self.isInitialized()) {
|
|
1496
|
+
self.ready(function() {
|
|
1497
|
+
func();
|
|
1498
|
+
});
|
|
1499
|
+
return true;
|
|
1500
|
+
}
|
|
1501
|
+
return false;
|
|
1502
|
+
}
|