@mparticle/web-sdk 2.32.5 → 2.33.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.
@@ -48,6 +48,7 @@ import { IEvents } from './events.interfaces';
48
48
  import { IECommerce } from './ecommerce.interfaces';
49
49
  import { INativeSdkHelpers } from './nativeSdkHelpers.interfaces';
50
50
  import { IPersistence } from './persistence.interfaces';
51
+ import ForegroundTimer from './foregroundTimeTracker';
51
52
 
52
53
  export interface IErrorLogMessage {
53
54
  message?: string;
@@ -84,6 +85,7 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
84
85
  _Store: IStore;
85
86
  _instanceName: string;
86
87
  _preInit: IPreInit;
88
+ _timeOnSiteTimer: ForegroundTimer;
87
89
  }
88
90
 
89
91
  const { Messages, HTTPCodes, FeatureFlags } = Constants;
@@ -79,7 +79,9 @@ export interface SDKEvent {
79
79
  DataPlan?: SDKDataPlan;
80
80
  LaunchReferral?: string;
81
81
  ExpandedEventCount: number;
82
+ ActiveTimeOnSite: number;
82
83
  }
84
+
83
85
  export interface SDKGeoLocation {
84
86
  lat: number | string;
85
87
  lng: number | string;
@@ -658,6 +658,7 @@ export function convertBaseEventData(
658
658
  custom_attributes: sdkEvent.EventAttributes,
659
659
  location: convertSDKLocation(sdkEvent.Location),
660
660
  source_message_id: sdkEvent.SourceMessageId,
661
+ active_time_on_site_ms: sdkEvent.ActiveTimeOnSite
661
662
  };
662
663
 
663
664
  return commonEventData;
@@ -17,7 +17,7 @@ import {
17
17
  Dictionary,
18
18
  isValidCustomFlagProperty,
19
19
  } from './utils';
20
- import { ServerSettings } from './store';
20
+ import { IntegrationAttributes, ServerSettings } from './store';
21
21
  import { MPID } from '@mparticle/web-sdk';
22
22
  import {
23
23
  IConsentStateV2DTO,
@@ -319,6 +319,7 @@ export default function ServerModel(
319
319
  mpInstance._Store.webviewBridgeEnabled
320
320
  ) {
321
321
  let customFlags: SDKEventCustomFlags = {...event.customFlags};
322
+ let integrationAttributes: IntegrationAttributes = mpInstance._Store.integrationAttributes;
322
323
 
323
324
  // https://go.mparticle.com/work/SQDSDKS-5053
324
325
  if (mpInstance._Helpers.getFeatureFlag && mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds)) {
@@ -328,6 +329,9 @@ export default function ServerModel(
328
329
  mpInstance._IntegrationCapture.capture();
329
330
  const transformedClickIDs = mpInstance._IntegrationCapture.getClickIdsAsCustomFlags();
330
331
  customFlags = {...transformedClickIDs, ...customFlags};
332
+
333
+ const transformedIntegrationAttributes = mpInstance._IntegrationCapture.getClickIdsAsIntegrationAttributes();
334
+ integrationAttributes = {...transformedIntegrationAttributes, ...integrationAttributes};
331
335
  }
332
336
 
333
337
  if (event.hasOwnProperty('toEventAPIObject')) {
@@ -345,6 +349,7 @@ export default function ServerModel(
345
349
  event.data,
346
350
  event.name
347
351
  ),
352
+ ActiveTimeOnSite: mpInstance._timeOnSiteTimer?.getTimeInForeground(),
348
353
  SourceMessageId:
349
354
  event.sourceMessageId ||
350
355
  mpInstance._Helpers.generateUniqueId(),
@@ -377,7 +382,7 @@ export default function ServerModel(
377
382
  Package: mpInstance._Store.SDKConfig.package,
378
383
  ClientGeneratedId: mpInstance._Store.clientId,
379
384
  DeviceId: mpInstance._Store.deviceId,
380
- IntegrationAttributes: mpInstance._Store.integrationAttributes,
385
+ IntegrationAttributes: integrationAttributes,
381
386
  CurrencyCode: mpInstance._Store.currencyCode,
382
387
  DataPlan: mpInstance._Store.SDKConfig.dataPlan
383
388
  ? mpInstance._Store.SDKConfig.dataPlan
@@ -132,17 +132,20 @@ export default function SessionManager(
132
132
  });
133
133
 
134
134
  mpInstance._Store.nullifySession();
135
+ mpInstance._timeOnSiteTimer?.resetTimer();
135
136
  return;
136
137
  }
137
138
 
138
139
  if (!mpInstance._Helpers.canLog()) {
139
- // At this moment, an AbandonedEndSession is defined when on of three things occurs:
140
+ // At this moment, an AbandonedEndSession is defined when one of three things occurs:
140
141
  // - the SDK's store is not enabled because mParticle.setOptOut was called
141
142
  // - the devToken is undefined
142
143
  // - webviewBridgeEnabled is set to false
143
144
  mpInstance.Logger.verbose(
144
145
  Messages.InformationMessages.AbandonEndSession
145
146
  );
147
+ mpInstance._timeOnSiteTimer?.resetTimer();
148
+
146
149
  return;
147
150
  }
148
151
 
@@ -155,6 +158,8 @@ export default function SessionManager(
155
158
  mpInstance.Logger.verbose(
156
159
  Messages.InformationMessages.NoSessionToEnd
157
160
  );
161
+ mpInstance._timeOnSiteTimer?.resetTimer();
162
+
158
163
  return;
159
164
  }
160
165
 
@@ -180,6 +185,8 @@ export default function SessionManager(
180
185
  mpInstance._Store.nullifySession();
181
186
  }
182
187
  }
188
+
189
+ mpInstance._timeOnSiteTimer?.resetTimer();
183
190
  };
184
191
 
185
192
  this.setSessionTimer = function(): void {
package/src/store.ts CHANGED
@@ -38,6 +38,7 @@ import {
38
38
  } from './persistence.interfaces';
39
39
  import { CookieSyncDates, IPixelConfiguration } from './cookieSyncManager';
40
40
  import { IMParticleWebSDKInstance } from './mp-instance';
41
+ import ForegroundTimer from './foregroundTimeTracker';
41
42
 
42
43
  // This represents the runtime configuration of the SDK AFTER
43
44
  // initialization has been complete and all settings and
@@ -680,6 +681,7 @@ export default function Store(
680
681
 
681
682
  if (workspaceToken) {
682
683
  this.SDKConfig.workspaceToken = workspaceToken;
684
+ mpInstance._timeOnSiteTimer = new ForegroundTimer(workspaceToken);
683
685
  } else {
684
686
  mpInstance.Logger.warning(
685
687
  'You should have a workspaceToken on your config object for security purposes.'
package/src/utils.ts CHANGED
@@ -292,14 +292,19 @@ interface URLSearchParamsFallback {
292
292
  }
293
293
 
294
294
  const queryStringParserFallback = (url: string): URLSearchParamsFallback => {
295
- let params: Dictionary<string> = {};
295
+ const params: Dictionary<string> = {};
296
296
  const queryString = url.split('?')[1] || '';
297
297
  const pairs = queryString.split('&');
298
298
 
299
299
  pairs.forEach(pair => {
300
- var [key, value] = pair.split('=');
301
- if (key && value) {
302
- params[key] = decodeURIComponent(value || '');
300
+ const [key, ...valueParts] = pair.split('=');
301
+ const value = valueParts.join('=');
302
+ if (key && value !== undefined) {
303
+ try {
304
+ params[key] = decodeURIComponent(value || '');
305
+ } catch (e) {
306
+ console.error(`Failed to decode value for key ${key}: ${e}`);
307
+ }
303
308
  }
304
309
  });
305
310