Skip to content

Commit b2d1557

Browse files
authored
feat: Implement Rokt Local Launcher SDKE-321 (#45)
1 parent 15a11a6 commit b2d1557

2 files changed

Lines changed: 90 additions & 26 deletions

File tree

src/Rokt-Kit.js

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -330,35 +330,40 @@ var constructor = function () {
330330
launcherOptions || {}
331331
);
332332

333-
window.Rokt.createLauncher(options)
334-
.then(function (launcher) {
335-
// Assign the launcher to a global variable for later access
336-
window.Rokt.currentLauncher = launcher;
337-
// Locally cache the launcher and filters
338-
self.launcher = launcher;
333+
if (isPartnerInLocalLauncherTestGroup()) {
334+
var localLauncher = window.Rokt.createLocalLauncher(options);
335+
initRoktLauncher(localLauncher);
336+
} else {
337+
window.Rokt.createLauncher(options)
338+
.then(initRoktLauncher)
339+
.catch(function (err) {
340+
console.error('Error creating Rokt launcher:', err);
341+
});
342+
}
343+
}
339344

340-
var roktFilters = window.mParticle.Rokt.filters;
345+
function initRoktLauncher(launcher) {
346+
// Assign the launcher to a global variable for later access
347+
window.Rokt.currentLauncher = launcher;
348+
// Locally cache the launcher and filters
349+
self.launcher = launcher;
341350

342-
if (!roktFilters) {
343-
console.warn('Rokt Kit: No filters have been set.');
344-
} else {
345-
self.filters = roktFilters;
346-
if (!roktFilters.filteredUser) {
347-
console.warn(
348-
'Rokt Kit: No filtered user has been set.'
349-
);
350-
}
351-
}
351+
var roktFilters = window.mParticle.Rokt.filters;
352352

353-
// Kit must be initialized before attaching to the Rokt manager
354-
self.isInitialized = true;
355-
// Attaches the kit to the Rokt manager
356-
window.mParticle.Rokt.attachKit(self);
357-
processEventQueue();
358-
})
359-
.catch(function (err) {
360-
console.error('Error creating Rokt launcher:', err);
361-
});
353+
if (!roktFilters) {
354+
console.warn('Rokt Kit: No filters have been set.');
355+
} else {
356+
self.filters = roktFilters;
357+
if (!roktFilters.filteredUser) {
358+
console.warn('Rokt Kit: No filtered user has been set.');
359+
}
360+
}
361+
362+
// Kit must be initialized before attaching to the Rokt manager
363+
self.isInitialized = true;
364+
// Attaches the kit to the Rokt manager
365+
window.mParticle.Rokt.attachKit(self);
366+
processEventQueue();
362367
}
363368

364369
// mParticle Kit Callback Methods
@@ -426,6 +431,13 @@ var constructor = function () {
426431
function isKitReady() {
427432
return !!(self.isInitialized && self.launcher);
428433
}
434+
435+
function isPartnerInLocalLauncherTestGroup() {
436+
return (
437+
window.mParticle.config &&
438+
window.mParticle.config.isLocalLauncherEnabled
439+
);
440+
}
429441
};
430442

431443
function generateIntegrationName(customIntegrationName) {

test/src/tests.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ describe('Rokt Forwarder', () => {
9898
this.sandbox = null;
9999
this.integrationName = null;
100100
this.createLauncherCalled = false;
101+
this.createLocalLauncherCalled = false;
101102

102103
this.createLauncher = function (options) {
103104
self.accountId = options.accountId;
@@ -115,6 +116,26 @@ describe('Rokt Forwarder', () => {
115116
});
116117
};
117118

119+
this.createLocalLauncher = function (options) {
120+
self.accountId = options.accountId;
121+
self.integrationName = options.integrationName;
122+
self.noFunctional = options.noFunctional;
123+
self.noTargeting = options.noTargeting;
124+
self.createLocalLauncherCalled = true;
125+
self.isInitialized = true;
126+
self.sandbox = options.sandbox;
127+
128+
return {
129+
selectPlacements: function () {},
130+
hashAttributes: function () {
131+
throw new Error('hashAttributes not implemented');
132+
},
133+
use: function () {
134+
throw new Error('use not implemented');
135+
},
136+
};
137+
};
138+
118139
this.currentLauncher = function () {};
119140
};
120141

@@ -544,6 +565,37 @@ describe('Rokt Forwarder', () => {
544565
},
545566
},
546567
};
568+
window.mParticle.config = undefined;
569+
});
570+
571+
it('should create a remote launcher if the partner is not in the local launcher test group', async () => {
572+
await window.mParticle.forwarder.init(
573+
{ accountId: '123456' },
574+
reportService.cb,
575+
true,
576+
null,
577+
{}
578+
);
579+
580+
window.mParticle.Rokt.createLauncherCalled.should.equal(true);
581+
window.mParticle.Rokt.createLocalLauncherCalled.should.equal(false);
582+
});
583+
584+
it('should create a local launcher if the partner is in the local launcher test group', async () => {
585+
window.mParticle.config = {
586+
isLocalLauncherEnabled: true,
587+
};
588+
589+
await window.mParticle.forwarder.init(
590+
{ accountId: '123456' },
591+
reportService.cb,
592+
true,
593+
null,
594+
{}
595+
);
596+
597+
window.mParticle.Rokt.createLauncherCalled.should.equal(false);
598+
window.mParticle.Rokt.createLocalLauncherCalled.should.equal(true);
547599
});
548600

549601
it('should call attachKit', async () => {

0 commit comments

Comments
 (0)