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
30 changes: 30 additions & 0 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

var name = 'Rokt';
var moduleId = 181;
Comment thread
jaissica12 marked this conversation as resolved.
var EVENT_NAME_SELECT_PLACEMENTS = 'selectPlacements';

var constructor = function () {
var self = this;
Expand Down Expand Up @@ -255,9 +256,38 @@ var constructor = function () {
attributes: selectPlacementsAttributes,
});

// Log custom event for selectPlacements call
logSelectPlacementsEvent(selectPlacementsAttributes);

return self.launcher.selectPlacements(selectPlacementsOptions);
}

/**
* Logs a custom event when selectPlacements is called
* This enables visibility and troubleshooting
* @param {Object} attributes - The attributes sent to Rokt
*/
function logSelectPlacementsEvent(attributes) {
if (
!window.mParticle ||
typeof window.mParticle.logEvent !== 'function'
Comment thread
jaissica12 marked this conversation as resolved.
) {
return;
}

if (!isObject(attributes)) {
return;
}

var EVENT_TYPE_OTHER = window.mParticle.EventType.Other;

window.mParticle.logEvent(
EVENT_NAME_SELECT_PLACEMENTS,
EVENT_TYPE_OTHER,
attributes
);
Comment thread
jaissica12 marked this conversation as resolved.
}

/**
* Enables optional Integration Launcher extensions before selecting placements
* @param {string} extensionName - Name of the extension to enable
Expand Down
101 changes: 101 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ describe('Rokt Forwarder', () => {
mParticle.generateHash = function (input) {
return 'hashed-<' + input + '>-value';
};
// Mock for logEvent to capture custom event logging
mParticle.loggedEvents = [];
mParticle.logEvent = function (eventName, eventType, eventAttributes) {
mParticle.loggedEvents.push({
eventName: eventName,
eventType: eventType,
eventAttributes: eventAttributes,
});
};
Comment thread
jaissica12 marked this conversation as resolved.
// -------------------START EDITING BELOW:-----------------------
var MockRoktForwarder = function () {
var self = this;
Expand Down Expand Up @@ -734,6 +743,7 @@ describe('Rokt Forwarder', () => {
window.mParticle.Rokt.attachKitCalled = true;
return Promise.resolve();
};
mParticle.loggedEvents = [];
window.mParticle.Rokt.setLocalSessionAttribute = function (
key,
value
Expand Down Expand Up @@ -2495,6 +2505,97 @@ describe('Rokt Forwarder', () => {
);
});
});

describe('#logSelectPlacementsEvent', () => {
it('should log a custom event', async () => {
await window.mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true,
null,
{
'cached-user-attr': 'cached-value',
}
);

await window.mParticle.forwarder.selectPlacements({
identifier: 'test-placement',
attributes: {
'new-attr': 'new-value',
},
});

mParticle.loggedEvents.length.should.equal(1);
mParticle.loggedEvents[0].eventName.should.equal(
'selectPlacements'
);
mParticle.loggedEvents[0].eventType.should.equal(8); // EventType.Other

const eventAttributes =
mParticle.loggedEvents[0].eventAttributes;
eventAttributes.should.have.property('mpid');
Comment thread
rmi22186 marked this conversation as resolved.
});

it('should include merged user attributes, identities, and mpid', async () => {
await window.mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true,
null,
{
'cached-user-attr': 'cached-value',
}
);

await window.mParticle.forwarder.selectPlacements({
identifier: 'test-placement',
attributes: {
'new-attr': 'new-value',
},
});
Comment thread
jaissica12 marked this conversation as resolved.

const eventAttributes =
mParticle.loggedEvents[0].eventAttributes;

// eventAttributes should include merged attributes and mpid directly
eventAttributes.should.have.property('mpid', '123');
eventAttributes.should.have.property('new-attr', 'new-value');
eventAttributes.should.have.property(
'cached-user-attr',
'cached-value'
);
});

it('should skip logging when mParticle.logEvent is not available', async () => {
var originalLogEvent = window.mParticle.logEvent;
window.mParticle.logEvent = undefined;

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

await window.mParticle.forwarder.selectPlacements({
identifier: 'test-placement',
attributes: {
attr: 'value',
},
});

window.Rokt.selectPlacementsCalled.should.equal(true);
mParticle.loggedEvents.length.should.equal(0);
window.mParticle.logEvent = originalLogEvent;
});
});
});

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