Skip to content

Commit ca98d4a

Browse files
filipovmkomorski
authored andcommitted
Yandex Bid Adapter: Change request domain (#14012)
* Yandex Bid Adapter: The request domain has been changed * Bug fix after resolve conflicts
1 parent 935d386 commit ca98d4a

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

modules/yandexBidAdapter.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ import { isWebdriverEnabled } from '../libraries/webdriver/webdriver.js';
5050
* @typedef {BidRequest & AdditionalBidRequestFields} ExtendedBidRequest
5151
*/
5252

53+
const BIDDER_DOMAIN = 'yandex.com';
54+
5355
const BIDDER_CODE = 'yandex';
54-
const BIDDER_URL = 'https://yandex.ru/ads/prebid';
55-
const EVENT_TRACKER_URL = 'https://yandex.ru/ads/trace';
56+
const BIDDER_URL = '/ads/prebid';
57+
const EVENT_TRACKER_URL = '/ads/trace';
5658
// We send data in 1% of cases
5759
const DEFAULT_SAMPLING_RATE = 0.01;
5860
const EVENT_LOG_RANDOM_NUMBER = Math.random();
@@ -70,7 +72,7 @@ const ORTB_MTYPES = {
7072
};
7173

7274
const SSP_ID = 10500;
73-
const ADAPTER_VERSION = '2.8.0';
75+
const ADAPTER_VERSION = '2.9.0';
7476

7577
const TRACKER_METHODS = {
7678
img: 1,
@@ -164,11 +166,14 @@ export const spec = {
164166

165167
const { pageId, impId } = extractPlacementIds(params);
166168

169+
const domain = getBidderDomain();
170+
167171
const queryParams = {
168172
'imp-id': impId,
169173
'target-ref': targetRef || ortb2?.site?.domain,
170174
'adapter-version': ADAPTER_VERSION,
171175
'ssp-id': SSP_ID,
176+
domain,
172177
};
173178

174179
const gdprApplies = Boolean(deepAccess(bidderRequest, 'gdprConsent.gdprApplies'));
@@ -247,7 +252,7 @@ export const spec = {
247252

248253
const request = {
249254
method: 'POST',
250-
url: BIDDER_URL + `/${pageId}?${queryParamsString}`,
255+
url: `https://${domain}${BIDDER_URL}/${pageId}?${queryParamsString}`,
251256
data,
252257
options: {
253258
withCredentials,
@@ -287,10 +292,7 @@ export const spec = {
287292
},
288293
onBidderError: function({ error, bidderRequest }) {
289294
eventLog('PREBID_BIDDER_ERROR_EVENT', {
290-
error: {
291-
message: error?.reason?.message,
292-
stack: error?.reason?.stack,
293-
},
295+
error,
294296
bidderRequest,
295297
});
296298
},
@@ -636,10 +638,17 @@ function eventLog(name, resp) {
636638
data: resp,
637639
};
638640

639-
ajax(EVENT_TRACKER_URL, undefined, JSON.stringify(data), { method: 'POST', withCredentials: true });
641+
const domain = getBidderDomain();
642+
643+
ajax(`https://${domain}${EVENT_TRACKER_URL}`, undefined, JSON.stringify(data), { method: 'POST', withCredentials: true });
640644
}
641645
}
642646

647+
function getBidderDomain() {
648+
const bidderConfig = pbjsConfig.getConfig();
649+
return bidderConfig?.yandex?.domain ?? BIDDER_DOMAIN;
650+
}
651+
643652
/**
644653
* Determines the appropriate window context for a given DOM element by checking
645654
* its presence in the current window's DOM or the top-level window's DOM.

test/spec/modules/yandexBidAdapter_spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,34 @@ describe('Yandex adapter', function () {
193193
},
194194
};
195195

196+
it('create a valid banner request with custom domain', function () {
197+
config.setConfig({
198+
yandex: {
199+
domain: 'yandex.tr',
200+
},
201+
});
202+
203+
const bannerRequest = getBidRequest();
204+
bannerRequest.getFloor = () => ({
205+
currency: 'EUR',
206+
// floor: 0.5
207+
});
208+
209+
const requests = spec.buildRequests([bannerRequest], bidderRequest);
210+
211+
expect(requests).to.have.lengthOf(1);
212+
const request = requests[0];
213+
214+
expect(request).to.exist;
215+
const { method, url } = request;
216+
217+
expect(method).to.equal('POST');
218+
219+
const parsedRequestUrl = utils.parseUrl(url);
220+
221+
expect(parsedRequestUrl.hostname).to.equal('yandex.tr');
222+
})
223+
196224
it('creates a valid banner request', function () {
197225
const bannerRequest = getBidRequest();
198226
bannerRequest.getFloor = () => ({
@@ -213,7 +241,7 @@ describe('Yandex adapter', function () {
213241
const parsedRequestUrl = utils.parseUrl(url);
214242
const { search: query } = parsedRequestUrl
215243

216-
expect(parsedRequestUrl.hostname).to.equal('yandex.ru');
244+
expect(parsedRequestUrl.hostname).to.equal('yandex.com');
217245
expect(parsedRequestUrl.pathname).to.equal('/ads/prebid/123');
218246

219247
expect(query['imp-id']).to.equal('1');

0 commit comments

Comments
 (0)