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

onetag Bid Adapter : add support for price floors, supply chain, and gpid #8675

Merged
merged 6 commits into from
Jul 21, 2022
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
51 changes: 44 additions & 7 deletions modules/onetagBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {INSTREAM, OUTSTREAM} from '../src/video.js';
import {Renderer} from '../src/Renderer.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { INSTREAM, OUTSTREAM } from '../src/video.js';
import { Renderer } from '../src/Renderer.js';
import {find} from '../src/polyfill.js';
import {getStorageManager} from '../src/storageManager.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {createEidsArray} from './userId/eids.js';
import {deepClone} from '../src/utils.js';
import { getStorageManager } from '../src/storageManager.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { createEidsArray } from './userId/eids.js';
import { deepClone, logError, deepAccess } from '../src/utils.js';

const ENDPOINT = 'https://onetag-sys.com/prebid-request';
const USER_SYNC_ENDPOINT = 'https://onetag-sys.com/usync/';
Expand Down Expand Up @@ -68,6 +68,9 @@ function buildRequests(validBidRequests, bidderRequest) {
if (validBidRequests && validBidRequests.length !== 0 && validBidRequests[0].userId) {
payload.userId = createEidsArray(validBidRequests[0].userId);
}
if (validBidRequests && validBidRequests.length !== 0 && validBidRequests[0].schain && isSchainValid(validBidRequests[0].schain)) {
payload.schain = validBidRequests[0].schain;
}
try {
if (storage.hasLocalStorage()) {
payload.onetagSid = storage.getDataFromLocalStorage('onetag_sid');
Expand Down Expand Up @@ -245,6 +248,7 @@ function requestsToBids(bidRequests) {
// Other params
videoObj['mediaTypeInfo'] = deepClone(bidRequest.mediaTypes.video);
videoObj['type'] = VIDEO;
videoObj['priceFloors'] = getBidFloor(bidRequest, VIDEO, videoObj['playerSize']);
return videoObj;
});
const bannerBidRequests = bidRequests.filter(bidRequest => isValid(BANNER, bidRequest)).map(bidRequest => {
Expand All @@ -253,6 +257,7 @@ function requestsToBids(bidRequests) {
bannerObj['sizes'] = parseSizes(bidRequest);
bannerObj['type'] = BANNER;
bannerObj['mediaTypeInfo'] = deepClone(bidRequest.mediaTypes.banner);
bannerObj['priceFloors'] = getBidFloor(bidRequest, BANNER, bannerObj['sizes']);
return bannerObj;
});
return videoBidRequests.concat(bannerBidRequests);
Expand All @@ -265,6 +270,7 @@ function setGeneralInfo(bidRequest) {
this['bidderRequestId'] = bidRequest.bidderRequestId;
this['auctionId'] = bidRequest.auctionId;
this['transactionId'] = bidRequest.transactionId;
this['gpid'] = deepAccess(bidRequest, 'ortb2Imp.ext.gpid') || deepAccess(bidRequest, 'ortb2Imp.ext.data.pbadslot');
this['pubId'] = params.pubId;
this['ext'] = params.ext;
if (params.pubClick) {
Expand Down Expand Up @@ -373,6 +379,37 @@ function getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent) {
return syncs;
}

function getBidFloor(bidRequest, mediaType, sizes) {
const priceFloors = [];
if (typeof bidRequest.getFloor === 'function') {
sizes.forEach(size => {
const floor = bidRequest.getFloor({
currency: 'EUR',
mediaType: mediaType || '*',
size: [size.width, size.height]
});
floor.size = deepClone(size);
if (!floor.floor) { floor.floor = null; }
priceFloors.push(floor);
});
}
return priceFloors;
}
Comment on lines +382 to +397
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this a mistake to set all bid currency to EUR for floors? am seeing a warning when bidding is set in USD:

WARNING: Price Floors: Unable to get currency conversion for getFloor for bidder onetag. You must have currency module enabled with defaultRates in your currency config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @andyblackwell, that's not a mistake if what is written in documentation is true:

The job of the getFloor() function is to retrieve an appropriate floor for the requesting Bid Adapter, for a given auction context. If a Bid Adapter performs a getFloor() call with a currency different than the currency of the floor data, the module will attempt to perform a currency conversion, utilizing the convertCurrency function in the global Prebid object.

If a currency conversion is successful in getFloor(), the resulting floor will be returned to the requesting Bid Adapter. If the conversion failed, the module will return the original floor currency defined within the selected rule location data set.

So we always request the price floor in EUR, but if conversion fails we pass the original currency (e.g USD) to our server, which makes the right conversion internally. Let me know if you catch something wrong in my point.

Thanks


export function isSchainValid(schain) {
let isValid = false;
const requiredFields = ['asi', 'sid', 'hp'];
if (!schain || !schain.nodes) return isValid;
isValid = schain.nodes.reduce((status, node) => {
if (!status) return status;
return requiredFields.every(field => node.hasOwnProperty(field));
}, true);
if (!isValid) {
logError('OneTag: required schain params missing');
}
return isValid;
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
Expand Down
57 changes: 53 additions & 4 deletions test/spec/modules/onetagBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spec, isValid, hasTypeVideo } from 'modules/onetagBidAdapter.js';
import { spec, isValid, hasTypeVideo, isSchainValid } from 'modules/onetagBidAdapter.js';
import { expect } from 'chai';
import {find} from 'src/polyfill.js';
import { BANNER, VIDEO } from 'src/mediaTypes.js';
Expand All @@ -15,7 +15,21 @@ describe('onetag', function () {
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
'transactionId': 'qwerty123'
'transactionId': 'qwerty123',
'schain': {
'validation': 'off',
'config': {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'indirectseller.com',
'sid': '00001',
'hp': 1
}
]
}
},
};
}

Expand Down Expand Up @@ -193,7 +207,8 @@ describe('onetag', function () {
'context',
'playerSize',
'mediaTypeInfo',
'type'
'type',
'priceFloors'
);
} else if (isValid(BANNER, bid)) {
expect(bid).to.have.all.keys(
Expand All @@ -205,9 +220,13 @@ describe('onetag', function () {
'transactionId',
'mediaTypeInfo',
'sizes',
'type'
'type',
'priceFloors'
);
}
if (bid.schain && isSchainValid(bid.schain)) {
expect(data).to.have.all.keys('schain');
}
expect(bid.bidId).to.be.a('string');
expect(bid.pubId).to.be.a('string');
}
Expand Down Expand Up @@ -358,6 +377,36 @@ describe('onetag', function () {
expect(syncs[0].url).to.match(/(?:[?&](?:us_privacy=us_foo(?:[&][^&]*)*))+$/);
});
});
describe('isSchainValid', function () {
it('Should return false when schain is null or undefined', function () {
expect(isSchainValid(null)).to.be.false;
expect(isSchainValid(undefined)).to.be.false;
});
it('Should return false when schain is missing nodes key', function () {
const schain = {'otherKey': 'otherValue'};
expect(isSchainValid(schain)).to.be.false;
});
it('Should return false when schain is missing one of the required SupplyChainNode attribute', function () {
const missingAsiNode = {'sid': '00001', 'hp': 1};
const missingSidNode = {'asi': 'indirectseller.com', 'hp': 1};
const missingHpNode = {'asi': 'indirectseller.com', 'sid': '00001'};
expect(isSchainValid({'config': {'nodes': [missingAsiNode]}})).to.be.false;
expect(isSchainValid({'config': {'nodes': [missingSidNode]}})).to.be.false;
expect(isSchainValid({'config': {'nodes': [missingHpNode]}})).to.be.false;
});
it('Should return true when schain contains all required attributes', function () {
const validSchain = {
'nodes': [
{
'asi': 'indirectseller.com',
'sid': '00001',
'hp': 1
}
]
};
expect(isSchainValid(validSchain)).to.be.true;
})
});
});

function getBannerVideoResponse() {
Expand Down