diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index b1574fd..f9f1e14 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -539,11 +539,19 @@ var constructor = function () { } function attachLauncher(accountId, launcherOptions) { + var mpSessionId = + window.mParticle && + window.mParticle.sessionManager && + typeof window.mParticle.sessionManager.getSession === 'function' + ? window.mParticle.sessionManager.getSession() + : undefined; + var options = mergeObjects( { accountId: accountId, }, - launcherOptions || {} + launcherOptions || {}, + mpSessionId ? { mpSessionId: mpSessionId } : {} ); if (isPartnerInLocalLauncherTestGroup()) { diff --git a/test/src/tests.js b/test/src/tests.js index 2d05873..48bbce5 100644 --- a/test/src/tests.js +++ b/test/src/tests.js @@ -82,6 +82,11 @@ describe('Rokt Forwarder', () => { mParticle._Store = { localSessionAttributes: {}, }; + mParticle.sessionManager = { + getSession: function () { + return 'test-mp-session-id'; + }, + }; mParticle._getActiveForwarders = function () { return []; }; @@ -114,6 +119,7 @@ describe('Rokt Forwarder', () => { self.integrationName = options.integrationName; self.noFunctional = options.noFunctional; self.noTargeting = options.noTargeting; + self.mpSessionId = options.mpSessionId; self.createLauncherCalled = true; self.isInitialized = true; self.sandbox = options.sandbox; @@ -130,6 +136,7 @@ describe('Rokt Forwarder', () => { self.integrationName = options.integrationName; self.noFunctional = options.noFunctional; self.noTargeting = options.noTargeting; + self.mpSessionId = options.mpSessionId; self.createLocalLauncherCalled = true; self.isInitialized = true; self.sandbox = options.sandbox; @@ -842,6 +849,40 @@ describe('Rokt Forwarder', () => { window.mParticle.Rokt.createLauncherCalled.should.equal(true); }); + + it('should pass mpSessionId from mParticle sessionManager to createLauncher', async () => { + window.mParticle.sessionManager = { + getSession: function () { + return 'my-mp-session-123'; + }, + }; + + await window.mParticle.forwarder.init( + { accountId: '123456' }, + reportService.cb, + true, + null, + {} + ); + + window.mParticle.Rokt.mpSessionId.should.equal('my-mp-session-123'); + }); + + it('should not pass mpSessionId when sessionManager is unavailable', async () => { + delete window.mParticle.sessionManager; + + await window.mParticle.forwarder.init( + { accountId: '123456' }, + reportService.cb, + true, + null, + {} + ); + + (window.mParticle.Rokt.mpSessionId === undefined).should.equal( + true + ); + }); }); describe('#selectPlacements', () => {