From c5f08c381b46dd61f5e98653184ba6a599ac8b92 Mon Sep 17 00:00:00 2001 From: Patrick Wu Date: Thu, 1 May 2025 11:18:22 -0400 Subject: [PATCH 1/3] Add experiments allocation function to RoktManager --- src/roktManager.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/roktManager.ts b/src/roktManager.ts index f7b4aec5e..154a953a6 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,13 @@ 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 +122,12 @@ export default class RoktManager { } public selectPlacements(options: IRoktSelectPlacementsOptions): Promise { + if (this.experimentAllocation) { + options.attributes['rokt.experimentid'] = this.experimentAllocation.experimentId; + options.attributes['rokt.bucketid'] = this.experimentAllocation.bucketId; + options.attributes['rokt.userid'] = this.experimentAllocation.userId; + } + if (!this.isReady()) { this.queueMessage({ methodName: 'selectPlacements', @@ -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); From 7e2dc18c219cca661ad854ad148c2887e140f78d Mon Sep 17 00:00:00 2001 From: Patrick Wu Date: Thu, 1 May 2025 12:57:21 -0400 Subject: [PATCH 2/3] Move into try block --- src/roktManager.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/roktManager.ts b/src/roktManager.ts index 154a953a6..0225511a7 100644 --- a/src/roktManager.ts +++ b/src/roktManager.ts @@ -122,11 +122,6 @@ export default class RoktManager { } public selectPlacements(options: IRoktSelectPlacementsOptions): Promise { - if (this.experimentAllocation) { - options.attributes['rokt.experimentid'] = this.experimentAllocation.experimentId; - options.attributes['rokt.bucketid'] = this.experimentAllocation.bucketId; - options.attributes['rokt.userid'] = this.experimentAllocation.userId; - } if (!this.isReady()) { this.queueMessage({ @@ -143,6 +138,12 @@ export default class RoktManager { this.setUserAttributes(mappedAttributes); + if (this.experimentAllocation) { + mappedAttributes['rokt.experimentid'] = this.experimentAllocation.experimentId; + mappedAttributes['rokt.bucketid'] = this.experimentAllocation.bucketId; + mappedAttributes['rokt.userid'] = this.experimentAllocation.userId; + } + const enrichedAttributes = { ...mappedAttributes, ...(sandboxValue !== null ? { sandbox: sandboxValue } : {}), From b5079935cbc806d15ba599e2c18c46b5bce74bd7 Mon Sep 17 00:00:00 2001 From: Patrick Wu Date: Thu, 1 May 2025 13:28:50 -0400 Subject: [PATCH 3/3] Add more specific prefix for kit to parse; rm ws --- src/roktManager.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/roktManager.ts b/src/roktManager.ts index 0225511a7..31c624767 100644 --- a/src/roktManager.ts +++ b/src/roktManager.ts @@ -84,7 +84,6 @@ export default class RoktManager { private experimentAllocation: IRoktExperimentAllocation | null = null; - /** * Initializes the RoktManager with configuration settings and user data. * @@ -139,9 +138,9 @@ export default class RoktManager { this.setUserAttributes(mappedAttributes); if (this.experimentAllocation) { - mappedAttributes['rokt.experimentid'] = this.experimentAllocation.experimentId; - mappedAttributes['rokt.bucketid'] = this.experimentAllocation.bucketId; - mappedAttributes['rokt.userid'] = this.experimentAllocation.userId; + mappedAttributes['rokt.partnerexperiment.experimentid'] = this.experimentAllocation.experimentId; + mappedAttributes['rokt.partnerexperiment.bucketid'] = this.experimentAllocation.bucketId; + mappedAttributes['rokt.partnerexperiment.userid'] = this.experimentAllocation.userId; } const enrichedAttributes = {