diff --git a/src/roktManager.ts b/src/roktManager.ts index f7b4aec5e..31c624767 100644 --- a/src/roktManager.ts +++ b/src/roktManager.ts @@ -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 @@ -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[] = []; + private experimentAllocation: IRoktExperimentAllocation | null = null; + /** * Initializes the RoktManager with configuration settings and user data. * @@ -112,6 +121,7 @@ export default class RoktManager { } public selectPlacements(options: IRoktSelectPlacementsOptions): Promise { + if (!this.isReady()) { this.queueMessage({ methodName: 'selectPlacements', @@ -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 } : {}), @@ -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);