Skip to content

Commit 32118d5

Browse files
feat: Expose Rokt launcher config options (#30)
1 parent 38b4903 commit 32118d5

2 files changed

Lines changed: 60 additions & 46 deletions

File tree

src/Rokt-Kit.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,22 @@ var constructor = function () {
5050
_service,
5151
testMode,
5252
_trackerId,
53-
filteredUserAttributes,
54-
filteredUserIdentities,
55-
appVersion,
56-
appName,
57-
customFlags
53+
filteredUserAttributes
5854
) {
5955
var accountId = settings.accountId;
6056
self.userAttributes = filteredUserAttributes;
6157
self.onboardingExpProvider = settings.onboardingExpProvider;
6258

63-
var integrationName =
64-
customFlags && customFlags['Rokt.integrationName'];
65-
var noFunctional = customFlags && customFlags['Rokt.noFunctional'];
66-
var noTargeting = customFlags && customFlags['Rokt.noTargeting'];
59+
var managerOptions = window.mParticle.Rokt.managerOptions || {};
60+
var sandbox = managerOptions.sandbox || false;
6761

68-
var launcherOptions = {
69-
integrationName: generateIntegrationName(integrationName),
70-
noFunctional: noFunctional,
71-
noTargeting: noTargeting,
72-
};
62+
var launcherOptions = window.mParticle.Rokt.launcherOptions || {};
63+
launcherOptions.integrationName = generateIntegrationName(
64+
launcherOptions.integrationName
65+
);
7366

7467
if (testMode) {
75-
attachLauncher(accountId, launcherOptions);
68+
attachLauncher(accountId, sandbox, launcherOptions);
7669
return;
7770
}
7871

@@ -93,7 +86,7 @@ var constructor = function () {
9386
typeof window.Rokt.createLauncher === 'function' &&
9487
window.Rokt.currentLauncher === undefined
9588
) {
96-
attachLauncher(accountId, launcherOptions);
89+
attachLauncher(accountId, sandbox, launcherOptions);
9790
} else {
9891
console.error(
9992
'Rokt object is not available after script load.'
@@ -183,9 +176,12 @@ var constructor = function () {
183176
delete self.userAttributes[key];
184177
}
185178

186-
function attachLauncher(accountId, launcherOptions) {
179+
function attachLauncher(accountId, sandbox, launcherOptions) {
187180
var options = mergeObjects(
188-
{ accountId: accountId },
181+
{
182+
accountId: accountId,
183+
sandbox: sandbox,
184+
},
189185
launcherOptions || {}
190186
);
191187

test/src/tests.js

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe('Rokt Forwarder', () => {
7878
self.noTargeting = options.noTargeting;
7979
self.createLauncherCalled = true;
8080
self.isInitialized = true;
81+
self.sandbox = options.sandbox;
8182

8283
return Promise.resolve({
8384
then: function (callback) {
@@ -98,6 +99,8 @@ describe('Rokt Forwarder', () => {
9899

99100
afterEach(() => {
100101
window.mParticle.forwarder.userAttributes = {};
102+
delete window.mParticle.forwarder.launcherOptions;
103+
delete window.mParticle.Rokt.launcherOptions;
101104
});
102105

103106
describe('#initForwarder', () => {
@@ -138,57 +141,70 @@ describe('Rokt Forwarder', () => {
138141
window.Rokt.createLauncherCalled.should.equal(true);
139142
});
140143

141-
it('should set optional settings from customFlags', async () => {
144+
it('should set sandbox to true if sandbox is true in managerOptions', async () => {
145+
window.mParticle.Rokt.managerOptions = {
146+
sandbox: true,
147+
};
148+
142149
await mParticle.forwarder.init(
143150
{
144151
accountId: '123456',
145152
},
146153
reportService.cb,
147-
true,
148-
null,
149-
{},
150-
null,
151-
null,
152-
null,
153-
{
154-
'Rokt.integrationName': 'customName',
155-
'Rokt.noFunctional': true,
156-
'Rokt.noTargeting': true,
157-
}
154+
true
158155
);
159156

160-
var expectedIntegrationName =
161-
'mParticle_wsdkv_1.2.3_kitv_' +
162-
require('../../package.json').version +
163-
'_customName';
157+
window.Rokt.createLauncherCalled.should.equal(true);
158+
window.Rokt.sandbox.should.equal(true);
159+
});
160+
161+
it('should set sandbox to false if sandbox is false in managerOptions', async () => {
162+
window.mParticle.Rokt.managerOptions = {
163+
sandbox: false,
164+
};
165+
166+
await mParticle.forwarder.init(
167+
{
168+
accountId: '123456',
169+
},
170+
reportService.cb,
171+
true
172+
);
164173

165174
window.Rokt.createLauncherCalled.should.equal(true);
166-
window.Rokt.accountId.should.equal('123456');
167-
window.Rokt.integrationName.should.equal(expectedIntegrationName);
168-
window.Rokt.noFunctional.should.equal(true);
169-
window.Rokt.noTargeting.should.equal(true);
175+
window.Rokt.sandbox.should.equal(false);
170176
});
171177

172-
it('should not set optional settings when not in customFlags', async () => {
178+
it('should set optional settings from launcherOptions', async () => {
179+
window.mParticle.Rokt.launcherOptions = {
180+
integrationName: 'customName',
181+
noFunctional: true,
182+
noTargeting: true,
183+
};
184+
173185
await mParticle.forwarder.init(
174186
{
175187
accountId: '123456',
176188
},
177189
reportService.cb,
178190
true,
179191
null,
180-
{}
192+
{},
193+
null,
194+
null,
195+
null
181196
);
182197

183198
var expectedIntegrationName =
184199
'mParticle_wsdkv_1.2.3_kitv_' +
185-
require('../../package.json').version;
200+
require('../../package.json').version +
201+
'_customName';
186202

187203
window.Rokt.createLauncherCalled.should.equal(true);
188204
window.Rokt.accountId.should.equal('123456');
189205
window.Rokt.integrationName.should.equal(expectedIntegrationName);
190-
(window.Rokt.noFunctional === undefined).should.equal(true);
191-
(window.Rokt.noTargeting === undefined).should.equal(true);
206+
window.Rokt.noFunctional.should.equal(true);
207+
window.Rokt.noTargeting.should.equal(true);
192208
});
193209

194210
it('should set the filters on the forwarder', async () => {
@@ -244,7 +260,7 @@ describe('Rokt Forwarder', () => {
244260
);
245261
});
246262

247-
it('should append custom integration name to integrationName if customFlags is passed', async () => {
263+
it('should append custom integration name to integrationName if passed in launcherOptions', async () => {
248264
const packageVersion = require('../../package.json').version;
249265
const customIntegrationName = 'myCustomIntegration';
250266

@@ -255,6 +271,9 @@ describe('Rokt Forwarder', () => {
255271
window.mParticle.Rokt.attachKitCalled = true;
256272
return Promise.resolve();
257273
};
274+
window.mParticle.Rokt.launcherOptions = {
275+
integrationName: customIntegrationName,
276+
};
258277

259278
// Simulate the forwarder appending the custom integration name
260279
window.Rokt.integrationName =
@@ -273,8 +292,7 @@ describe('Rokt Forwarder', () => {
273292
{},
274293
null,
275294
null,
276-
null,
277-
{ 'Rokt.integrationName': customIntegrationName }
295+
null
278296
);
279297

280298
window.Rokt.integrationName.should.equal(

0 commit comments

Comments
 (0)