From 2384f36f636731a40af03857adb358bd70a58a81 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Wed, 21 Jan 2026 09:45:59 -0500 Subject: [PATCH 1/4] feat: skip attaching the launcher when its embedded and update tests --- src/Rokt-Kit.js | 8 +++++--- test/src/tests.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index 1e11709..0797620 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -120,7 +120,11 @@ var constructor = function () { return; } - if (!window.Rokt || !(window.Rokt && window.Rokt.currentLauncher)) { + if (window.Rokt && typeof window.Rokt.createLauncher === 'function') { + if (!window.Rokt.currentLauncher) { + attachLauncher(accountId, launcherOptions); + } + } else { var target = document.head || document.body; var script = document.createElement('script'); script.type = 'text/javascript'; @@ -151,8 +155,6 @@ var constructor = function () { target.appendChild(script); captureTiming(PerformanceMarks.RoktScriptAppended); - } else { - console.warn('Unable to find Rokt on the page'); } } /** diff --git a/test/src/tests.js b/test/src/tests.js index 0b75846..c1821d0 100644 --- a/test/src/tests.js +++ b/test/src/tests.js @@ -577,6 +577,14 @@ describe('Rokt Forwarder', () => { }); it('should add a performance marker when the script is appended', async () => { + var savedRokt = window.mParticle.Rokt; + window.Rokt = undefined; + window.mParticle.Rokt = { + domain: 'apps.rokt.com', + attachKit: async () => Promise.resolve(), + filters: savedRokt.filters, + }; + await window.mParticle.forwarder.init( { accountId: '123456' }, reportService.cb, @@ -724,6 +732,34 @@ describe('Rokt Forwarder', () => { mockMessageQueue.length.should.equal(0); }); + + it('should call createLauncher when launcher is embedded and not yet initialized', async () => { + await window.mParticle.forwarder.init( + { accountId: '123456' }, + reportService.cb, + false, + null, + {} + ); + + await waitForCondition(() => window.mParticle.Rokt.attachKitCalled); + + window.mParticle.Rokt.createLauncherCalled.should.equal(true); + }); + + it('should not call createLauncher when launcher is already initialized', async () => { + window.Rokt.currentLauncher = { initialized: true }; + + await window.mParticle.forwarder.init( + { accountId: '123456' }, + reportService.cb, + false, + null, + {} + ); + + window.mParticle.Rokt.createLauncherCalled.should.equal(false); + }); }); describe('#selectPlacements', () => { From 8760220ea6c0819d0ac53802483a9bcff1ed883d Mon Sep 17 00:00:00 2001 From: Jaissica Date: Wed, 21 Jan 2026 12:05:01 -0500 Subject: [PATCH 2/4] add additional check for currentLauncher and update test --- src/Rokt-Kit.js | 2 ++ test/src/tests.js | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index 0797620..5c04557 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -123,6 +123,8 @@ var constructor = function () { if (window.Rokt && typeof window.Rokt.createLauncher === 'function') { if (!window.Rokt.currentLauncher) { attachLauncher(accountId, launcherOptions); + } else { + initRoktLauncher(window.Rokt.currentLauncher); } } else { var target = document.head || document.body; diff --git a/test/src/tests.js b/test/src/tests.js index c1821d0..3ca00b4 100644 --- a/test/src/tests.js +++ b/test/src/tests.js @@ -747,8 +747,16 @@ describe('Rokt Forwarder', () => { window.mParticle.Rokt.createLauncherCalled.should.equal(true); }); - it('should not call createLauncher when launcher is already initialized', async () => { - window.Rokt.currentLauncher = { initialized: true }; + it('should attach to existing launcher when currentLauncher already exists', async () => { + var existingLauncher = { + selectPlacements: function () { + return Promise.resolve({}); + }, + hashAttributes: function (attrs) { + return attrs; + }, + }; + window.Rokt.currentLauncher = existingLauncher; await window.mParticle.forwarder.init( { accountId: '123456' }, @@ -758,7 +766,13 @@ describe('Rokt Forwarder', () => { {} ); + await waitForCondition(() => window.mParticle.Rokt.attachKitCalled); + + // Should not call createLauncher since launcher exists window.mParticle.Rokt.createLauncherCalled.should.equal(false); + + // Forwarder should be initialized and functional + window.mParticle.forwarder.isInitialized.should.equal(true); }); }); From 1eedab7911e047998c3f2a7c6d93f7155045af60 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Wed, 28 Jan 2026 16:04:36 -0500 Subject: [PATCH 3/4] add helper to check if launcher can be attached and update tests --- src/Rokt-Kit.js | 27 +++++++++++++++------------ test/src/tests.js | 28 ---------------------------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index 5c04557..806a8db 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -58,6 +58,18 @@ var constructor = function () { return baseUrl + '?extensions=' + extensions.join(','); } + /** + * Checks if Rokt launcher is available and ready to attach + * @returns {boolean} True if launcher can be attached + */ + function isLauncherReadyToAttach() { + return ( + window.Rokt && + typeof window.Rokt.createLauncher === 'function' && + window.Rokt.currentLauncher === undefined + ); + } + /** * Passes attributes to the Rokt Web SDK for client-side hashing * @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes @@ -120,12 +132,8 @@ var constructor = function () { return; } - if (window.Rokt && typeof window.Rokt.createLauncher === 'function') { - if (!window.Rokt.currentLauncher) { - attachLauncher(accountId, launcherOptions); - } else { - initRoktLauncher(window.Rokt.currentLauncher); - } + if (isLauncherReadyToAttach()) { + attachLauncher(accountId, launcherOptions); } else { var target = document.head || document.body; var script = document.createElement('script'); @@ -137,12 +145,7 @@ var constructor = function () { script.id = 'rokt-launcher'; script.onload = function () { - // Once the script loads, ensure the Rokt object is available - if ( - window.Rokt && - typeof window.Rokt.createLauncher === 'function' && - window.Rokt.currentLauncher === undefined - ) { + if (isLauncherReadyToAttach()) { attachLauncher(accountId, launcherOptions); } else { console.error( diff --git a/test/src/tests.js b/test/src/tests.js index 3ca00b4..ada98e0 100644 --- a/test/src/tests.js +++ b/test/src/tests.js @@ -746,34 +746,6 @@ describe('Rokt Forwarder', () => { window.mParticle.Rokt.createLauncherCalled.should.equal(true); }); - - it('should attach to existing launcher when currentLauncher already exists', async () => { - var existingLauncher = { - selectPlacements: function () { - return Promise.resolve({}); - }, - hashAttributes: function (attrs) { - return attrs; - }, - }; - window.Rokt.currentLauncher = existingLauncher; - - await window.mParticle.forwarder.init( - { accountId: '123456' }, - reportService.cb, - false, - null, - {} - ); - - await waitForCondition(() => window.mParticle.Rokt.attachKitCalled); - - // Should not call createLauncher since launcher exists - window.mParticle.Rokt.createLauncherCalled.should.equal(false); - - // Forwarder should be initialized and functional - window.mParticle.forwarder.isInitialized.should.equal(true); - }); }); describe('#selectPlacements', () => { From 6d50f614ae1661818b863cc904e27b25a8488f82 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 29 Jan 2026 17:08:44 -0500 Subject: [PATCH 4/4] remove check for Rokt.currentLauncher --- src/Rokt-Kit.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index 806a8db..ecd5440 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -63,11 +63,7 @@ var constructor = function () { * @returns {boolean} True if launcher can be attached */ function isLauncherReadyToAttach() { - return ( - window.Rokt && - typeof window.Rokt.createLauncher === 'function' && - window.Rokt.currentLauncher === undefined - ); + return window.Rokt && typeof window.Rokt.createLauncher === 'function'; } /**