Skip to content

Commit

Permalink
Fill currency parameters for Kobler adapter. (#6825)
Browse files Browse the repository at this point in the history
  • Loading branch information
acsbendi authored May 25, 2021
1 parent 585c710 commit 180ddaf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
11 changes: 9 additions & 2 deletions modules/koblerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ export const buildRequests = function (validBidRequests, bidderRequest) {
};

export const interpretResponse = function (serverResponse) {
const adServerPriceCurrency = config.getConfig('currency.adServerCurrency') || SUPPORTED_CURRENCY;
const res = serverResponse.body;
const bids = []
if (res) {
res.seatbid.forEach(sb => {
sb.bid.forEach(b => {
const adWithCorrectCurrency = b.adm
.replace(/\${AUCTION_PRICE_CURRENCY}/g, adServerPriceCurrency);
bids.push({
requestId: b.impid,
cpm: b.price,
Expand All @@ -42,7 +45,7 @@ export const interpretResponse = function (serverResponse) {
dealId: b.dealid,
netRevenue: true,
ttl: TIME_TO_LIVE_IN_SECONDS,
ad: b.adm,
ad: adWithCorrectCurrency,
nurl: b.nurl,
meta: {
advertiserDomains: b.adomain
Expand All @@ -56,10 +59,14 @@ export const interpretResponse = function (serverResponse) {

export const onBidWon = function (bid) {
const cpm = bid.cpm || 0;
const cpmCurrency = bid.currency || SUPPORTED_CURRENCY;
const adServerPrice = utils.deepAccess(bid, 'adserverTargeting.hb_pb', 0);
const adServerPriceCurrency = config.getConfig('currency.adServerCurrency') || SUPPORTED_CURRENCY;
if (utils.isStr(bid.nurl) && bid.nurl !== '') {
const winNotificationUrl = utils.replaceAuctionPrice(bid.nurl, cpm)
.replace(/\${AD_SERVER_PRICE}/g, adServerPrice);
.replace(/\${AUCTION_PRICE_CURRENCY}/g, cpmCurrency)
.replace(/\${AD_SERVER_PRICE}/g, adServerPrice)
.replace(/\${AD_SERVER_PRICE_CURRENCY}/g, adServerPriceCurrency);
utils.triggerPixel(winNotificationUrl);
}
};
Expand Down
31 changes: 21 additions & 10 deletions test/spec/modules/koblerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ describe('KoblerAdapter', function () {
});

it('should generate bids from OpenRTB response', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'NOK'
}
});
const responseWithTwoBids = {
body: {
seatbid: [
Expand All @@ -521,25 +526,25 @@ describe('KoblerAdapter', function () {
{
impid: '6194ddef-89a4-404f-9efd-6b718fc23308',
price: 7.981,
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&asp=${AD_SERVER_PRICE}',
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}',
crid: 'edea9b03-3a57-41aa-9c00-abd673e22006',
dealid: '',
w: 320,
h: 250,
adm: '<script src="https://atag.essrtb.com/serve/prebid_ad_tag?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}"></script>',
adm: '<script src="https://atag.essrtb.com/serve/prebid_ad_tag?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&cur=${AUCTION_PRICE_CURRENCY}"></script>',
adomain: [
'https://kobler.no'
]
},
{
impid: '2ec0b40f-d3ca-4ba5-8ce3-48290565690f',
price: 6.71234,
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}&asp=${AD_SERVER_PRICE}',
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}',
crid: 'fa2d5af7-2678-4204-9023-44c526160742',
dealid: '2783483223432342',
w: 580,
h: 400,
adm: '<script src="https://atag.essrtb.com/serve/prebid_ad_tag?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}"></script>',
adm: '<script src="https://atag.essrtb.com/serve/prebid_ad_tag?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}&cur=${AUCTION_PRICE_CURRENCY}"></script>',
adomain: [
'https://bid.kobler.no'
]
Expand All @@ -563,8 +568,8 @@ describe('KoblerAdapter', function () {
dealId: '',
netRevenue: true,
ttl: 600,
ad: '<script src="https://atag.essrtb.com/serve/prebid_ad_tag?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}"></script>',
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&asp=${AD_SERVER_PRICE}',
ad: '<script src="https://atag.essrtb.com/serve/prebid_ad_tag?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&cur=NOK"></script>',
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}',
meta: {
advertiserDomains: [
'https://kobler.no'
Expand All @@ -581,8 +586,8 @@ describe('KoblerAdapter', function () {
dealId: '2783483223432342',
netRevenue: true,
ttl: 600,
ad: '<script src="https://atag.essrtb.com/serve/prebid_ad_tag?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}"></script>',
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}&asp=${AD_SERVER_PRICE}',
ad: '<script src="https://atag.essrtb.com/serve/prebid_ad_tag?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}&cur=NOK"></script>',
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}',
meta: {
advertiserDomains: [
'https://bid.kobler.no'
Expand Down Expand Up @@ -617,17 +622,23 @@ describe('KoblerAdapter', function () {
});

it('Should trigger pixel with replaced nurl if nurl is not empty', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'NOK'
}
});
spec.onBidWon({
cpm: 8.341,
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&asp=${AD_SERVER_PRICE}',
currency: 'NOK',
nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}',
adserverTargeting: {
hb_pb: 8
}
});

expect(utils.triggerPixel.callCount).to.be.equal(1);
expect(utils.triggerPixel.firstCall.args[0]).to.be.equal(
'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=8.341&asp=8'
'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=8.341&sp_cur=NOK&asp=8&asp_cur=NOK'
);
});
});
Expand Down

0 comments on commit 180ddaf

Please sign in to comment.