diff --git a/modules/taboolaBidAdapter.js b/modules/taboolaBidAdapter.js index dda4694a52c..3e7127f1ab7 100644 --- a/modules/taboolaBidAdapter.js +++ b/modules/taboolaBidAdapter.js @@ -114,6 +114,9 @@ const converter = ortbConverter({ bidResponse(buildBidResponse, bid, context) { const bidResponse = buildBidResponse(bid, context); bidResponse.nurl = bid.nurl; + if (bid.burl) { + bidResponse.burl = bid.burl; + } bidResponse.ad = replaceAuctionPrice(bid.adm, bid.price); if (bid.ext && bid.ext.dchain) { deepSetValue(bidResponse, 'meta.dchain', bid.ext.dchain); @@ -212,9 +215,20 @@ export const spec = { return bids; }, onBidWon: (bid) => { - if (bid.nurl) { + if (bid.nurl && !bid.deferBilling) { const resolvedNurl = replaceAuctionPrice(bid.nurl, bid.originalCpm); ajax(resolvedNurl); + bid.taboolaBillingFired = true; + } + }, + onBidBillable: (bid) => { + if (bid.taboolaBillingFired) { + return; + } + const billingUrl = bid.burl || bid.nurl; + if (billingUrl) { + const resolvedBillingUrl = replaceAuctionPrice(billingUrl, bid.originalCpm); + ajax(resolvedBillingUrl); } }, getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) { diff --git a/test/spec/modules/taboolaBidAdapter_spec.js b/test/spec/modules/taboolaBidAdapter_spec.js index 8219ec3e8e2..9c06d717a04 100644 --- a/test/spec/modules/taboolaBidAdapter_spec.js +++ b/test/spec/modules/taboolaBidAdapter_spec.js @@ -116,6 +116,89 @@ describe('Taboola Adapter', function () { spec.onBidWon(bid); expect(server.requests[0].url).to.equals('http://win.example.com/3.4') }); + + it('should not fire nurl when deferBilling is true', function () { + const nurl = 'http://win.example.com/${AUCTION_PRICE}'; + const bid = { + requestId: 1, + cpm: 2, + originalCpm: 3.4, + creativeId: 1, + ttl: 60, + netRevenue: true, + mediaType: 'banner', + ad: '...', + width: 300, + height: 250, + nurl: nurl, + deferBilling: true + } + spec.onBidWon(bid); + expect(server.requests.length).to.equal(0); + }); + }); + + describe('onBidBillable', function () { + it('onBidBillable exist as a function', () => { + expect(spec.onBidBillable).to.exist.and.to.be.a('function'); + }); + + it('should fire burl when available', function () { + const burl = 'http://billing.example.com/${AUCTION_PRICE}'; + const nurl = 'http://win.example.com/${AUCTION_PRICE}'; + const bid = { + requestId: 1, + cpm: 2, + originalCpm: 3.4, + creativeId: 1, + ttl: 60, + netRevenue: true, + mediaType: 'banner', + ad: '...', + width: 300, + height: 250, + nurl: nurl, + burl: burl + } + spec.onBidBillable(bid); + expect(server.requests[0].url).to.equals('http://billing.example.com/3.4'); + }); + + it('should fall back to nurl when burl is not available', function () { + const nurl = 'http://win.example.com/${AUCTION_PRICE}'; + const bid = { + requestId: 1, + cpm: 2, + originalCpm: 3.4, + creativeId: 1, + ttl: 60, + netRevenue: true, + mediaType: 'banner', + ad: '...', + width: 300, + height: 250, + nurl: nurl + } + spec.onBidBillable(bid); + expect(server.requests[0].url).to.equals('http://win.example.com/3.4'); + }); + + it('should not fire anything when neither burl nor nurl is available', function () { + const bid = { + requestId: 1, + cpm: 2, + originalCpm: 3.4, + creativeId: 1, + ttl: 60, + netRevenue: true, + mediaType: 'banner', + ad: '...', + width: 300, + height: 250 + } + spec.onBidBillable(bid); + expect(server.requests.length).to.equal(0); + }); }); describe('onTimeout', function () {