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
15 changes: 15 additions & 0 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var constructor = function () {
var self = this;
var EMAIL_SHA256_IDENTITY = 'emailsha256';
var OTHER_IDENTITY = 'other';
var PerformanceMarks = {
RoktScriptAppended: 'mp:RoktScriptAppended',
};

self.name = name;
self.moduleId = moduleId;
Expand Down Expand Up @@ -137,6 +140,7 @@ var constructor = function () {
};

target.appendChild(script);
captureTiming(PerformanceMarks.RoktScriptAppended);
} else {
console.warn('Unable to find Rokt on the page');
}
Expand Down Expand Up @@ -444,6 +448,17 @@ var constructor = function () {
var LOCAL_LAUNCHER_TEST_GROUP_THRESHOLD = 0.5;
return Math.random() > LOCAL_LAUNCHER_TEST_GROUP_THRESHOLD;
}

function captureTiming(metricName) {
if (
window &&
window.mParticle &&
window.mParticle.captureTiming &&
metricName
) {
window.mParticle.captureTiming(metricName);
}
}
};

function generateIntegrationName(customIntegrationName) {
Expand Down
21 changes: 21 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ describe('Rokt Forwarder', () => {
window.mParticle.Rokt = window.Rokt;
window.mParticle.Rokt.attachKitCalled = false;

// Ensure currentLauncher is undefined to trigger script appending
window.Rokt.currentLauncher = undefined;

// Set attachKit as async to allow for await calls in the test
// This is necessary to simiulate a race condition between the
// core sdk and the Rokt forwarder
Expand All @@ -567,6 +570,24 @@ describe('Rokt Forwarder', () => {
};
window.mParticle.config = undefined;
Math.random = () => 1;

window.mParticle.captureTiming = function (metricName) {
window.mParticle.Rokt.capturedPerformanceMetric = metricName;
};
});

it('should add a performance marker when the script is appended', async () => {
await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
false,
null,
{}
);

window.mParticle.Rokt.capturedPerformanceMetric.should.equal(
'mp:RoktScriptAppended'
);
});

it('should create a remote launcher if the partner is not in the local launcher test group', async () => {
Expand Down