@mparticle/web-sdk 2.68.0 → 2.70.0

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.
@@ -16,7 +16,7 @@
16
16
  // Uses portions of code from jQuery
17
17
  // jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
18
18
 
19
- import { EventType, IdentityType, CommerceEventType, PromotionActionType, ProductActionType, MessageType } from './types';
19
+ import { EventType, IdentityType, CommerceEventType, PromotionActionType, ProductActionType, MessageType, RoktEvents } from './types';
20
20
  import Constants from './constants';
21
21
  import APIClient, { IAPIClient } from './apiClient';
22
22
  import Helpers from './helpers';
@@ -55,6 +55,7 @@ import CookieConsentManager, { ICookieConsentManager } from './cookieConsentMana
55
55
  import { ErrorReportingDispatcher } from './reporting/errorReportingDispatcher';
56
56
  import { LoggingDispatcher } from './reporting/loggingDispatcher';
57
57
  import { IErrorReportingService, ILoggingService } from './reporting/types';
58
+ import { logDeprecatedMethodUsage } from './reporting/deprecatedMethodLogger';
58
59
 
59
60
  export interface IErrorLogMessage {
60
61
  message?: string;
@@ -187,6 +188,7 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
187
188
  this.CommerceEventType = CommerceEventType;
188
189
  this.PromotionType = PromotionActionType;
189
190
  this.ProductActionType = ProductActionType;
191
+ this.RoktEvents = RoktEvents;
190
192
 
191
193
 
192
194
  this._Identity = new Identity(this);
@@ -772,13 +774,18 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
772
774
  * @deprecated
773
775
  */
774
776
  add: function(product, logEventBoolean) {
775
- self.Logger.warning(
776
- generateDeprecationMessage(
777
- 'eCommerce.Cart.add()',
778
- true,
779
- 'eCommerce.logProductAction()',
780
- 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
781
- )
777
+ logDeprecatedMethodUsage(
778
+ {
779
+ methodName: 'mPInstance.eCommerce.Cart.add()',
780
+ warningMessage: generateDeprecationMessage(
781
+ 'eCommerce.Cart.add()',
782
+ true,
783
+ 'eCommerce.logProductAction()',
784
+ 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
785
+ ),
786
+ },
787
+ self.Logger,
788
+ self._LoggingDispatcher
782
789
  );
783
790
  },
784
791
  /**
@@ -789,13 +796,18 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
789
796
  * @deprecated
790
797
  */
791
798
  remove: function(product, logEventBoolean) {
792
- self.Logger.warning(
793
- generateDeprecationMessage(
794
- 'eCommerce.Cart.remove()',
795
- true,
796
- 'eCommerce.logProductAction()',
797
- 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
798
- )
799
+ logDeprecatedMethodUsage(
800
+ {
801
+ methodName: 'mPInstance.eCommerce.Cart.remove()',
802
+ warningMessage: generateDeprecationMessage(
803
+ 'eCommerce.Cart.remove()',
804
+ true,
805
+ 'eCommerce.logProductAction()',
806
+ 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
807
+ ),
808
+ },
809
+ self.Logger,
810
+ self._LoggingDispatcher
799
811
  );
800
812
  },
801
813
  /**
@@ -804,13 +816,18 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
804
816
  * @deprecated
805
817
  */
806
818
  clear: function() {
807
- self.Logger.warning(
808
- generateDeprecationMessage(
809
- 'eCommerce.Cart.clear()',
810
- true,
811
- '',
812
- 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
813
- )
819
+ logDeprecatedMethodUsage(
820
+ {
821
+ methodName: 'mPInstance.eCommerce.Cart.clear()',
822
+ warningMessage: generateDeprecationMessage(
823
+ 'eCommerce.Cart.clear()',
824
+ true,
825
+ '',
826
+ 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking'
827
+ ),
828
+ },
829
+ self.Logger,
830
+ self._LoggingDispatcher
814
831
  );
815
832
  },
816
833
  },
@@ -940,8 +957,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
940
957
  * @deprecated
941
958
  */
942
959
  logCheckout: function(step, option, attrs, customFlags) {
943
- self.Logger.warning(
944
- 'mParticle.logCheckout is deprecated, please use mParticle.logProductAction instead'
960
+ logDeprecatedMethodUsage(
961
+ {
962
+ methodName: 'mParticle.logCheckout',
963
+ warningMessage: 'mParticle.logCheckout is deprecated, please use mParticle.logProductAction instead',
964
+ },
965
+ self.Logger,
966
+ self._LoggingDispatcher
945
967
  );
946
968
 
947
969
  if (!self._Store.isInitialized) {
@@ -1020,8 +1042,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
1020
1042
  attrs,
1021
1043
  customFlags
1022
1044
  ) {
1023
- self.Logger.warning(
1024
- 'mParticle.logPurchase is deprecated, please use mParticle.logProductAction instead'
1045
+ logDeprecatedMethodUsage(
1046
+ {
1047
+ methodName: 'mParticle.logPurchase',
1048
+ warningMessage: 'mParticle.logPurchase is deprecated, please use mParticle.logProductAction instead',
1049
+ },
1050
+ self.Logger,
1051
+ self._LoggingDispatcher
1025
1052
  );
1026
1053
  if (!self._Store.isInitialized) {
1027
1054
  self.ready(function() {
@@ -1132,8 +1159,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
1132
1159
  attrs,
1133
1160
  customFlags
1134
1161
  ) {
1135
- self.Logger.warning(
1136
- 'mParticle.logRefund is deprecated, please use mParticle.logProductAction instead'
1162
+ logDeprecatedMethodUsage(
1163
+ {
1164
+ methodName: 'mParticle.logRefund',
1165
+ warningMessage: 'mParticle.logRefund is deprecated, please use mParticle.logProductAction instead',
1166
+ },
1167
+ self.Logger,
1168
+ self._LoggingDispatcher
1137
1169
  );
1138
1170
  if (!self._Store.isInitialized) {
1139
1171
  self.ready(function() {
@@ -1741,4 +1773,3 @@ function queueIfNotInitialized(func, self) {
1741
1773
  });
1742
1774
  return true;
1743
1775
  }
1744
-
@@ -1,5 +1,5 @@
1
1
  import Polyfill from './polyfill';
2
- import { CommerceEventType, EventType, IdentityType, PerformanceMarkType, ProductActionType, PromotionActionType } from './types';
2
+ import { CommerceEventType, EventType, IdentityType, PerformanceMarkType, ProductActionType, PromotionActionType, RoktEvents } from './types';
3
3
  import Constants from './constants';
4
4
  import mParticleInstance, { IMParticleWebSDKInstance } from './mp-instance.js';
5
5
  import _BatchValidator from './mockBatchCreator';
@@ -36,6 +36,7 @@ function mParticleInstanceManager(this: IMParticleInstanceManager) {
36
36
  this.CommerceEventType = CommerceEventType;
37
37
  this.PromotionType = PromotionActionType;
38
38
  this.ProductActionType = ProductActionType;
39
+ this.RoktEvents = RoktEvents;
39
40
 
40
41
  this.MPSideloadedKit = MPSideloadedKit;
41
42
 
@@ -27,6 +27,8 @@ export type {
27
27
  ProductActionType,
28
28
  PromotionActionType,
29
29
  MessageType,
30
+ RoktEventName,
31
+ RoktEvents,
30
32
  } from './types';
31
33
 
32
34
  // Configuration
@@ -0,0 +1,19 @@
1
+ import { ErrorCodes, ILoggingService } from './types';
2
+ import { SDKLoggerApi } from '../sdkRuntimeModels';
3
+
4
+ interface DeprecatedMethodUsage {
5
+ methodName: string;
6
+ warningMessage: string;
7
+ }
8
+
9
+ export function logDeprecatedMethodUsage(
10
+ usage: DeprecatedMethodUsage,
11
+ logger: Pick<SDKLoggerApi, 'warning'>,
12
+ loggingDispatcher: ILoggingService | undefined
13
+ ): void {
14
+ logger.warning(usage.warningMessage);
15
+ loggingDispatcher?.log({
16
+ message: usage.methodName,
17
+ code: ErrorCodes.MP_DEPRECATED_METHOD_USAGE,
18
+ });
19
+ }
@@ -6,6 +6,7 @@ export const ErrorCodes = {
6
6
  IDENTITY_REQUEST: 'IDENTITY_REQUEST',
7
7
  IDENTITY_MISMATCH: 'IDENTITY_MISMATCH',
8
8
  ROKT_KIT_ATTACHED: 'ROKT_KIT_ATTACHED',
9
+ MP_DEPRECATED_METHOD_USAGE: 'MP_DEPRECATED_METHOD_USAGE',
9
10
  } as const;
10
11
 
11
12
  export type ErrorCodes = valueof<typeof ErrorCodes>;
@@ -39,6 +39,7 @@ import {
39
39
  IdentityType,
40
40
  ProductActionType,
41
41
  PromotionActionType,
42
+ RoktEvents,
42
43
  } from './types';
43
44
  import { IPixelConfiguration } from './cookieSyncManager';
44
45
  import _BatchValidator from './mockBatchCreator';
@@ -145,6 +146,14 @@ export enum SDKProductActionType {
145
146
  Refund = 8,
146
147
  AddToWishlist = 9,
147
148
  RemoveFromWishlist = 10,
149
+ ViewCart = 11,
150
+ AddShippingInfo = 12,
151
+ AddPaymentInfo = 13,
152
+ PaymentMethodSelected = 14,
153
+ PaymentAttempted = 15,
154
+ PaymentSucceeded = 16,
155
+ PaymentFailed = 17,
156
+ RefundInitiated = 18,
148
157
  }
149
158
 
150
159
  export interface SDKProductAction {
@@ -184,6 +193,7 @@ export interface MParticleWebSDK {
184
193
  EventType: typeof EventType;
185
194
  PromotionType: typeof PromotionActionType;
186
195
  ProductActionType: typeof ProductActionType;
196
+ RoktEvents: typeof RoktEvents;
187
197
  Identity: SDKIdentityApi;
188
198
  Logger: SDKLoggerApi;
189
199
  Consent: SDKConsentApi;
@@ -6,6 +6,7 @@ import { generateDeprecationMessage } from './utils';
6
6
  import { IMParticleUser } from './identity-user-interfaces';
7
7
  import { IMParticleWebSDKInstance } from './mp-instance';
8
8
  import { hasIdentityRequestChanged, hasExplicitIdentifier } from './identity-utils';
9
+ import { logDeprecatedMethodUsage } from './reporting/deprecatedMethodLogger';
9
10
 
10
11
  const { Messages } = Constants;
11
12
 
@@ -67,12 +68,17 @@ export default function SessionManager(
67
68
  };
68
69
 
69
70
  this.getSession = function (): string {
70
- mpInstance.Logger.warning(
71
- generateDeprecationMessage(
72
- 'SessionManager.getSession()',
73
- false,
74
- 'SessionManager.getSessionId()'
75
- )
71
+ logDeprecatedMethodUsage(
72
+ {
73
+ methodName: 'SessionManager.getSession()',
74
+ warningMessage: generateDeprecationMessage(
75
+ 'SessionManager.getSession()',
76
+ false,
77
+ 'SessionManager.getSessionId()'
78
+ ),
79
+ },
80
+ mpInstance.Logger,
81
+ mpInstance._LoggingDispatcher
76
82
  );
77
83
  return this.getSessionId();
78
84
  };
@@ -28,6 +28,7 @@ let mParticle = {
28
28
  IdentityType: {},
29
29
  ProductActionType: {},
30
30
  PromotionType: {},
31
+ RoktEvents: {},
31
32
  eCommerce: {
32
33
  createImpression: returnImpression,
33
34
  createProduct: returnProduct,
package/src/types.ts CHANGED
@@ -302,6 +302,20 @@ export const ProductActionType = {
302
302
  AddToWishlist: 9 as const,
303
303
  RemoveFromWishlist: 10 as const,
304
304
 
305
+ // Rokt Brain commerce-adjacent types
306
+ ViewCart: 11 as const,
307
+ AddShippingInfo: 12 as const,
308
+ AddPaymentInfo: 13 as const,
309
+ PaymentMethodSelected: 14 as const,
310
+ PaymentAttempted: 15 as const,
311
+ PaymentSucceeded: 16 as const,
312
+ PaymentFailed: 17 as const,
313
+ RefundInitiated: 18 as const,
314
+
315
+ isRoktCommerceType: (id: number): boolean => {
316
+ return id >= ProductActionType.ViewCart && id <= ProductActionType.RefundInitiated;
317
+ },
318
+
305
319
  getName: (id: number): string => {
306
320
  switch (id) {
307
321
  case ProductActionType.AddToCart:
@@ -324,6 +338,22 @@ export const ProductActionType = {
324
338
  return 'Add to Wishlist';
325
339
  case ProductActionType.RemoveFromWishlist:
326
340
  return 'Remove from Wishlist';
341
+ case ProductActionType.ViewCart:
342
+ return 'View Cart';
343
+ case ProductActionType.AddShippingInfo:
344
+ return 'Add Shipping Info';
345
+ case ProductActionType.AddPaymentInfo:
346
+ return 'Add Payment Info';
347
+ case ProductActionType.PaymentMethodSelected:
348
+ return 'Payment Method Selected';
349
+ case ProductActionType.PaymentAttempted:
350
+ return 'Payment Attempted';
351
+ case ProductActionType.PaymentSucceeded:
352
+ return 'Payment Succeeded';
353
+ case ProductActionType.PaymentFailed:
354
+ return 'Payment Failed';
355
+ case ProductActionType.RefundInitiated:
356
+ return 'Refund Initiated';
327
357
  default:
328
358
  return 'Unknown';
329
359
  }
@@ -352,12 +382,56 @@ export const ProductActionType = {
352
382
  return 'add_to_wishlist';
353
383
  case ProductActionType.RemoveFromWishlist:
354
384
  return 'remove_from_wishlist';
385
+ case ProductActionType.ViewCart:
386
+ return 'view_cart';
387
+ case ProductActionType.AddShippingInfo:
388
+ return 'add_shipping_info';
389
+ case ProductActionType.AddPaymentInfo:
390
+ return 'add_payment_info';
391
+ case ProductActionType.PaymentMethodSelected:
392
+ return 'payment_method_selected';
393
+ case ProductActionType.PaymentAttempted:
394
+ return 'payment_attempted';
395
+ case ProductActionType.PaymentSucceeded:
396
+ return 'payment_succeeded';
397
+ case ProductActionType.PaymentFailed:
398
+ return 'payment_failed';
399
+ case ProductActionType.RefundInitiated:
400
+ return 'refund_initiated';
355
401
  default:
356
402
  return 'unknown';
357
403
  }
358
404
  },
359
405
  };
360
406
 
407
+ export type RoktEventName =
408
+ | 'sign_up'
409
+ | 'subscribe'
410
+ | 'start_trial'
411
+ | 'generate_lead'
412
+ | 'search'
413
+ | 'upsell'
414
+ | 'earn_virtual_currency'
415
+ | 'dwell_time'
416
+ | 'hover'
417
+ | 'scroll'
418
+ | 'click_to_expand'
419
+ | (string & {});
420
+
421
+ export const RoktEvents = {
422
+ SignUp: 'sign_up' as const,
423
+ Subscribe: 'subscribe' as const,
424
+ StartTrial: 'start_trial' as const,
425
+ GenerateLead: 'generate_lead' as const,
426
+ Search: 'search' as const,
427
+ Upsell: 'upsell' as const,
428
+ EarnVirtualCurrency: 'earn_virtual_currency' as const,
429
+ DwellTime: 'dwell_time' as const,
430
+ Hover: 'hover' as const,
431
+ Scroll: 'scroll' as const,
432
+ ClickToExpand: 'click_to_expand' as const,
433
+ };
434
+
361
435
  export const PromotionActionType = {
362
436
  Unknown: 0 as const,
363
437
  PromotionView: 1 as const,
@@ -544,5 +618,6 @@ export default {
544
618
  ApplicationTransitionType,
545
619
  ProductActionType,
546
620
  PromotionActionType,
621
+ RoktEvents,
547
622
  Environment: Constants.Environment,
548
623
  } as const;