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;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

/**
* 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 {
}
}

Copy link

Copilot AI May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a JSDoc comment above setExperimentAllocationData to clarify its purpose, input parameters, and usage.

Suggested change
/**
* Sets the experiment allocation data for a user.
*
* @param {string} userId - The unique identifier for the user.
* @param {string} experimentId - The unique identifier for the experiment.
* @param {string} bucketId - The unique identifier for the bucket within the experiment.
*
* This method stores the provided experiment allocation data in the `experimentAllocation` object.
*/

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another useful suggestion and something we should be doing more often. Not a blocker.

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