@mparticle/web-sdk 2.72.0 → 2.73.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.
@@ -10,6 +10,7 @@ import {
10
10
  AttributeValue,
11
11
  isEmpty,
12
12
  obfuscateDevData,
13
+ getErrorMessage,
13
14
  } from "./utils";
14
15
  import { SDKIdentityApi } from "./identity.interfaces";
15
16
  import { SDKLoggerApi } from "./sdkRuntimeModels";
@@ -18,6 +19,10 @@ import { UserIdentities } from "@mparticle/web-sdk";
18
19
  import { IdentityType, PerformanceMarkType } from "./types";
19
20
  import { ErrorCodes, IErrorReportingService, ILoggingService, WSDKErrorSeverity } from "./reporting/types";
20
21
  import { IRoktLauncherOptions, normalizeRoktLauncherOptions } from "./roktLauncherOptions";
22
+ import { PARTNER_MODULE_IDS } from "./cookieSyncManager";
23
+ import IntegrationCapture from "./integrationCapture";
24
+
25
+ const PASSBACK_CONVERSION_TRACKING_ID = 'passbackconversiontrackingid';
21
26
 
22
27
  // https://docs.rokt.com/developers/integration-guides/web/library/attributes
23
28
  export type RoktAttributeValueArray = Array<string | number | boolean>;
@@ -118,6 +123,7 @@ export default class RoktManager {
118
123
  private domain?: string;
119
124
  private mappedEmailShaIdentityType?: string | null;
120
125
  private captureTiming?: (metricsName: string) => void;
126
+ private integrationCapture?: IntegrationCapture;
121
127
  private onReadyCallback: (() => void) | null = null;
122
128
  private initialized: boolean = false;
123
129
  private isShoppableAdsLoaded: boolean = false;
@@ -152,7 +158,8 @@ export default class RoktManager {
152
158
  options?: IRoktOptions,
153
159
  captureTiming?: (metricsName: string) => void,
154
160
  errorReporter?: IErrorReportingService,
155
- loggingService?: ILoggingService
161
+ loggingService?: ILoggingService,
162
+ integrationCapture?: IntegrationCapture,
156
163
  ): void {
157
164
  const { userAttributeFilters, settings } = roktConfig || {};
158
165
  const { placementAttributesMapping, hashedEmailUserIdentityType } = settings || {};
@@ -164,6 +171,7 @@ export default class RoktManager {
164
171
  this.errorReporter = errorReporter;
165
172
  this.loggingService = loggingService;
166
173
  this.captureTiming = captureTiming;
174
+ this.integrationCapture = integrationCapture;
167
175
 
168
176
  this.captureTiming?.(PerformanceMarkType.JointSdkRoktKitInit);
169
177
 
@@ -216,11 +224,6 @@ export default class RoktManager {
216
224
  this.store?.setIntegrationName(kit.integrationName);
217
225
  }
218
226
 
219
- this.loggingService?.log({
220
- message: 'RoktManager: Kit attached, Rokt is ready',
221
- code: ErrorCodes.ROKT_KIT_ATTACHED,
222
- });
223
-
224
227
  this.processMessageQueue();
225
228
 
226
229
  try {
@@ -336,8 +339,10 @@ export default class RoktManager {
336
339
  }
337
340
  );
338
341
  } catch (error) {
339
- const errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
340
- this.logger.error('Background identify threw an error: ' + errorMessage);
342
+ this.logger.error(
343
+ 'Background identify threw an error: ' +
344
+ getErrorMessage(error)
345
+ );
341
346
  }
342
347
  }
343
348
 
@@ -371,6 +376,15 @@ export default class RoktManager {
371
376
  }
372
377
  }
373
378
 
379
+ if (!enrichedAttributes[PASSBACK_CONVERSION_TRACKING_ID]) {
380
+ this.integrationCapture?.capture();
381
+ const capturedAttrs = this.integrationCapture?.getClickIdsAsIntegrationAttributes();
382
+ const passbackId = capturedAttrs?.[PARTNER_MODULE_IDS.Rokt]?.[PASSBACK_CONVERSION_TRACKING_ID];
383
+ if (passbackId) {
384
+ enrichedAttributes[PASSBACK_CONVERSION_TRACKING_ID] = passbackId;
385
+ }
386
+ }
387
+
374
388
  this.filters.filteredUser = this.currentUser || this.filters.filteredUser || null;
375
389
 
376
390
  const enrichedOptions = {
@@ -426,8 +440,9 @@ export default class RoktManager {
426
440
  return hashedAttributes;
427
441
 
428
442
  } catch (error) {
429
- const errorMessage = error instanceof Error ? error.message : String(error);
430
- this.logger.error(`Failed to hashAttributes, returning an empty object: ${errorMessage}`);
443
+ this.logger.error(
444
+ `Failed to hashAttributes, returning an empty object: ${getErrorMessage(error)}`
445
+ );
431
446
  return {};
432
447
  }
433
448
  }
@@ -441,8 +456,9 @@ export default class RoktManager {
441
456
  try {
442
457
  this.kit.setExtensionData<T>(extensionData);
443
458
  } catch (error) {
444
- const errorMessage = error instanceof Error ? error.message : String(error);
445
- throw new Error('Error setting extension data: ' + errorMessage);
459
+ throw new Error(
460
+ 'Error setting extension data: ' + getErrorMessage(error)
461
+ );
446
462
  }
447
463
  }
448
464
 
@@ -467,8 +483,9 @@ export default class RoktManager {
467
483
  try {
468
484
  this.kit.onShoppableAdsReady(callback);
469
485
  } catch (error) {
470
- const errorMessage = error instanceof Error ? error.message : String(error);
471
- this.logger.error(`Failed to register onShoppableAdsReady callback: ${errorMessage}`);
486
+ this.logger.error(
487
+ `Failed to register onShoppableAdsReady callback: ${getErrorMessage(error)}`
488
+ );
472
489
  }
473
490
  }
474
491
 
@@ -506,8 +523,9 @@ export default class RoktManager {
506
523
  const normalizedValue = String(attribute).trim().toLocaleLowerCase();
507
524
  return await this.sha256Hex(normalizedValue);
508
525
  } catch (error) {
509
- const errorMessage = error instanceof Error ? error.message : String(error);
510
- this.logger.error(`Failed to hashSha256, returning undefined: ${errorMessage}`);
526
+ this.logger.error(
527
+ `Failed to hashSha256, returning undefined: ${getErrorMessage(error)}`
528
+ );
511
529
  return undefined;
512
530
  }
513
531
  }
@@ -596,8 +614,9 @@ export default class RoktManager {
596
614
  const reject = message.reject;
597
615
 
598
616
  const handleError = (error: unknown) => {
599
- const errorMessage = error instanceof Error ? error.message : String(error);
600
- this.logger?.error(`RoktManager: Error processing message '${message.methodName}': ${errorMessage}`);
617
+ this.logger?.error(
618
+ `RoktManager: Error processing message '${message.methodName}': ${getErrorMessage(error)}`
619
+ );
601
620
  if (reject) {
602
621
  reject(error);
603
622
  }
package/src/utils.ts CHANGED
@@ -625,6 +625,27 @@ function extend(...args: any[]): any {
625
625
  return target;
626
626
  }
627
627
 
628
+ const getErrorMessage = (
629
+ e: unknown,
630
+ fallback = 'unknown error'
631
+ ): string => {
632
+ if (e instanceof Error) {
633
+ return e.message;
634
+ }
635
+ if (typeof e === 'string') {
636
+ return e;
637
+ }
638
+ // fetch-mock and some network libs reject with { message } rather than Error
639
+ if (
640
+ e &&
641
+ typeof e === 'object' &&
642
+ typeof (e as { message?: unknown }).message === 'string'
643
+ ) {
644
+ return (e as { message: string }).message;
645
+ }
646
+ return fallback;
647
+ };
648
+
628
649
  export {
629
650
  createCookieString,
630
651
  revertCookieString,
@@ -639,6 +660,7 @@ export {
639
660
  generateDeprecationMessage,
640
661
  generateHash,
641
662
  generateUniqueId,
663
+ getErrorMessage,
642
664
  getRampNumber,
643
665
  inArray,
644
666
  isObject,