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: use ortb2 info & Core: add webdriver flag #11110

Merged
merged 5 commits into from
Feb 24, 2024
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
39 changes: 12 additions & 27 deletions modules/yandexBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { formatQS, deepAccess, deepSetValue, triggerPixel, _each, _map } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js'
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { _each, _map, deepAccess, deepSetValue, formatQS, triggerPixel } from '../src/utils.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
Expand Down Expand Up @@ -53,7 +53,7 @@ const DEFAULT_CURRENCY = 'EUR';
/**
* @type {MediaType[]}
*/
const SUPPORTED_MEDIA_TYPES = [ BANNER, NATIVE ];
const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE];
const SSP_ID = 10500;

const IMAGE_ASSET_TYPES = {
Expand Down Expand Up @@ -121,15 +121,7 @@ export const spec = {
buildRequests: function(validBidRequests, bidderRequest) {
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);

let referrer = '';
let domain = '';
let page = '';

if (bidderRequest && bidderRequest.refererInfo) {
referrer = bidderRequest.refererInfo.ref;
domain = bidderRequest.refererInfo.domain;
page = bidderRequest.refererInfo.page;
}
const ortb2 = bidderRequest.ortb2;

let timeout = null;
if (bidderRequest) {
Expand All @@ -146,7 +138,7 @@ export const spec = {

const queryParams = {
'imp-id': impId,
'target-ref': targetRef || domain,
'target-ref': targetRef || ortb2?.site?.domain,
'ssp-id': SSP_ID,
};

Expand Down Expand Up @@ -177,24 +169,17 @@ export const spec = {
const data = {
id: bidRequest.bidId,
imp: [imp],
site: {
ref: referrer,
page,
domain,
},
site: ortb2?.site,
tmax: timeout,
user: ortb2?.user,
device: ortb2?.device,
};

const eids = deepAccess(bidRequest, 'userIdAsEids');
if (eids && eids.length) {
deepSetValue(data, 'user.ext.eids', eids);
}

const userData = deepAccess(bidRequest, 'ortb2.user.data');
if (userData && userData.length) {
deepSetValue(data, 'user.data', userData);
}

const queryParamsString = formatQS(queryParams);
return {
method: 'POST',
Expand Down Expand Up @@ -274,8 +259,8 @@ function getBidfloor(bidRequest) {
const floorInfo = bidRequest.getFloor({
currency: DEFAULT_CURRENCY,
mediaType: type,
size: bidRequest.sizes || '*' }
)
size: bidRequest.sizes || '*'
})
floors.push(floorInfo);
}
});
Expand Down Expand Up @@ -332,7 +317,7 @@ function mapNative(bidRequest) {
}

function mapAsset(assetCode, adUnitAssetParams, nativeAsset) {
const [ nativeAssetId, nativeAssetType ] = nativeAsset;
const [nativeAssetId, nativeAssetType] = nativeAsset;
const asset = {
id: nativeAssetId,
};
Expand Down
1 change: 1 addition & 0 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @property {refererInfo} refererInfo - referer info object
* @property {string} [tid] - random UUID (used for s2s)
* @property {string} [src] - s2s or client (used for s2s)
* @property {import('./types/ortb2.js').Ortb2.BidRequest} [ortb2] Global (not specific to any adUnit) first party data to use for all requests in this auction.
*/

/**
Expand Down
8 changes: 7 additions & 1 deletion src/fpd/enrichment.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ const ENRICHMENTS = {
const w = win.innerWidth || win.document.documentElement.clientWidth || win.document.body.clientWidth;
const h = win.innerHeight || win.document.documentElement.clientHeight || win.document.body.clientHeight;

return {
const device = {
w,
h,
dnt: getDNT() ? 1 : 0,
ua: win.navigator.userAgent,
language: win.navigator.language.split('-').shift(),
};

if (win.navigator?.webdriver) {
deepSetValue(device, 'ext.webdriver', true);
}

return device;
})
},
regs() {
Expand Down
59 changes: 59 additions & 0 deletions src/types/ortb2.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @see https://iabtechlab.com/standards/openrtb/
*/
export namespace Ortb2 {
patmmccann marked this conversation as resolved.
Show resolved Hide resolved
type Site = {
page?: string;
ref?: string;
domain?: string;
publisher?: {
domain?: string;
};
keywords?: string;
ext?: Record<string, unknown>;
};

type Device = {
w?: number;
h?: number;
dnt?: 0 | 1;
ua?: string;
language?: string;
sua?: {
source?: number;
platform?: unknown;
browsers?: unknown[];
mobile?: number;
};
ext?: {
webdriver?: true;
[key: string]: unknown;
};
};

type Regs = {
coppa?: unknown;
ext?: {
gdpr?: unknown;
us_privacy?: unknown;
[key: string]: unknown;
};
};

type User = {
ext?: Record<string, unknown>;
};

/**
* Ortb2 info provided in bidder request. Some of the sections are mutually exclusive.
* @see clientSectionChecker
*/
type BidRequest = {
device?: Device;
regs?: Regs;
user?: User;
site?: Site;
app?: unknown;
dooh?: unknown;
};
}
19 changes: 17 additions & 2 deletions test/spec/fpd/enrichment_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ describe('FPD enrichment', () => {
});
});

describe('ext.webdriver', () => {
it('when navigator.webdriver is available', () => {
win.navigator.webdriver = true;
return fpd().then(ortb2 => {
expect(ortb2.device.ext?.webdriver).to.eql(true);
});
});

it('when navigator.webdriver is not present', () => {
return fpd().then(ortb2 => {
expect(ortb2.device.ext?.webdriver).to.not.exist;
});
});
});

it('sets ua', () => {
win.navigator.userAgent = 'mock-ua';
return fpd().then(ortb2 => {
Expand Down Expand Up @@ -362,7 +377,7 @@ describe('FPD enrichment', () => {
setup();
cdep = Promise.resolve('example-test-label');
return fpd().then(ortb2 => {
expect(ortb2.device.ext).to.not.exist;
expect(ortb2.device.ext?.cdep).to.not.exist;
if (navigator.cookieDeprecationLabel) {
sinon.assert.notCalled(navigator.cookieDeprecationLabel.getValue);
}
Expand All @@ -373,7 +388,7 @@ describe('FPD enrichment', () => {
it('if the navigator API returns a promise that rejects, the enrichment does not halt forever', () => {
cdep = Promise.reject(new Error('oops, something went wrong'));
return fpd().then(ortb2 => {
expect(ortb2.device.ext).to.not.exist;
expect(ortb2.device.ext?.cdep).to.not.exist;
})
});
});
Expand Down
92 changes: 73 additions & 19 deletions test/spec/modules/yandexBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assert, expect } from 'chai';
import { spec, NATIVE_ASSETS } from 'modules/yandexBidAdapter.js';
import { NATIVE_ASSETS, spec } from 'modules/yandexBidAdapter.js';
import * as utils from 'src/utils.js';
import { BANNER, NATIVE } from '../../../src/mediaTypes';
import { config } from '../../../src/config';
import { BANNER, NATIVE } from '../../../src/mediaTypes';

describe('Yandex adapter', function () {
describe('isBidRequestValid', function () {
Expand Down Expand Up @@ -41,11 +41,45 @@ describe('Yandex adapter', function () {
});

describe('buildRequests', function () {
/** @type {import('../../../src/auction').BidderRequest} */
const bidderRequest = {
refererInfo: {
domain: 'ya.ru',
ref: 'https://ya.ru/',
page: 'https://ya.ru/',
ortb2: {
site: {
domain: 'ya.ru',
ref: 'https://ya.ru/',
page: 'https://ya.ru/',
publisher: {
domain: 'ya.ru',
},
},
device: {
w: 1600,
h: 900,
dnt: 0,
ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
language: 'en',
sua: {
source: 1,
platform: {
brand: 'macOS',
},
browsers: [
{
brand: 'Not_A Brand',
version: ['8'],
},
{
brand: 'Chromium',
version: ['120'],
},
{
brand: 'Google Chrome',
version: ['120'],
},
],
mobile: 0,
},
},
},
gdprConsent: {
gdprApplies: 1,
Expand Down Expand Up @@ -107,12 +141,10 @@ describe('Yandex adapter', function () {
});

it('should send eids and ortb2 user data if defined', function() {
const bidRequestExtra = {
userIdAsEids: [{
source: 'sharedid.org',
uids: [{ id: '01', atype: 1 }],
}],
const bidderRequestWithUserData = {
...bidderRequest,
ortb2: {
...bidderRequest.ortb2,
user: {
data: [
{
Expand All @@ -127,17 +159,24 @@ describe('Yandex adapter', function () {
},
],
},
},
}
};
const bidRequestExtra = {
userIdAsEids: [{
source: 'sharedid.org',
uids: [{ id: '01', atype: 1 }],
}],
};

const expected = {
ext: {
eids: bidRequestExtra.userIdAsEids,
},
data: bidRequestExtra.ortb2.user.data,
data: bidderRequestWithUserData.ortb2.user.data,
};

const bannerRequest = getBidRequest(bidRequestExtra);
const requests = spec.buildRequests([bannerRequest], bidderRequest);
const requests = spec.buildRequests([bannerRequest], bidderRequestWithUserData);

expect(requests).to.have.lengthOf(1);
const request = requests[0];
Expand All @@ -149,6 +188,16 @@ describe('Yandex adapter', function () {
expect(data.user).to.deep.equal(expected);
});

it('should send site', function() {
const expected = {
site: bidderRequest.ortb2.site
};

const requests = spec.buildRequests([getBidRequest()], bidderRequest);

expect(requests[0].data.site).to.deep.equal(expected.site);
});

describe('banner', () => {
it('should create valid banner object', () => {
const bannerRequest = getBidRequest({
Expand Down Expand Up @@ -496,41 +545,46 @@ describe('Yandex adapter', function () {
});

it('Should not trigger pixel if bid does not contain nurl', function() {
const result = spec.onBidWon({});
spec.onBidWon({});

expect(utils.triggerPixel.callCount).to.equal(0)
})

it('Should trigger pixel if bid has nurl', function() {
const result = spec.onBidWon({
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({
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({
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({
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')
})
Expand Down