Skip to content

Commit

Permalink
Geoedge RTD module: support billing events (prebid#9267)
Browse files Browse the repository at this point in the history
* Add billable events for applicable winning bids

* Update test for billable events

* Add meta bid advertiser domains collection

* Revert "Add meta bid advertiser domains collection"

This reverts commit 09c19c9.

* Add meta bid advertiser domains collection

* Update geoedgeRtdProvider_spec.js

Force circleci

Co-authored-by: daniel manan <mmndaniel@gmail.com>
Co-authored-by: Patrick McCann <patmmccann@gmail.com>
  • Loading branch information
3 people authored and jorgeluisrocha committed May 18, 2023
1 parent 69c975e commit 5d067dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/geoedgeRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import { submodule } from '../src/hook.js';
import { ajax } from '../src/ajax.js';
import { generateUUID, insertElement, isEmpty, logError } from '../src/utils.js';
import * as events from '../src/events.js';
import CONSTANTS from '../src/constants.json';

/** @type {string} */
const SUBMODULE_NAME = 'geoedge';
Expand Down Expand Up @@ -105,6 +107,7 @@ function getMacros(bid, key) {
'%%PATTERN:hb_bidder%%': bid.bidderCode,
'%_isHb!': true,
'%_hbcid!': bid.creativeId || '',
'%_hbadomains': bid.meta && bid.meta.advertiserDomains,
'%%PATTERN:hb_pb%%': bid.pbHg,
'%%SITE%%': location.hostname,
'%_pimp%': PV_ID
Expand Down Expand Up @@ -184,13 +187,32 @@ function conditionallyWrap(bidResponse, config, userConsent) {
}
}

/**
* Fire billable events for applicable bids
*/
function fireBillableEventsForApplicableBids(params) {
events.on(CONSTANTS.EVENTS.BID_WON, function (winningBid) {
if (shouldWrap(winningBid, params)) {
events.emit(CONSTANTS.EVENTS.BILLABLE_EVENT, {
vendor: SUBMODULE_NAME,
billingId: generateUUID(),
type: 'impression',
transactionId: winningBid.transactionId,
auctionId: winningBid.auctionId,
bidId: winningBid.requestId
});
}
});
}

function init(config, userConsent) {
let params = config.params;
if (!params || !params.key) {
logError('missing key for geoedge RTD module provider');
return false;
}
preloadClient(params.key);
fireBillableEventsForApplicableBids(params);
return true;
}

Expand Down
15 changes: 15 additions & 0 deletions test/spec/modules/geoedgeRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as utils from '../../../src/utils.js';
import * as hook from '../../../src/hook.js'
import { beforeInit, geoedgeSubmodule, setWrapper, wrapper, htmlPlaceholder, WRAPPER_URL, getClientUrl } from '../../../modules/geoedgeRtdProvider.js';
import { server } from '../../../test/mocks/xhr.js';
import * as events from '../../../src/events.js';
import CONSTANTS from '../../../src/constants.json';

let key = '123123123';
function makeConfig() {
Expand Down Expand Up @@ -88,6 +90,19 @@ describe('Geoedge RTD module', function () {
let isLinkPreloadAsScript = arg => arg.tagName === 'LINK' && arg.rel === 'preload' && arg.as === 'script' && arg.href === getClientUrl(key);
expect(insertElementStub.calledWith(sinon.match(isLinkPreloadAsScript))).to.equal(true);
});
it('should emit billable events with applicable winning bids', function () {
let applicableBid = mockBid('bidderA');
let nonApplicableBid = mockBid('bidderB');
let counter = 0;
events.on(CONSTANTS.EVENTS.BILLABLE_EVENT, function (event) {
if (event.vendor === 'geoedge' && event.type === 'impression') {
counter += 1;
}
});
events.emit(CONSTANTS.EVENTS.BID_WON, applicableBid);
events.emit(CONSTANTS.EVENTS.BID_WON, nonApplicableBid);
expect(counter).to.equal(1);
});
});
describe('onBidResponseEvent', function () {
let bidFromA = mockBid('bidderA');
Expand Down

0 comments on commit 5d067dd

Please sign in to comment.