Skip to content

Commit

Permalink
Browsi RTD Module: add support for page view billable events (prebid#…
Browse files Browse the repository at this point in the history
…8829)

* real time data module,
browsi sub module for real time data,
new hook bidsBackCallback,
fix for config unsubscribe

* change timeout&primary ad server only to auctionDelay
update docs

* support multiple providers

* change promise to callbacks
configure submodule on submodules.json

* bug fixes

* use Prebid ajax

* tests fix

* browsi real time data provider improvements

* real time data module,
browsi sub module for real time data,
new hook bidsBackCallback,
fix for config unsubscribe

* change timeout&primary ad server only to auctionDelay
update docs

* support multiple providers

* change promise to callbacks
configure submodule on submodules.json

* bug fixes

* use Prebid ajax

* tests fix

* browsi real time data provider improvements

* Browsi RTD provider - add billiable event type

* Browsi RTD provider - add billiable event type

* lint fixes
  • Loading branch information
omerDotan authored and jorgeluisrocha committed May 18, 2023
1 parent 4e6d889 commit a8f1e7b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 11 deletions.
34 changes: 24 additions & 10 deletions modules/browsiRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ export function addBrowsiTag(data) {
return script;
}

export function sendPageviewEvent(eventType) {
if (eventType === 'PAGEVIEW') {
events.emit(CONSTANTS.EVENTS.BILLABLE_EVENT, {
vendor: 'browsi',
type: 'pageview',
billingId: generateUUID()
})
}
}

/**
* collect required data from page
* send data to browsi server to get predictions
Expand Down Expand Up @@ -262,10 +272,11 @@ function getPredictionsFromServer(url) {
try {
const data = JSON.parse(response);
if (data && data.p && data.kn) {
setData({p: data.p, kn: data.kn, pmd: data.pmd});
setData({p: data.p, kn: data.kn, pmd: data.pmd, bet: data.bet});
} else {
setData({});
}
sendPageviewEvent(data.bet);
addBrowsiTag(data);
} catch (err) {
logError('unable to parse data');
Expand Down Expand Up @@ -336,19 +347,22 @@ export const browsiSubmodule = {

function getTargetingData(uc, c, us, a) {
const targetingData = getRTD(uc);
const auctionId = a.auctionId
const auctionId = a.auctionId;
const sendAdRequestEvent = _browsiData['bet'] === 'AD_REQUEST';
uc.forEach(auc => {
if (isNumber(_ic[auc])) {
_ic[auc] = _ic[auc] + 1;
}
const transactionId = a.adUnits.find(adUnit => adUnit.code === auc).transactionId;
events.emit(CONSTANTS.EVENTS.BILLABLE_EVENT, {
vendor: 'browsi',
type: 'adRequest',
billingId: generateUUID(),
transactionId: transactionId,
auctionId: auctionId
})
if (sendAdRequestEvent) {
const transactionId = a.adUnits.find(adUnit => adUnit.code === auc).transactionId;
events.emit(CONSTANTS.EVENTS.BILLABLE_EVENT, {
vendor: 'browsi',
type: 'adRequest',
billingId: generateUUID(),
transactionId: transactionId,
auctionId: auctionId
})
}
});
logInfo('Browsi RTD provider returned targeting data', targetingData, 'for', uc)
return targetingData;
Expand Down
41 changes: 40 additions & 1 deletion test/spec/modules/browsiRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {makeSlot} from '../integration/faker/googletag.js';
import * as utils from '../../../src/utils'
import * as events from '../../../src/events';
import * as sinon from 'sinon';
import {sendPageviewEvent} from '../../../modules/browsiRtdProvider.js';

describe('browsi Real time data sub module', function () {
const conf = {
Expand Down Expand Up @@ -160,7 +161,19 @@ describe('browsi Real time data sub module', function () {
})
})

describe('should emit billable event', function () {
describe('should emit ad request billable event', function () {
before(() => {
const data = {
p: {
'adUnit1': {ps: {0: 0.234}},
'adUnit2': {ps: {0: 0.134}}},
kn: 'bv',
pmd: undefined,
bet: 'AD_REQUEST'
};
browsiRTD.setData(data);
})

beforeEach(() => {
eventsEmitSpy.resetHistory();
})
Expand Down Expand Up @@ -232,4 +245,30 @@ describe('browsi Real time data sub module', function () {
expect(callArguments).to.eql(expectedCall);
})
})

describe('should emit pageveiw billable event', function () {
beforeEach(() => {
eventsEmitSpy.resetHistory();
})
it('should send event if type is correct', function () {
sendPageviewEvent('PAGEVIEW')

const expectedCall = {
vendor: 'browsi',
type: 'pageview',
}

expect(eventsEmitSpy.callCount).to.equal(1);
const callArguments = eventsEmitSpy.getCalls()[0].args[1];
// billing id is random, we can't check its value
delete callArguments['billingId'];
expect(callArguments).to.eql(expectedCall);
})
it('should not send event if type is incorrect', function () {
sendPageviewEvent('AD_REQUEST');
sendPageviewEvent('INACTIVE');
sendPageviewEvent(undefined);
expect(eventsEmitSpy.callCount).to.equal(0);
})
})
});

0 comments on commit a8f1e7b

Please sign in to comment.