diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index 1730adf..f92bca2 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -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; @@ -137,6 +140,7 @@ var constructor = function () { }; target.appendChild(script); + captureTiming(PerformanceMarks.RoktScriptAppended); } else { console.warn('Unable to find Rokt on the page'); } @@ -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) { diff --git a/test/src/tests.js b/test/src/tests.js index fc073a4..87367ef 100644 --- a/test/src/tests.js +++ b/test/src/tests.js @@ -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 @@ -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 () => {