Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 7 additions & 3 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ var constructor = function () {
return;
}

if (!window.Rokt || !(window.Rokt && window.Rokt.currentLauncher)) {
if (window.Rokt && typeof window.Rokt.createLauncher === 'function') {
if (!window.Rokt.currentLauncher) {
attachLauncher(accountId, launcherOptions);
} else {
initRoktLauncher(window.Rokt.currentLauncher);
Comment thread
jaissica12 marked this conversation as resolved.
Outdated
}
} else {
var target = document.head || document.body;
var script = document.createElement('script');
script.type = 'text/javascript';
Expand Down Expand Up @@ -151,8 +157,6 @@ var constructor = function () {

target.appendChild(script);
captureTiming(PerformanceMarks.RoktScriptAppended);
} else {
console.warn('Unable to find Rokt on the page');
}
}
/**
Expand Down
50 changes: 50 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,14 @@ describe('Rokt Forwarder', () => {
});

it('should add a performance marker when the script is appended', async () => {
var savedRokt = window.mParticle.Rokt;
window.Rokt = undefined;
window.mParticle.Rokt = {
domain: 'apps.rokt.com',
attachKit: async () => Promise.resolve(),
filters: savedRokt.filters,
Comment thread
jaissica12 marked this conversation as resolved.
};

await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
Expand Down Expand Up @@ -724,6 +732,48 @@ describe('Rokt Forwarder', () => {

mockMessageQueue.length.should.equal(0);
});

it('should call createLauncher when launcher is embedded and not yet initialized', async () => {
await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
false,
null,
{}
);

await waitForCondition(() => window.mParticle.Rokt.attachKitCalled);

window.mParticle.Rokt.createLauncherCalled.should.equal(true);
});

it('should attach to existing launcher when currentLauncher already exists', async () => {
var existingLauncher = {
selectPlacements: function () {
return Promise.resolve({});
},
hashAttributes: function (attrs) {
return attrs;
},
};
window.Rokt.currentLauncher = existingLauncher;

await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
false,
null,
{}
);

await waitForCondition(() => window.mParticle.Rokt.attachKitCalled);

// Should not call createLauncher since launcher exists
window.mParticle.Rokt.createLauncherCalled.should.equal(false);

// Forwarder should be initialized and functional
window.mParticle.forwarder.isInitialized.should.equal(true);
});
});

describe('#selectPlacements', () => {
Expand Down
Loading