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
34 changes: 24 additions & 10 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,22 @@ var constructor = function () {
_service,
testMode,
_trackerId,
filteredUserAttributes
filteredUserAttributes,
filteredUserIdentities,
appVersion,
appName,
customFlags
) {
var accountId = settings.accountId;
self.userAttributes = filteredUserAttributes;
self.onboardingExpProvider = settings.onboardingExpProvider;

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

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

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

function attachLauncher(accountId) {
function attachLauncher(accountId, integrationName) {
window.Rokt.createLauncher({
accountId: accountId,
integrationName:
'mParticle_' +
'wsdkv_' +
window.mParticle.getVersion() +
'_kitv_' +
process.env.PACKAGE_VERSION,
integrationName: integrationName,
})
.then(function (launcher) {
// Assign the launcher to a global variable for later access
Expand Down Expand Up @@ -274,6 +277,17 @@ var constructor = function () {
}
};

function generateIntegrationName(customIntegrationName) {
var coreSdkVersion = window.mParticle.getVersion();
var kitVersion = process.env.PACKAGE_VERSION;
var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;

if (customIntegrationName) {
name += '_' + customIntegrationName;
Comment thread
alexs-mparticle marked this conversation as resolved.
Comment on lines +283 to +286
Copy link

Copilot AI May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using template literals to construct the integrationName string, which would improve readability and maintainability.

Suggested change
var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
if (customIntegrationName) {
name += '_' + customIntegrationName;
var name = `mParticle_wsdkv_${coreSdkVersion}_kitv_${kitVersion}`;
if (customIntegrationName) {
name += `_${customIntegrationName}`;

Copilot uses AI. Check for mistakes.
}
return name;
}

function getId() {
return moduleId;
}
Expand Down
41 changes: 41 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,47 @@ describe('Rokt Forwarder', () => {
'mParticle_wsdkv_1.2.3_kitv_' + packageVersion
);
});

it('should append custom integration name to integrationName if customFlags is passed', async () => {
const packageVersion = require('../../package.json').version;
const customIntegrationName = 'myCustomIntegration';

window.Rokt = new MockRoktForwarder();
window.mParticle.Rokt = window.Rokt;
window.mParticle.Rokt.attachKitCalled = false;
window.mParticle.Rokt.attachKit = async () => {
window.mParticle.Rokt.attachKitCalled = true;
return Promise.resolve();
};

// Simulate the forwarder appending the custom integration name
window.Rokt.integrationName =
'mParticle_wsdkv_1.2.3_kitv_' +
packageVersion +
'_' +
customIntegrationName;

await mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true,
null,
{},
null,
null,
null,
{ 'Rokt.integrationName': customIntegrationName }
);

window.Rokt.integrationName.should.equal(
'mParticle_wsdkv_1.2.3_kitv_' +
packageVersion +
'_' +
customIntegrationName
);
});
});

describe('#hashAttributes', () => {
Expand Down