Skip to content

Commit c5f08c3

Browse files
committed
Add experiments allocation function to RoktManager
1 parent 7c30759 commit c5f08c3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/roktManager.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export interface IRoktManagerOptions {
5656
sandbox?: boolean;
5757
}
5858

59+
export interface IRoktExperimentAllocation {
60+
userId: string;
61+
experimentId: string;
62+
bucketId: string;
63+
}
64+
5965
// The purpose of this class is to create a link between the Core mParticle SDK and the
6066
// Rokt Web SDK via a Web Kit.
6167
// The Rokt Manager should load before the Web Kit and stubs out many of the
@@ -72,9 +78,13 @@ export default class RoktManager {
7278
private currentUser: IMParticleUser | null = null;
7379
private filteredUser: IMParticleUser | null = null;
7480
private messageQueue: IRoktMessage[] = [];
81+
7582
private sandbox: boolean | null = null;
7683
private placementAttributesMapping: Dictionary<string>[] = [];
7784

85+
private experimentAllocation: IRoktExperimentAllocation | null = null;
86+
87+
7888
/**
7989
* Initializes the RoktManager with configuration settings and user data.
8090
*
@@ -112,6 +122,12 @@ export default class RoktManager {
112122
}
113123

114124
public selectPlacements(options: IRoktSelectPlacementsOptions): Promise<IRoktSelection> {
125+
if (this.experimentAllocation) {
126+
options.attributes['rokt.experimentid'] = this.experimentAllocation.experimentId;
127+
options.attributes['rokt.bucketid'] = this.experimentAllocation.bucketId;
128+
options.attributes['rokt.userid'] = this.experimentAllocation.userId;
129+
}
130+
115131
if (!this.isReady()) {
116132
this.queueMessage({
117133
methodName: 'selectPlacements',
@@ -176,6 +192,15 @@ export default class RoktManager {
176192
}
177193
}
178194

195+
public setExperimentAllocationData(userId: string, experimentId: string, bucketId: string): void {
196+
this.experimentAllocation = {
197+
userId,
198+
experimentId,
199+
bucketId,
200+
};
201+
202+
}
203+
179204
private isReady(): boolean {
180205
// The Rokt Manager is ready when a kit is attached and has a launcher
181206
return Boolean(this.kit && this.kit.launcher);

0 commit comments

Comments
 (0)