Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ var constructor = function () {
self.userAttributes = filteredUserAttributes;
self.onboardingExpProvider = settings.onboardingExpProvider;

var customIntegrationName =
var integrationName =
customFlags && customFlags['Rokt.integrationName'];
var integrationName = generateIntegrationName(customIntegrationName);
var noFunctional = customFlags && customFlags['Rokt.noFunctional'];
var noTargeting = customFlags && customFlags['Rokt.noTargeting'];

var launcherOptions = {
integrationName: generateIntegrationName(integrationName),
noFunctional: noFunctional,
noTargeting: noTargeting,
};

if (testMode) {
attachLauncher(accountId, integrationName);
attachLauncher(accountId, launcherOptions);
return;
}

Expand All @@ -86,7 +93,7 @@ var constructor = function () {
typeof window.Rokt.createLauncher === 'function' &&
window.Rokt.currentLauncher === undefined
) {
attachLauncher(accountId, integrationName);
attachLauncher(accountId, launcherOptions);
} else {
console.error(
'Rokt object is not available after script load.'
Expand Down Expand Up @@ -176,11 +183,13 @@ var constructor = function () {
delete self.userAttributes[key];
}

function attachLauncher(accountId, integrationName) {
window.Rokt.createLauncher({
accountId: accountId,
integrationName: integrationName,
})
function attachLauncher(accountId, launcherOptions) {
var options = mergeObjects(
{ accountId: accountId },
launcherOptions || {}
);

window.Rokt.createLauncher(options)
.then(function (launcher) {
// Assign the launcher to a global variable for later access
window.Rokt.currentLauncher = launcher;
Expand Down
56 changes: 56 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ describe('Rokt Forwarder', () => {
this.accountId = null;
this.sandbox = null;
this.integrationName = null;
this.noFunctional = null;
this.noTargeting = null;

this.createLauncherCalled = false;
this.createLauncher = function (options) {
self.accountId = options.accountId;
self.integrationName = options.integrationName;
self.noFunctional = options.noFunctional;
self.noTargeting = options.noTargeting;
self.createLauncherCalled = true;
self.isInitialized = true;

Expand Down Expand Up @@ -131,8 +135,60 @@ describe('Rokt Forwarder', () => {
);

window.Rokt.accountId.should.equal('123456');
window.Rokt.createLauncherCalled.should.equal(true);
});

it('should set optional settings from customFlags', async () => {
await mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true,
null,
{},
null,
null,
null,
{
'Rokt.integrationName': 'customName',
'Rokt.noFunctional': true,
'Rokt.noTargeting': true,
}
);

var expectedIntegrationName =
'mParticle_wsdkv_1.2.3_kitv_' +
require('../../package.json').version +
'_customName';

window.Rokt.createLauncherCalled.should.equal(true);
window.Rokt.accountId.should.equal('123456');
window.Rokt.integrationName.should.equal(expectedIntegrationName);
window.Rokt.noFunctional.should.equal(true);
window.Rokt.noTargeting.should.equal(true);
});

it('should not set optional settings when not in customFlags', async () => {
await mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true,
null,
{}
);

var expectedIntegrationName =
'mParticle_wsdkv_1.2.3_kitv_' +
require('../../package.json').version;

window.Rokt.createLauncherCalled.should.equal(true);
window.Rokt.accountId.should.equal('123456');
window.Rokt.integrationName.should.equal(expectedIntegrationName);
(window.Rokt.noFunctional === undefined).should.equal(true);
(window.Rokt.noTargeting === undefined).should.equal(true);
});

it('should set the filters on the forwarder', async () => {
Expand Down