Skip to content

Commit df103dd

Browse files
SavelievTaras Saveliev
and
Taras Saveliev
authored
Yandex Bid Adapter: (#10152)
* added adServerCurrency support * fixed auction price values for nurl Co-authored-by: Taras Saveliev <[email protected]>
1 parent be01782 commit df103dd

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

modules/yandexBidAdapter.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { formatQS, deepAccess, triggerPixel, _each, _map } from '../src/utils.js
22
import { registerBidder } from '../src/adapters/bidderFactory.js';
33
import { BANNER, NATIVE } from '../src/mediaTypes.js'
44
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
5+
import { config } from '../src/config.js';
56

67
const BIDDER_CODE = 'yandex';
78
const BIDDER_URL = 'https://bs.yandex.ru/prebid';
@@ -76,9 +77,11 @@ export const spec = {
7677
timeout = bidderRequest.timeout;
7778
}
7879

80+
const adServerCurrency = config.getConfig('currency.adServerCurrency');
81+
7982
return validBidRequests.map((bidRequest) => {
8083
const { params } = bidRequest;
81-
const { targetRef, withCredentials = true } = params;
84+
const { targetRef, withCredentials = true, cur } = params;
8285

8386
const { pageId, impId } = extractPlacementIds(params);
8487

@@ -107,6 +110,11 @@ export const spec = {
107110
imp.bidfloorcur = bidfloor.currency;
108111
}
109112

113+
const currency = cur || adServerCurrency;
114+
if (currency) {
115+
queryParams['ssp-cur'] = currency;
116+
}
117+
110118
const queryParamsString = formatQS(queryParams);
111119
return {
112120
method: 'POST',
@@ -132,24 +140,13 @@ export const spec = {
132140
interpretResponse: interpretResponse,
133141

134142
onBidWon: function (bid) {
135-
let nurl = bid['nurl'];
143+
const nurl = bid['nurl'];
136144

137145
if (!nurl) {
138146
return;
139147
}
140148

141-
let cpm, currency;
142-
if (bid.hasOwnProperty('originalCurrency') && bid.hasOwnProperty('originalCpm')) {
143-
cpm = bid.originalCpm;
144-
currency = bid.originalCurrency;
145-
} else {
146-
cpm = bid.cpm;
147-
currency = bid.currency;
148-
}
149-
cpm = deepAccess(bid, 'adserverTargeting.hb_pb') || cpm;
150-
151-
const pixel = replaceAuctionPrice(nurl, cpm, currency);
152-
triggerPixel(pixel);
149+
triggerPixel(nurl);
153150
}
154151
}
155152

@@ -316,7 +313,7 @@ function interpretResponse(serverResponse, { bidRequest }) {
316313
width: bidReceived.w,
317314
height: bidReceived.h,
318315
creativeId: bidReceived.adid,
319-
nurl: bidReceived.nurl,
316+
nurl: replaceAuctionPrice(bidReceived.nurl, price, currency),
320317

321318
netRevenue: true,
322319
ttl: DEFAULT_TTL,

test/spec/modules/yandexBidAdapter_spec.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert, expect } from 'chai';
22
import { spec, NATIVE_ASSETS } from 'modules/yandexBidAdapter.js';
33
import { parseUrl } from 'src/utils.js';
44
import { BANNER, NATIVE } from '../../../src/mediaTypes';
5-
import {OPENRTB} from '../../../modules/rtbhouseBidAdapter';
5+
import { config } from '../../../src/config';
66

77
describe('Yandex adapter', function () {
88
describe('isBidRequestValid', function () {
@@ -90,6 +90,22 @@ describe('Yandex adapter', function () {
9090
expect(data.site.ref).to.equal('https://ya.ru/');
9191
});
9292

93+
it('should send currency if defined', function () {
94+
config.setConfig({
95+
currency: {
96+
adServerCurrency: 'USD'
97+
}
98+
});
99+
100+
const bannerRequest = getBidRequest();
101+
const requests = spec.buildRequests([bannerRequest], bidderRequest);
102+
const { url } = requests[0];
103+
const parsedRequestUrl = parseUrl(url);
104+
const { search: query } = parsedRequestUrl
105+
106+
expect(query['ssp-cur']).to.equal('USD');
107+
});
108+
93109
describe('banner', () => {
94110
it('should create valid banner object', () => {
95111
const bannerRequest = getBidRequest({
@@ -273,7 +289,7 @@ describe('Yandex adapter', function () {
273289
},
274290
});
275291
});
276-
})
292+
});
277293
});
278294

279295
describe('interpretResponse', function () {
@@ -294,6 +310,7 @@ describe('Yandex adapter', function () {
294310
'example.com'
295311
],
296312
adid: 'yabs.123=',
313+
nurl: 'https://example.com/nurl/?price=${AUCTION_PRICE}&cur=${AUCTION_CURRENCY}',
297314
}
298315
]
299316
}],
@@ -314,11 +331,12 @@ describe('Yandex adapter', function () {
314331
const rtbBid = result[0];
315332
expect(rtbBid.width).to.equal(300);
316333
expect(rtbBid.height).to.equal(250);
317-
expect(rtbBid.cpm).to.be.within(0.1, 0.5);
334+
expect(rtbBid.cpm).to.be.within(0.3, 0.3);
318335
expect(rtbBid.ad).to.equal('<!-- HTML/JS -->');
319336
expect(rtbBid.currency).to.equal('USD');
320337
expect(rtbBid.netRevenue).to.equal(true);
321338
expect(rtbBid.ttl).to.equal(180);
339+
expect(rtbBid.nurl).to.equal('https://example.com/nurl/?price=0.3&cur=USD');
322340

323341
expect(rtbBid.meta.advertiserDomains).to.deep.equal(['example.com']);
324342
});

0 commit comments

Comments
 (0)