Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 28 additions & 10 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
self.filteredUser = {};
self.userAttributes = {};

self.integrationName = null;

/**
* Passes attributes to the Rokt Web SDK for client-side hashing
* @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
Expand All @@ -50,14 +52,21 @@
_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'];

Check failure on line 65 in src/Rokt-Kit.js

View workflow job for this annotation

GitHub Actions / Run Web Kit PR Workflow / Build and Test

Insert `⏎···········`
self.integrationName = generateIntegrationName(customIntegrationName);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Any reason to keep the integration name on the class? It's only used once, I'd just call it a local variable that passes into attachLauncher instead

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good callout.


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

Expand All @@ -78,7 +87,7 @@
typeof window.Rokt.createLauncher === 'function' &&
window.Rokt.currentLauncher === undefined
) {
attachLauncher(accountId);
attachLauncher(accountId, self.integrationName);
} else {
console.error(
'Rokt object is not available after script load.'
Expand Down Expand Up @@ -168,15 +177,10 @@
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 +278,20 @@
}
};

function generateIntegrationName(customIntegrationName) {
var name =
'mParticle_' +
'wsdkv_' +
window.mParticle.getVersion() +
'_kitv_' +
process.env.PACKAGE_VERSION;
Comment thread
alexs-mparticle marked this conversation as resolved.
Outdated

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

Copilot AI May 9, 2025

Copy link

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
Loading