Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#55040 Add Event Options to mParticle event…
Browse files Browse the repository at this point in the history
… logging methods v2.13.0 (#1) by @alexs-mparticle
  • Loading branch information
alexs-mparticle authored Aug 9, 2021
1 parent cbefe78 commit e8e7fb9
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
13 changes: 12 additions & 1 deletion types/mparticle__web-sdk/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export interface SDKEventCustomFlags {
| unknown[]
| Record<string, unknown>;
}

export interface SDKEventOptions {
shouldUploadEvent: boolean;
}

export interface DataPlanConfig {
planId: string;
planVersion?: number | undefined;
Expand Down Expand Up @@ -83,6 +88,7 @@ interface LogEvent {
eventType?: EventType,
eventInfo?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
eventOptions?: SDKEventOptions,
): void;
}

Expand All @@ -109,8 +115,10 @@ interface LogPageView {
eventName?: string,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
eventOptions?: SDKEventOptions,
): void;
}

interface Ready {
(callback: () => void): void;
}
Expand Down Expand Up @@ -147,7 +155,7 @@ interface StopTrackingLocation {
}

interface LogBaseEvent {
(event: BaseEvent): void;
(event: BaseEvent, eventOptions?: SDKEventOptions): void;
}
interface Upload {
(): void;
Expand Down Expand Up @@ -250,6 +258,7 @@ interface LogImpression {
impression: Impression[] | Impression,
attrs?: Record<string, unknown>,
customFlags?: Record<string, unknown>,
eventOptions?: SDKEventOptions,
): void;
}
interface LogProductAction {
Expand All @@ -259,6 +268,7 @@ interface LogProductAction {
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
transactionAttributes?: TransactionAttributes,
eventOptions?: SDKEventOptions,
): void;
}
interface LogPromotion {
Expand All @@ -267,6 +277,7 @@ interface LogPromotion {
promotion: Promotion,
attrs?: SDKEventAttrs,
customFlags?: SDKEventCustomFlags,
eventOptions?: SDKEventOptions,
): void;
}
interface LogPurchase {
Expand Down
43 changes: 43 additions & 0 deletions types/mparticle__web-sdk/test/mparticle__web-sdk-instance-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const customFlags: mParticle.SDKEventCustomFlags = {
attr5: { foo: 'bar' },
};

const eventOptions: mParticle.SDKEventOptions = {
shouldUploadEvent: false,
};

const identifyRequest: mParticle.IdentifyRequest = {
userIdentities: {
customerid: 'test',
Expand Down Expand Up @@ -133,6 +137,15 @@ instance.logBaseEvent({
messageType: 1,
eventType: 1,
});
instance.logBaseEvent(
{
data: {},
name: 'baseEventName',
messageType: 1,
eventType: 1,
},
eventOptions
);

instance.logError('Login Failed', customAttrs);
instance.logError(
Expand All @@ -153,6 +166,13 @@ instance.logEvent(
customAttrs,
customFlags,
);
instance.logEvent(
'eventName',
mParticle.EventType.Location,
customAttrs,
customFlags,
eventOptions,
);

instance.logForm('click', 'eventName');
instance.logForm('click', 'eventName', instance.EventType.Location);
Expand All @@ -176,6 +196,12 @@ instance.logPageView();
instance.logPageView('pageName');
instance.logPageView('pageName', customAttrs);
instance.logPageView('pageName', customAttrs, customFlags);
instance.logPageView(
'pageName',
customAttrs,
customFlags,
eventOptions
);

instance.ready(() => {
console.log('hi');
Expand Down Expand Up @@ -402,6 +428,15 @@ instance.eCommerce.logProductAction(
eCommerceCustomFlags,
);

instance.eCommerce.logProductAction(
300,
[product1, product2],
eCommerceCustomAttributes,
eCommerceCustomFlags,
transactionAttributes1,
eventOptions,
);

instance.eCommerce.logPurchase(
transactionAttributes1,
[product1, product2],
Expand All @@ -426,13 +461,21 @@ instance.eCommerce.logPromotion(
eCommerceCustomAttributes,
eCommerceCustomFlags,
);
instance.eCommerce.logPromotion(
instance.PromotionType.Unknown,
promotion1,
eCommerceCustomAttributes,
eCommerceCustomFlags,
eventOptions,
);

instance.eCommerce.logImpression(impression1);
instance.eCommerce.logImpression([impression1, impression2]);
instance.eCommerce.logImpression(
impression1,
eCommerceCustomAttributes,
eCommerceCustomFlags,
eventOptions,
);

instance.eCommerce.logRefund(
Expand Down
43 changes: 43 additions & 0 deletions types/mparticle__web-sdk/test/mparticle__web-sdk-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const customFlags: mParticle.SDKEventCustomFlags = {
attr5: { foo: 'bar' },
};

const eventOptions: mParticle.SDKEventOptions = {
shouldUploadEvent: false,
};

const identifyRequest: mParticle.IdentifyRequest = {
userIdentities: {
customerid: 'test',
Expand Down Expand Up @@ -131,6 +135,15 @@ mParticle.logBaseEvent({
messageType: 1,
eventType: 1,
});
mParticle.logBaseEvent(
{
data: {},
name: 'baseEventName',
messageType: 1,
eventType: 1,
},
eventOptions
);

mParticle.logError('Login Failed', customAttrs);
mParticle.logError(
Expand All @@ -151,6 +164,13 @@ mParticle.logEvent(
customAttrs,
customFlags,
);
mParticle.logEvent(
'eventName',
mParticle.EventType.Location,
customAttrs,
customFlags,
eventOptions,
);

mParticle.logForm('click', 'eventName');
mParticle.logForm('click', 'eventName', mParticle.EventType.Location);
Expand All @@ -174,6 +194,12 @@ mParticle.logPageView();
mParticle.logPageView('pageName');
mParticle.logPageView('pageName', customAttrs);
mParticle.logPageView('pageName', customAttrs, customFlags);
mParticle.logPageView(
'pageName',
customAttrs,
customFlags,
eventOptions
);

mParticle.ready(() => {
console.log('hi');
Expand Down Expand Up @@ -400,6 +426,15 @@ mParticle.eCommerce.logProductAction(
eCommerceCustomFlags,
);

mParticle.eCommerce.logProductAction(
300,
[product1, product2],
eCommerceCustomAttributes,
eCommerceCustomFlags,
transactionAttributes1,
eventOptions,
);

mParticle.eCommerce.logPurchase(
transactionAttributes1,
[product1, product2],
Expand All @@ -424,13 +459,21 @@ mParticle.eCommerce.logPromotion(
eCommerceCustomAttributes,
eCommerceCustomFlags,
);
mParticle.eCommerce.logPromotion(
mParticle.PromotionType.Unknown,
promotion1,
eCommerceCustomAttributes,
eCommerceCustomFlags,
eventOptions,
);

mParticle.eCommerce.logImpression(impression1);
mParticle.eCommerce.logImpression([impression1, impression2]);
mParticle.eCommerce.logImpression(
impression1,
eCommerceCustomAttributes,
eCommerceCustomFlags,
eventOptions,
);

mParticle.eCommerce.logRefund(
Expand Down

0 comments on commit e8e7fb9

Please sign in to comment.