From a015c9628306af12839606daa7253fa4cb4963a9 Mon Sep 17 00:00:00 2001 From: Guillermo Tamanaha Date: Mon, 13 Oct 2025 12:02:02 -0300 Subject: [PATCH 1/2] feat: Enhance local launcher logic with user threshold check --- src/Rokt-Kit.js | 8 +++++++- test/src/tests.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index ce29f00..b6497fa 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -435,9 +435,15 @@ var constructor = function () { function isPartnerInLocalLauncherTestGroup() { return ( window.mParticle.config && - window.mParticle.config.isLocalLauncherEnabled + window.mParticle.config.isLocalLauncherEnabled && + _isUserAboveLocalLauncherThreshold() ); } + + function _isUserAboveLocalLauncherThreshold() { + var LOCAL_LAUNCHER_TEST_GROUP_THRESHOLD = 0.5; + return Math.random() > LOCAL_LAUNCHER_TEST_GROUP_THRESHOLD; + } }; function generateIntegrationName(customIntegrationName) { diff --git a/test/src/tests.js b/test/src/tests.js index 459d04b..fc073a4 100644 --- a/test/src/tests.js +++ b/test/src/tests.js @@ -566,6 +566,7 @@ describe('Rokt Forwarder', () => { }, }; window.mParticle.config = undefined; + Math.random = () => 1; }); it('should create a remote launcher if the partner is not in the local launcher test group', async () => { @@ -598,6 +599,44 @@ describe('Rokt Forwarder', () => { window.mParticle.Rokt.createLocalLauncherCalled.should.equal(true); }); + it('should create a remote launcher if the partner is in the local launcher test group but the random number is below the thresholds', async () => { + window.mParticle.config = { + isLocalLauncherEnabled: true, + }; + + Math.random = () => 0; + + await window.mParticle.forwarder.init( + { accountId: '123456' }, + reportService.cb, + true, + null, + {} + ); + + window.mParticle.Rokt.createLauncherCalled.should.equal(true); + window.mParticle.Rokt.createLocalLauncherCalled.should.equal(false); + }); + + it('should create a local launcher if the partner is in the local launcher test group but the random number is above the thresholds', async () => { + window.mParticle.config = { + isLocalLauncherEnabled: true, + }; + + Math.random = () => 1; + + await window.mParticle.forwarder.init( + { accountId: '123456' }, + reportService.cb, + true, + null, + {} + ); + + window.mParticle.Rokt.createLauncherCalled.should.equal(false); + window.mParticle.Rokt.createLocalLauncherCalled.should.equal(true); + }); + it('should call attachKit', async () => { await window.mParticle.forwarder.init( { accountId: '123456' }, From 2b897e1becb3e4aac713906466737236cf9ae799 Mon Sep 17 00:00:00 2001 From: Guillermo Tamanaha Date: Mon, 13 Oct 2025 13:03:46 -0300 Subject: [PATCH 2/2] Rename function --- src/Rokt-Kit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index b6497fa..1730adf 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -436,11 +436,11 @@ var constructor = function () { return ( window.mParticle.config && window.mParticle.config.isLocalLauncherEnabled && - _isUserAboveLocalLauncherThreshold() + _isAssignedToSampleGroup() ); } - function _isUserAboveLocalLauncherThreshold() { + function _isAssignedToSampleGroup() { var LOCAL_LAUNCHER_TEST_GROUP_THRESHOLD = 0.5; return Math.random() > LOCAL_LAUNCHER_TEST_GROUP_THRESHOLD; }