Skip to content

Commit 1180363

Browse files
fix: Update integrationName to support postfix (#28)
1 parent 768e6f7 commit 1180363

2 files changed

Lines changed: 65 additions & 10 deletions

File tree

src/Rokt-Kit.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,22 @@ var constructor = function () {
5050
_service,
5151
testMode,
5252
_trackerId,
53-
filteredUserAttributes
53+
filteredUserAttributes,
54+
filteredUserIdentities,
55+
appVersion,
56+
appName,
57+
customFlags
5458
) {
5559
var accountId = settings.accountId;
5660
self.userAttributes = filteredUserAttributes;
5761
self.onboardingExpProvider = settings.onboardingExpProvider;
5862

63+
var customIntegrationName =
64+
customFlags && customFlags['Rokt.integrationName'];
65+
var integrationName = generateIntegrationName(customIntegrationName);
66+
5967
if (testMode) {
60-
attachLauncher(accountId);
68+
attachLauncher(accountId, integrationName);
6169
return;
6270
}
6371

@@ -78,7 +86,7 @@ var constructor = function () {
7886
typeof window.Rokt.createLauncher === 'function' &&
7987
window.Rokt.currentLauncher === undefined
8088
) {
81-
attachLauncher(accountId);
89+
attachLauncher(accountId, integrationName);
8290
} else {
8391
console.error(
8492
'Rokt object is not available after script load.'
@@ -168,15 +176,10 @@ var constructor = function () {
168176
delete self.userAttributes[key];
169177
}
170178

171-
function attachLauncher(accountId) {
179+
function attachLauncher(accountId, integrationName) {
172180
window.Rokt.createLauncher({
173181
accountId: accountId,
174-
integrationName:
175-
'mParticle_' +
176-
'wsdkv_' +
177-
window.mParticle.getVersion() +
178-
'_kitv_' +
179-
process.env.PACKAGE_VERSION,
182+
integrationName: integrationName,
180183
})
181184
.then(function (launcher) {
182185
// Assign the launcher to a global variable for later access
@@ -274,6 +277,17 @@ var constructor = function () {
274277
}
275278
};
276279

280+
function generateIntegrationName(customIntegrationName) {
281+
var coreSdkVersion = window.mParticle.getVersion();
282+
var kitVersion = process.env.PACKAGE_VERSION;
283+
var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
284+
285+
if (customIntegrationName) {
286+
name += '_' + customIntegrationName;
287+
}
288+
return name;
289+
}
290+
277291
function getId() {
278292
return moduleId;
279293
}

test/src/tests.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,47 @@ describe('Rokt Forwarder', () => {
187187
'mParticle_wsdkv_1.2.3_kitv_' + packageVersion
188188
);
189189
});
190+
191+
it('should append custom integration name to integrationName if customFlags is passed', async () => {
192+
const packageVersion = require('../../package.json').version;
193+
const customIntegrationName = 'myCustomIntegration';
194+
195+
window.Rokt = new MockRoktForwarder();
196+
window.mParticle.Rokt = window.Rokt;
197+
window.mParticle.Rokt.attachKitCalled = false;
198+
window.mParticle.Rokt.attachKit = async () => {
199+
window.mParticle.Rokt.attachKitCalled = true;
200+
return Promise.resolve();
201+
};
202+
203+
// Simulate the forwarder appending the custom integration name
204+
window.Rokt.integrationName =
205+
'mParticle_wsdkv_1.2.3_kitv_' +
206+
packageVersion +
207+
'_' +
208+
customIntegrationName;
209+
210+
await mParticle.forwarder.init(
211+
{
212+
accountId: '123456',
213+
},
214+
reportService.cb,
215+
true,
216+
null,
217+
{},
218+
null,
219+
null,
220+
null,
221+
{ 'Rokt.integrationName': customIntegrationName }
222+
);
223+
224+
window.Rokt.integrationName.should.equal(
225+
'mParticle_wsdkv_1.2.3_kitv_' +
226+
packageVersion +
227+
'_' +
228+
customIntegrationName
229+
);
230+
});
190231
});
191232

192233
describe('#hashAttributes', () => {

0 commit comments

Comments
 (0)