Skip to content

Commit 14c6418

Browse files
🤖 Merge PR DefinitelyTyped#73242 add Rokt namespace to mParticle Web SDK by @alexs-mparticle
Co-authored-by: Robert Ing <ring@mparticle.com>
1 parent 7a84978 commit 14c6418

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

‎types/mparticle__web-sdk/index.d.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,51 @@ import { Batch } from "@mparticle/event-models";
33
// Placeholder for Dictionary-like Types
44
export type Dictionary<V = any> = Record<string, V>;
55

6+
// Rokt Manager Types
7+
export type RoktPartnerAttributes = Dictionary<string | number | boolean | undefined | null>;
8+
9+
export interface RoktPartnerExtensionData<T> {
10+
[extensionName: string]: T;
11+
}
12+
13+
export interface RoktSelectPlacementsOptions {
14+
attributes: RoktPartnerAttributes;
15+
identifier?: string;
16+
}
17+
18+
export interface RoktPlacementEvent<T = void> {
19+
body: T;
20+
event: string;
21+
placement: RoktPlacement;
22+
}
23+
24+
export interface RoktSubscriber<T> {
25+
subscribe(handler: T): RoktUnsubscriber;
26+
}
27+
28+
export interface RoktUnsubscriber {
29+
unsubscribe(): void;
30+
}
31+
32+
export interface RoktPlacement {
33+
id: string;
34+
element: HTMLIFrameElement;
35+
close(): Promise<void>;
36+
on(event: string): RoktSubscriber<RoktPlacementEvent<unknown>>;
37+
ready(): Promise<void>;
38+
send(event: string, data?: unknown): Promise<void>;
39+
onClose(): Promise<void>;
40+
}
41+
42+
export interface RoktSelection {
43+
close: () => void;
44+
getPlacements: () => Promise<Array<RoktPlacement>>;
45+
on(eventName: string): RoktSubscriber<RoktPlacementEvent<unknown>>;
46+
ready(): Promise<void>;
47+
send(event: string, data?: unknown): Promise<void>;
48+
setAttributes(attributes: RoktPartnerAttributes): Promise<void>;
49+
}
50+
651
export as namespace mParticle;
752
export {};
853
export interface MPConfiguration {
@@ -309,6 +354,19 @@ interface GetSession {
309354
(): string;
310355
}
311356

357+
// Rokt Manager Method Interfaces
358+
interface SelectPlacements {
359+
(options: RoktSelectPlacementsOptions): Promise<RoktSelection>;
360+
}
361+
362+
interface HashAttributes {
363+
(attributes: RoktPartnerAttributes): Promise<Record<string, string>>;
364+
}
365+
366+
interface SetExtensionData {
367+
(extensionData: RoktPartnerExtensionData<unknown>): void;
368+
}
369+
312370
export const endSession: EndSession;
313371
export const getAppName: GetAppName;
314372
export const getAppVersion: GetAppVersion;
@@ -491,6 +549,12 @@ export namespace eCommerce {
491549
const Cart: Cart;
492550
}
493551

552+
export namespace Rokt {
553+
const selectPlacements: SelectPlacements;
554+
const hashAttributes: HashAttributes;
555+
const setExtensionData: SetExtensionData;
556+
}
557+
494558
export interface IdentifyRequest {
495559
userIdentities: UserIdentities;
496560
}
@@ -744,6 +808,11 @@ declare class mParticleInstance {
744808
setCurrencyCode: SetCurrencyCode;
745809
Cart: Cart;
746810
};
811+
Rokt: {
812+
selectPlacements: SelectPlacements;
813+
hashAttributes: HashAttributes;
814+
setExtensionData: SetExtensionData;
815+
};
747816
PromotionType: {
748817
Unknown: PromotionType.Unknown;
749818
PromotionClick: PromotionType.PromotionClick;

‎types/mparticle__web-sdk/test/mparticle__web-sdk-tests.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@ mParticle.logPageView("pageName", customAttrs);
193193
mParticle.logPageView("pageName", customAttrs, customFlags);
194194
mParticle.logPageView("pageName", customAttrs, customFlags, eventOptions);
195195

196+
mParticle.Rokt.selectPlacements({
197+
identifier: "mp-test-identifier",
198+
attributes: {
199+
email: "test@test.com",
200+
},
201+
});
202+
203+
mParticle.Rokt.hashAttributes({
204+
email: "test@test.com",
205+
});
206+
207+
mParticle.Rokt.setExtensionData({
208+
"test-extension": {
209+
"test-key": "test-value",
210+
},
211+
});
212+
196213
mParticle.ready(() => {
197214
console.log("hi");
198215
});

0 commit comments

Comments
 (0)