Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confiant Rtd Provider : add message type check #9950

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
27 changes: 15 additions & 12 deletions modules/confiantRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function setupPage(config) {

if (config?.params?.shouldEmitBillableEvent) {
if (window.frames['cnftComm']) {
subscribeToConfiantCommFrame(window);
subscribeToConfiantCommFrame(window, propertyId);
} else {
setUpMutationObserver();
}
Expand All @@ -58,8 +58,8 @@ function setupPage(config) {
* Subscribe to window's message events to report Billable events
* @param {Window} targetWindow window instance to subscribe to
*/
function subscribeToConfiantCommFrame(targetWindow) {
targetWindow.addEventListener('message', reportBillableEvents);
function subscribeToConfiantCommFrame(targetWindow, propertyId) {
targetWindow.addEventListener('message', getEventHandlerFunction(propertyId));
}

let mutationObserver;
Expand All @@ -86,14 +86,18 @@ function setUpMutationObserver() {
/**
* Emit billable event when Confiant integration reports that it has monitored an impression
*/
function reportBillableEvents (e) {
events.emit(CONSTANTS.EVENTS.BILLABLE_EVENT, {
auctionId: e.data.auctionId,
billingId: generateUUID(),
transactionId: e.data.transactionId,
type: 'impression',
vendor: 'confiant'
});
function getEventHandlerFunction(propertyId) {
return function reportBillableEvent(e) {
if (e.data.type.indexOf('cnft:reportBillableEvent:' + propertyId) > -1) {
events.emit(CONSTANTS.EVENTS.BILLABLE_EVENT, {
auctionId: e.data.auctionId,
billingId: generateUUID(),
transactionId: e.data.transactionId,
type: 'impression',
vendor: 'confiant'
});
}
}
}

/**
Expand Down Expand Up @@ -123,6 +127,5 @@ export default {
setupPage,
subscribeToConfiantCommFrame,
setUpMutationObserver,
reportBillableEvents,
registerConfiantSubmodule
};
5 changes: 4 additions & 1 deletion test/spec/modules/confiantRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('Confiant RTD module', function () {
let listenerCallback;
const mockWindow = { addEventListener: (a, cb) => (listenerCallback = cb) };
let billableEventsCounter = 0;
const propertyId = 'fff';

events.on(CONSTANTS.EVENTS.BILLABLE_EVENT, (e) => {
if (e.vendor === 'confiant') {
Expand All @@ -57,15 +58,17 @@ describe('Confiant RTD module', function () {
}
});

subscribeToConfiantCommFrame(mockWindow);
subscribeToConfiantCommFrame(mockWindow, propertyId);
listenerCallback({
data: {
type: 'cnft:reportBillableEvent:' + propertyId,
auctionId: 'auctionId',
transactionId: 'transactionId'
}
});
listenerCallback({
data: {
type: 'cnft:reportBillableEvent:' + propertyId,
auctionId: 'auctionId',
transactionId: 'transactionId'
}
Expand Down