Skip to content

Commit a6ad782

Browse files
fix: Update attachLauncher to use options object for integration settings (#29)
1 parent 1180363 commit a6ad782

2 files changed

Lines changed: 74 additions & 9 deletions

File tree

src/Rokt-Kit.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,19 @@ var constructor = function () {
6060
self.userAttributes = filteredUserAttributes;
6161
self.onboardingExpProvider = settings.onboardingExpProvider;
6262

63-
var customIntegrationName =
63+
var integrationName =
6464
customFlags && customFlags['Rokt.integrationName'];
65-
var integrationName = generateIntegrationName(customIntegrationName);
65+
var noFunctional = customFlags && customFlags['Rokt.noFunctional'];
66+
var noTargeting = customFlags && customFlags['Rokt.noTargeting'];
67+
68+
var launcherOptions = {
69+
integrationName: generateIntegrationName(integrationName),
70+
noFunctional: noFunctional,
71+
noTargeting: noTargeting,
72+
};
6673

6774
if (testMode) {
68-
attachLauncher(accountId, integrationName);
75+
attachLauncher(accountId, launcherOptions);
6976
return;
7077
}
7178

@@ -86,7 +93,7 @@ var constructor = function () {
8693
typeof window.Rokt.createLauncher === 'function' &&
8794
window.Rokt.currentLauncher === undefined
8895
) {
89-
attachLauncher(accountId, integrationName);
96+
attachLauncher(accountId, launcherOptions);
9097
} else {
9198
console.error(
9299
'Rokt object is not available after script load.'
@@ -176,11 +183,13 @@ var constructor = function () {
176183
delete self.userAttributes[key];
177184
}
178185

179-
function attachLauncher(accountId, integrationName) {
180-
window.Rokt.createLauncher({
181-
accountId: accountId,
182-
integrationName: integrationName,
183-
})
186+
function attachLauncher(accountId, launcherOptions) {
187+
var options = mergeObjects(
188+
{ accountId: accountId },
189+
launcherOptions || {}
190+
);
191+
192+
window.Rokt.createLauncher(options)
184193
.then(function (launcher) {
185194
// Assign the launcher to a global variable for later access
186195
window.Rokt.currentLauncher = launcher;

test/src/tests.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ describe('Rokt Forwarder', () => {
6767
this.accountId = null;
6868
this.sandbox = null;
6969
this.integrationName = null;
70+
this.noFunctional = null;
71+
this.noTargeting = null;
7072

7173
this.createLauncherCalled = false;
7274
this.createLauncher = function (options) {
7375
self.accountId = options.accountId;
7476
self.integrationName = options.integrationName;
77+
self.noFunctional = options.noFunctional;
78+
self.noTargeting = options.noTargeting;
7579
self.createLauncherCalled = true;
7680
self.isInitialized = true;
7781

@@ -131,8 +135,60 @@ describe('Rokt Forwarder', () => {
131135
);
132136

133137
window.Rokt.accountId.should.equal('123456');
138+
window.Rokt.createLauncherCalled.should.equal(true);
139+
});
140+
141+
it('should set optional settings from customFlags', async () => {
142+
await mParticle.forwarder.init(
143+
{
144+
accountId: '123456',
145+
},
146+
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+
}
158+
);
159+
160+
var expectedIntegrationName =
161+
'mParticle_wsdkv_1.2.3_kitv_' +
162+
require('../../package.json').version +
163+
'_customName';
164+
165+
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);
170+
});
171+
172+
it('should not set optional settings when not in customFlags', async () => {
173+
await mParticle.forwarder.init(
174+
{
175+
accountId: '123456',
176+
},
177+
reportService.cb,
178+
true,
179+
null,
180+
{}
181+
);
182+
183+
var expectedIntegrationName =
184+
'mParticle_wsdkv_1.2.3_kitv_' +
185+
require('../../package.json').version;
134186

135187
window.Rokt.createLauncherCalled.should.equal(true);
188+
window.Rokt.accountId.should.equal('123456');
189+
window.Rokt.integrationName.should.equal(expectedIntegrationName);
190+
(window.Rokt.noFunctional === undefined).should.equal(true);
191+
(window.Rokt.noTargeting === undefined).should.equal(true);
136192
});
137193

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

0 commit comments

Comments
 (0)