Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/ecommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ export default function Ecommerce(mpInstance) {
return 'RemoveFromWishlist';
case Types.ProductActionType.ViewDetail:
return 'ViewDetail';
case Types.ProductActionType.ViewCart:
return 'ViewCart';
case Types.ProductActionType.AddShippingInfo:
return 'AddShippingInfo';
case Types.ProductActionType.AddPaymentInfo:
return 'AddPaymentInfo';
case Types.ProductActionType.PaymentMethodSelected:
return 'PaymentMethodSelected';
case Types.ProductActionType.PaymentAttempted:
return 'PaymentAttempted';
case Types.ProductActionType.PaymentSucceeded:
return 'PaymentSucceeded';
case Types.ProductActionType.PaymentFailed:
return 'PaymentFailed';
case Types.ProductActionType.RefundInitiated:
return 'RefundInitiated';
case Types.ProductActionType.Unknown:
default:
return 'Unknown';
Expand Down Expand Up @@ -113,6 +129,18 @@ export default function Ecommerce(mpInstance) {

case Types.ProductActionType.ViewDetail:
return Types.CommerceEventType.ProductViewDetail;

// Rokt Brain commerce-adjacent types map to Unknown on server
case Types.ProductActionType.ViewCart:
case Types.ProductActionType.AddShippingInfo:
case Types.ProductActionType.AddPaymentInfo:
case Types.ProductActionType.PaymentMethodSelected:
case Types.ProductActionType.PaymentAttempted:
case Types.ProductActionType.PaymentSucceeded:
case Types.ProductActionType.PaymentFailed:
case Types.ProductActionType.RefundInitiated:
return Types.EventType.Unknown;

default:
mpInstance.Logger.error(
'Could not convert product action type ' +
Expand Down
7 changes: 7 additions & 0 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export default function Events(mpInstance) {
ProductList: productList,
};

if (Types.ProductActionType.isRoktCommerceType(productActionType)) {
event.CustomFlags = event.CustomFlags || {};
event.CustomFlags[
'Rokt.CommerceEventType'
] = Types.ProductActionType.getExpansionName(productActionType);
}

if (mpInstance._Helpers.isObject(transactionAttributes)) {
mpInstance._Ecommerce.convertTransactionAttributesToProductAction(
transactionAttributes,
Expand Down
3 changes: 2 additions & 1 deletion src/mp-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// Uses portions of code from jQuery
// jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license

import { EventType, IdentityType, CommerceEventType, PromotionActionType, ProductActionType, MessageType } from './types';
import { EventType, IdentityType, CommerceEventType, PromotionActionType, ProductActionType, MessageType, RoktEvents } from './types';
import Constants from './constants';
import APIClient, { IAPIClient } from './apiClient';
import Helpers from './helpers';
Expand Down Expand Up @@ -126,12 +126,12 @@
this._instanceName = instanceName;
this._NativeSdkHelpers = new NativeSdkHelpers(this);
this._SessionManager = new SessionManager(this);
this._Persistence = new Persistence(this);

Check failure on line 129 in src/mp-instance.ts

View workflow job for this annotation

GitHub Actions / Core Tests / Core SDK Tests

Type '_Persistence' is not assignable to type 'IPersistence'.
this._Helpers = new Helpers(this);

Check failure on line 130 in src/mp-instance.ts

View workflow job for this annotation

GitHub Actions / Core Tests / Core SDK Tests

Type 'Helpers' is not assignable to type 'SDKHelpersApi'.
this._Events = new Events(this);
this._CookieSyncManager = new CookieSyncManager(this);
this._ServerModel = new ServerModel(this);
this._Ecommerce = new Ecommerce(this);

Check failure on line 134 in src/mp-instance.ts

View workflow job for this annotation

GitHub Actions / Core Tests / Core SDK Tests

Type 'Ecommerce' is not assignable to type 'IECommerce'.
this._ForwardingStatsUploader = new ForwardingStatsUploader(this);
this._Consent = new Consent(this);
this._IdentityAPIClient = new IdentityAPIClient(this);
Expand Down Expand Up @@ -187,9 +187,10 @@
this.CommerceEventType = CommerceEventType;
this.PromotionType = PromotionActionType;
this.ProductActionType = ProductActionType;
this.RoktEvents = RoktEvents;


this._Identity = new Identity(this);

Check failure on line 193 in src/mp-instance.ts

View workflow job for this annotation

GitHub Actions / Core Tests / Core SDK Tests

Type 'Identity' is not assignable to type 'IIdentity'.
this.Identity = this._Identity.IdentityAPI;
this.generateHash = this._Helpers.generateHash;

Expand All @@ -198,9 +199,9 @@
this.getDeviceId = this._Persistence.getDeviceId;

if (typeof window !== 'undefined') {
if (window.mParticle && window.mParticle.config) {

Check failure on line 202 in src/mp-instance.ts

View workflow job for this annotation

GitHub Actions / Core Tests / Core SDK Tests

Property 'config' does not exist on type 'typeof import("/home/runner/work/mparticle-web-sdk/mparticle-web-sdk/node_modules/@types/mparticle__web-sdk/index")'.
if (window.mParticle.config.hasOwnProperty('rq')) {

Check failure on line 203 in src/mp-instance.ts

View workflow job for this annotation

GitHub Actions / Core Tests / Core SDK Tests

Property 'config' does not exist on type 'typeof import("/home/runner/work/mparticle-web-sdk/mparticle-web-sdk/node_modules/@types/mparticle__web-sdk/index")'.
this._preInit.readyQueue = window.mParticle.config.rq;

Check failure on line 204 in src/mp-instance.ts

View workflow job for this annotation

GitHub Actions / Core Tests / Core SDK Tests

Property 'config' does not exist on type 'typeof import("/home/runner/work/mparticle-web-sdk/mparticle-web-sdk/node_modules/@types/mparticle__web-sdk/index")'.
}
}
}
Expand Down Expand Up @@ -1659,7 +1660,7 @@
mpInstance._ErrorReportingDispatcher.logger = mpInstance.Logger;
mpInstance._LoggingDispatcher.logger = mpInstance.Logger;
mpInstance._Store = new Store(config, mpInstance, apiKey);
window.mParticle.Store = mpInstance._Store;

Check failure on line 1663 in src/mp-instance.ts

View workflow job for this annotation

GitHub Actions / Core Tests / Core SDK Tests

Property 'Store' does not exist on type 'typeof import("/home/runner/work/mparticle-web-sdk/mparticle-web-sdk/node_modules/@types/mparticle__web-sdk/index")'.
mpInstance.Logger.verbose(StartingInitialization);

// Initialize CookieConsentManager with privacy flags from launcherOptions
Expand Down
3 changes: 2 additions & 1 deletion src/mparticle-instance-manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Polyfill from './polyfill';
import { CommerceEventType, EventType, IdentityType, PerformanceMarkType, ProductActionType, PromotionActionType } from './types';
import { CommerceEventType, EventType, IdentityType, PerformanceMarkType, ProductActionType, PromotionActionType, RoktEvents } from './types';
import Constants from './constants';
import mParticleInstance, { IMParticleWebSDKInstance } from './mp-instance.js';
import _BatchValidator from './mockBatchCreator';
Expand Down Expand Up @@ -36,6 +36,7 @@ function mParticleInstanceManager(this: IMParticleInstanceManager) {
this.CommerceEventType = CommerceEventType;
this.PromotionType = PromotionActionType;
this.ProductActionType = ProductActionType;
this.RoktEvents = RoktEvents;

this.MPSideloadedKit = MPSideloadedKit;

Expand Down
2 changes: 2 additions & 0 deletions src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type {
ProductActionType,
PromotionActionType,
MessageType,
RoktEventName,
RoktEvents,
} from './types';

// Configuration
Expand Down
10 changes: 10 additions & 0 deletions src/sdkRuntimeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
IdentityType,
ProductActionType,
PromotionActionType,
RoktEvents,
} from './types';
import { IPixelConfiguration } from './cookieSyncManager';
import _BatchValidator from './mockBatchCreator';
Expand Down Expand Up @@ -145,6 +146,14 @@ export enum SDKProductActionType {
Refund = 8,
AddToWishlist = 9,
RemoveFromWishlist = 10,
ViewCart = 11,
AddShippingInfo = 12,
AddPaymentInfo = 13,
PaymentMethodSelected = 14,
PaymentAttempted = 15,
PaymentSucceeded = 16,
PaymentFailed = 17,
RefundInitiated = 18,
}

export interface SDKProductAction {
Expand Down Expand Up @@ -184,6 +193,7 @@ export interface MParticleWebSDK {
EventType: typeof EventType;
PromotionType: typeof PromotionActionType;
ProductActionType: typeof ProductActionType;
RoktEvents: typeof RoktEvents;
Identity: SDKIdentityApi;
Logger: SDKLoggerApi;
Consent: SDKConsentApi;
Expand Down
1 change: 1 addition & 0 deletions src/stub/mparticle.stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let mParticle = {
IdentityType: {},
ProductActionType: {},
PromotionType: {},
RoktEvents: {},
eCommerce: {
createImpression: returnImpression,
createProduct: returnProduct,
Expand Down
75 changes: 75 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ export const ProductActionType = {
AddToWishlist: 9 as const,
RemoveFromWishlist: 10 as const,

// Rokt Brain commerce-adjacent types
ViewCart: 11 as const,
AddShippingInfo: 12 as const,
AddPaymentInfo: 13 as const,
PaymentMethodSelected: 14 as const,
PaymentAttempted: 15 as const,
PaymentSucceeded: 16 as const,
PaymentFailed: 17 as const,
RefundInitiated: 18 as const,

isRoktCommerceType: (id: number): boolean => {
return id >= ProductActionType.ViewCart && id <= ProductActionType.RefundInitiated;
},

getName: (id: number): string => {
switch (id) {
case ProductActionType.AddToCart:
Expand All @@ -324,6 +338,22 @@ export const ProductActionType = {
return 'Add to Wishlist';
case ProductActionType.RemoveFromWishlist:
return 'Remove from Wishlist';
case ProductActionType.ViewCart:
return 'View Cart';
case ProductActionType.AddShippingInfo:
return 'Add Shipping Info';
case ProductActionType.AddPaymentInfo:
return 'Add Payment Info';
case ProductActionType.PaymentMethodSelected:
return 'Payment Method Selected';
case ProductActionType.PaymentAttempted:
return 'Payment Attempted';
case ProductActionType.PaymentSucceeded:
return 'Payment Succeeded';
case ProductActionType.PaymentFailed:
return 'Payment Failed';
case ProductActionType.RefundInitiated:
return 'Refund Initiated';
default:
return 'Unknown';
}
Expand Down Expand Up @@ -352,12 +382,56 @@ export const ProductActionType = {
return 'add_to_wishlist';
case ProductActionType.RemoveFromWishlist:
return 'remove_from_wishlist';
case ProductActionType.ViewCart:
return 'view_cart';
case ProductActionType.AddShippingInfo:
return 'add_shipping_info';
case ProductActionType.AddPaymentInfo:
return 'add_payment_info';
case ProductActionType.PaymentMethodSelected:
return 'payment_method_selected';
case ProductActionType.PaymentAttempted:
return 'payment_attempted';
case ProductActionType.PaymentSucceeded:
return 'payment_succeeded';
case ProductActionType.PaymentFailed:
return 'payment_failed';
case ProductActionType.RefundInitiated:
return 'refund_initiated';
default:
return 'unknown';
}
},
};

export type RoktEventName =
| 'sign_up'
| 'subscribe'
| 'start_trial'
| 'generate_lead'
| 'search'
| 'upsell'
| 'earn_virtual_currency'
| 'dwell_time'
| 'hover'
| 'scroll'
| 'click_to_expand'
| (string & {});
Comment thread
alexs-mparticle marked this conversation as resolved.

export const RoktEvents = {
SignUp: 'sign_up' as const,
Subscribe: 'subscribe' as const,
StartTrial: 'start_trial' as const,
GenerateLead: 'generate_lead' as const,
Search: 'search' as const,
Upsell: 'upsell' as const,
EarnVirtualCurrency: 'earn_virtual_currency' as const,
DwellTime: 'dwell_time' as const,
Hover: 'hover' as const,
Scroll: 'scroll' as const,
ClickToExpand: 'click_to_expand' as const,
};

export const PromotionActionType = {
Unknown: 0 as const,
PromotionView: 1 as const,
Expand Down Expand Up @@ -544,5 +618,6 @@ export default {
ApplicationTransitionType,
ProductActionType,
PromotionActionType,
RoktEvents,
Environment: Constants.Environment,
} as const;
Loading
Loading