Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yandex Bid Adapter: Add rtt (roud trip time) tracking via nurl #10846

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion modules/yandexBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const spec = {
interpretResponse: interpretResponse,

onBidWon: function (bid) {
const nurl = bid['nurl'];
const nurl = addRTT(bid['nurl'], bid.timeToRespond);

if (!nurl) {
return;
Expand Down Expand Up @@ -378,4 +378,24 @@ function replaceAuctionPrice(url, price, currency) {
.replace(/\${AUCTION_CURRENCY}/, currency);
}

function addRTT(url, rtt) {
if (!url) return;

if (url.indexOf(`\${RTT}`) > -1) {
return url.replace(/\${RTT}/, rtt ?? -1);
}

const urlObj = new URL(url);

if (Number.isInteger(rtt)) {
urlObj.searchParams.set('rtt', rtt);
} else {
urlObj.searchParams.delete('rtt');
}

url = urlObj.toString();

return url;
}

registerBidder(spec);
55 changes: 52 additions & 3 deletions test/spec/modules/yandexBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, expect } from 'chai';
import { spec, NATIVE_ASSETS } from 'modules/yandexBidAdapter.js';
import { parseUrl } from 'src/utils.js';
import * as utils from 'src/utils.js';
import { BANNER, NATIVE } from '../../../src/mediaTypes';
import { config } from '../../../src/config';

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Yandex adapter', function () {

expect(method).to.equal('POST');

const parsedRequestUrl = parseUrl(url);
const parsedRequestUrl = utils.parseUrl(url);
const { search: query } = parsedRequestUrl

expect(parsedRequestUrl.hostname).to.equal('bs.yandex.ru');
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('Yandex adapter', function () {
const bannerRequest = getBidRequest();
const requests = spec.buildRequests([bannerRequest], bidderRequest);
const { url } = requests[0];
const parsedRequestUrl = parseUrl(url);
const parsedRequestUrl = utils.parseUrl(url);
const { search: query } = parsedRequestUrl

expect(query['ssp-cur']).to.equal('USD');
Expand Down Expand Up @@ -443,6 +443,55 @@ describe('Yandex adapter', function () {
});
});
});

describe('onBidWon', function() {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});

it('Should not trigger pixel if bid does not contain nurl', function() {
const result = spec.onBidWon({});
expect(utils.triggerPixel.callCount).to.equal(0)
})

it('Should trigger pixel if bid has nurl', function() {
const result = spec.onBidWon({
nurl: 'https://example.com/some-tracker',
timeToRespond: 378,
});
expect(utils.triggerPixel.callCount).to.equal(1)
expect(utils.triggerPixel.getCall(0).args[0]).to.equal('https://example.com/some-tracker?rtt=378')
})

it('Should trigger pixel if bid has nurl with path & params', function() {
const result = spec.onBidWon({
nurl: 'https://example.com/some-tracker/abcdxyz?param1=1&param2=2',
timeToRespond: 378,
});
expect(utils.triggerPixel.callCount).to.equal(1)
expect(utils.triggerPixel.getCall(0).args[0]).to.equal('https://example.com/some-tracker/abcdxyz?param1=1&param2=2&rtt=378')
})

it('Should trigger pixel if bid has nurl with path & params and rtt macros', function() {
const result = spec.onBidWon({
nurl: 'https://example.com/some-tracker/abcdxyz?param1=1&param2=2&custom-rtt=${RTT}',
timeToRespond: 378,
});
expect(utils.triggerPixel.callCount).to.equal(1)
expect(utils.triggerPixel.getCall(0).args[0]).to.equal('https://example.com/some-tracker/abcdxyz?param1=1&param2=2&custom-rtt=378')
})

it('Should trigger pixel if bid has nurl and there is no timeToRespond param, but has rtt macros in nurl', function() {
const result = spec.onBidWon({
nurl: 'https://example.com/some-tracker/abcdxyz?param1=1&param2=2&custom-rtt=${RTT}',
});
expect(utils.triggerPixel.callCount).to.equal(1)
expect(utils.triggerPixel.getCall(0).args[0]).to.equal('https://example.com/some-tracker/abcdxyz?param1=1&param2=2&custom-rtt=-1')
})
})
});

function getBidConfig() {
Expand Down