Skip to content

Commit

Permalink
refactor: Create Interfaces for Events
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle committed Jan 7, 2025
1 parent bd9a63d commit f6af349
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
77 changes: 77 additions & 0 deletions src/events.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
Callback,
Dictionary,
SDKEventAttrs,
SDKEventOptions,
TransactionAttributes,
} from '@mparticle/web-sdk';
import {
BaseEvent,
SDKEventCustomFlags,
SDKProduct,
SDKProductImpression,
SDKPromotion,
} from './sdkRuntimeModels';
import { valueof } from './utils';
import { EventType, ProductActionType, PromotionActionType } from './types';

type dataFunction = (element: HTMLElement) => Dictionary<string>;
type dataObject = Dictionary<string>;

export interface IEvents {
addEventHandler(
domEvent: string,
selector: string | Node,
eventName: string,

// QUESTION: In what cases would data be a function?
data: dataObject | dataFunction,

eventType: valueof<typeof EventType>
): void;
logCheckoutEvent(
step: number,
option?: SDKEventOptions,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags
);
logEvent(event: BaseEvent, eventOptions?: SDKEventOptions): void;
logImpressionEvent(
impression: SDKProductImpression,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
eventOptions?: SDKEventOptions
);
logOptOut(): void;
logProductActionEvent(
productActionType: valueof<typeof ProductActionType>,
product: SDKProduct,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
transactionAttributes?: TransactionAttributes,
eventOptions?: SDKEventOptions
);
logPromotionEvent(
promotionType: valueof<typeof PromotionActionType>,
promotion: SDKPromotion,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
eventOptions?: SDKEventOptions
);
logPurchaseEvent(
product: SDKProduct,
transactionAttributes?: TransactionAttributes,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags
);
logRefundEvent(
transactionAttributes: TransactionAttributes,
product: SDKProduct,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags
);
startTracking(callback: Callback): void;
stopTracking(): void;


}
18 changes: 9 additions & 9 deletions src/sdkRuntimeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
MPConfiguration,
MPID,
IdentityApiData,
SDKEventOptions,
SDKEventAttrs,
} from '@mparticle/web-sdk';
import { IStore } from './store';
import Validators from './validators';
Expand Down Expand Up @@ -37,6 +39,7 @@ import {
import IntegrationCapture from './integrationCapture';
import { INativeSdkHelpers } from './nativeSdkHelpers.interfaces';
import { ICookieSyncManager, IPixelConfiguration } from './cookieSyncManager';
import { IEvents } from './events.interfaces';

// TODO: Resolve this with version in @mparticle/web-sdk
export type SDKEventCustomFlags = Dictionary<any>;
Expand Down Expand Up @@ -150,11 +153,6 @@ export interface SDKProduct {
Attributes?: { [key: string]: string };
}

// Temporary Interfaces for Events Module
interface IEvents {
logEvent?(event: BaseEvent): void;
}

export interface MParticleWebSDK {
addForwarder(mockForwarder: MPForwarder): void;
_IntegrationCapture: IntegrationCapture;
Expand Down Expand Up @@ -204,11 +202,12 @@ export interface MParticleWebSDK {
startNewSession(): void;
logEvent(
eventName: string,
eventType?: number,
attrs?: { [key: string]: string },
customFlags?: SDKEventCustomFlags
eventType?: valueof<typeof EventType>,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
eventOptions?: SDKEventOptions
): void;
logBaseEvent(event: any): void;
logBaseEvent(event: BaseEvent, eventOptions?: SDKEventOptions): void;
eCommerce: any;
logLevel: string;
ProductActionType: SDKProductActionType;
Expand Down Expand Up @@ -293,6 +292,7 @@ export interface SDKHelpersApi {
timeoutStart: number,
now: number
): boolean;
isEventType?(type: valueof<typeof EventType>): boolean;
isObject?(item: any);
invokeCallback?(
callback: IdentityCallback,
Expand Down

0 comments on commit f6af349

Please sign in to comment.