Skip to content

Commit 44cd55d

Browse files
jaissica12rmi22186
authored andcommitted
feat: add Rokt Brain event type constants (#1269)
1 parent cbefb33 commit 44cd55d

10 files changed

Lines changed: 259 additions & 2 deletions

src/ecommerce.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ export default function Ecommerce(mpInstance) {
6969
return 'RemoveFromWishlist';
7070
case Types.ProductActionType.ViewDetail:
7171
return 'ViewDetail';
72+
case Types.ProductActionType.ViewCart:
73+
return 'ViewCart';
74+
case Types.ProductActionType.AddShippingInfo:
75+
return 'AddShippingInfo';
76+
case Types.ProductActionType.AddPaymentInfo:
77+
return 'AddPaymentInfo';
78+
case Types.ProductActionType.PaymentMethodSelected:
79+
return 'PaymentMethodSelected';
80+
case Types.ProductActionType.PaymentAttempted:
81+
return 'PaymentAttempted';
82+
case Types.ProductActionType.PaymentSucceeded:
83+
return 'PaymentSucceeded';
84+
case Types.ProductActionType.PaymentFailed:
85+
return 'PaymentFailed';
86+
case Types.ProductActionType.RefundInitiated:
87+
return 'RefundInitiated';
7288
case Types.ProductActionType.Unknown:
7389
default:
7490
return 'Unknown';
@@ -113,6 +129,18 @@ export default function Ecommerce(mpInstance) {
113129

114130
case Types.ProductActionType.ViewDetail:
115131
return Types.CommerceEventType.ProductViewDetail;
132+
133+
// Rokt Brain commerce-adjacent types map to Unknown on server
134+
case Types.ProductActionType.ViewCart:
135+
case Types.ProductActionType.AddShippingInfo:
136+
case Types.ProductActionType.AddPaymentInfo:
137+
case Types.ProductActionType.PaymentMethodSelected:
138+
case Types.ProductActionType.PaymentAttempted:
139+
case Types.ProductActionType.PaymentSucceeded:
140+
case Types.ProductActionType.PaymentFailed:
141+
case Types.ProductActionType.RefundInitiated:
142+
return Types.EventType.Unknown;
143+
116144
default:
117145
mpInstance.Logger.error(
118146
'Could not convert product action type ' +

src/events.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ export default function Events(mpInstance) {
174174
ProductList: productList,
175175
};
176176

177+
if (Types.ProductActionType.isRoktCommerceType(productActionType)) {
178+
event.CustomFlags = event.CustomFlags || {};
179+
event.CustomFlags[
180+
'Rokt.CommerceEventType'
181+
] = Types.ProductActionType.getExpansionName(productActionType);
182+
}
183+
177184
if (mpInstance._Helpers.isObject(transactionAttributes)) {
178185
mpInstance._Ecommerce.convertTransactionAttributesToProductAction(
179186
transactionAttributes,

src/mp-instance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Uses portions of code from jQuery
1717
// jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
1818

19-
import { EventType, IdentityType, CommerceEventType, PromotionActionType, ProductActionType, MessageType } from './types';
19+
import { EventType, IdentityType, CommerceEventType, PromotionActionType, ProductActionType, MessageType, RoktEvents } from './types';
2020
import Constants from './constants';
2121
import APIClient, { IAPIClient } from './apiClient';
2222
import Helpers from './helpers';
@@ -188,6 +188,7 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
188188
this.CommerceEventType = CommerceEventType;
189189
this.PromotionType = PromotionActionType;
190190
this.ProductActionType = ProductActionType;
191+
this.RoktEvents = RoktEvents;
191192

192193

193194
this._Identity = new Identity(this);

src/mparticle-instance-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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';
33
import Constants from './constants';
44
import mParticleInstance, { IMParticleWebSDKInstance } from './mp-instance.js';
55
import _BatchValidator from './mockBatchCreator';
@@ -36,6 +36,7 @@ function mParticleInstanceManager(this: IMParticleInstanceManager) {
3636
this.CommerceEventType = CommerceEventType;
3737
this.PromotionType = PromotionActionType;
3838
this.ProductActionType = ProductActionType;
39+
this.RoktEvents = RoktEvents;
3940

4041
this.MPSideloadedKit = MPSideloadedKit;
4142

src/public-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export type {
2727
ProductActionType,
2828
PromotionActionType,
2929
MessageType,
30+
RoktEventName,
31+
RoktEvents,
3032
} from './types';
3133

3234
// Configuration

src/sdkRuntimeModels.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
IdentityType,
4040
ProductActionType,
4141
PromotionActionType,
42+
RoktEvents,
4243
} from './types';
4344
import { IPixelConfiguration } from './cookieSyncManager';
4445
import _BatchValidator from './mockBatchCreator';
@@ -145,6 +146,14 @@ export enum SDKProductActionType {
145146
Refund = 8,
146147
AddToWishlist = 9,
147148
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,
148157
}
149158

150159
export interface SDKProductAction {
@@ -184,6 +193,7 @@ export interface MParticleWebSDK {
184193
EventType: typeof EventType;
185194
PromotionType: typeof PromotionActionType;
186195
ProductActionType: typeof ProductActionType;
196+
RoktEvents: typeof RoktEvents;
187197
Identity: SDKIdentityApi;
188198
Logger: SDKLoggerApi;
189199
Consent: SDKConsentApi;

src/stub/mparticle.stub.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ let mParticle = {
2828
IdentityType: {},
2929
ProductActionType: {},
3030
PromotionType: {},
31+
RoktEvents: {},
3132
eCommerce: {
3233
createImpression: returnImpression,
3334
createProduct: returnProduct,

src/types.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ export const ProductActionType = {
302302
AddToWishlist: 9 as const,
303303
RemoveFromWishlist: 10 as const,
304304

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+
305319
getName: (id: number): string => {
306320
switch (id) {
307321
case ProductActionType.AddToCart:
@@ -324,6 +338,22 @@ export const ProductActionType = {
324338
return 'Add to Wishlist';
325339
case ProductActionType.RemoveFromWishlist:
326340
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';
327357
default:
328358
return 'Unknown';
329359
}
@@ -352,12 +382,56 @@ export const ProductActionType = {
352382
return 'add_to_wishlist';
353383
case ProductActionType.RemoveFromWishlist:
354384
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';
355401
default:
356402
return 'unknown';
357403
}
358404
},
359405
};
360406

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+
361435
export const PromotionActionType = {
362436
Unknown: 0 as const,
363437
PromotionView: 1 as const,
@@ -544,5 +618,6 @@ export default {
544618
ApplicationTransitionType,
545619
ProductActionType,
546620
PromotionActionType,
621+
RoktEvents,
547622
Environment: Constants.Environment,
548623
} as const;

0 commit comments

Comments
 (0)