Skip to content
Open
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
25 changes: 25 additions & 0 deletions src/roktManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export interface IRoktManagerOptions {
sandbox?: boolean;
}

export interface IRoktExperimentAllocation {
userId: string;
experimentId: string;
bucketId: string;
}

// The purpose of this class is to create a link between the Core mParticle SDK and the
// Rokt Web SDK via a Web Kit.
// The Rokt Manager should load before the Web Kit and stubs out many of the
Expand All @@ -72,9 +78,12 @@ export default class RoktManager {
private currentUser: IMParticleUser | null = null;
private filteredUser: IMParticleUser | null = null;
private messageQueue: IRoktMessage[] = [];

private sandbox: boolean | null = null;
private placementAttributesMapping: Dictionary<string>[] = [];

private experimentAllocation: IRoktExperimentAllocation | null = null;

/**
* Initializes the RoktManager with configuration settings and user data.
*
Expand Down Expand Up @@ -112,6 +121,7 @@ export default class RoktManager {
}

public selectPlacements(options: IRoktSelectPlacementsOptions): Promise<IRoktSelection> {

if (!this.isReady()) {
this.queueMessage({
methodName: 'selectPlacements',
Expand All @@ -127,6 +137,12 @@ export default class RoktManager {

this.setUserAttributes(mappedAttributes);

if (this.experimentAllocation) {
mappedAttributes['rokt.partnerexperiment.experimentid'] = this.experimentAllocation.experimentId;
mappedAttributes['rokt.partnerexperiment.bucketid'] = this.experimentAllocation.bucketId;
mappedAttributes['rokt.partnerexperiment.userid'] = this.experimentAllocation.userId;
}

const enrichedAttributes = {
...mappedAttributes,
...(sandboxValue !== null ? { sandbox: sandboxValue } : {}),
Expand Down Expand Up @@ -176,6 +192,15 @@ export default class RoktManager {
}
}

public setExperimentAllocationData(userId: string, experimentId: string, bucketId: string): void {
this.experimentAllocation = {
userId,
experimentId,
bucketId,
};

}

private isReady(): boolean {
// The Rokt Manager is ready when a kit is attached and has a launcher
return Boolean(this.kit && this.kit.launcher);
Expand Down