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

Preciso Bid Adapter : modified the request parameters #10436

Merged
merged 26 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cf49216
New bid adapter : Preciso
PrecisoSRL Jun 20, 2023
cc792c9
Merge branch 'prebid:master' into master
PrecisoSRL Jun 23, 2023
e62d496
Merge branch 'prebid:master' into master
PrecisoSRL Jul 3, 2023
05dc573
Added deafualt statement in interpretNativeAd
NikhilGopalChennissery Jul 3, 2023
abf2928
removed trailing space
NikhilGopalChennissery Jul 3, 2023
2fc09e4
Added Protected Audience API (FLEDGE) support
NikhilGopalChennissery Jul 4, 2023
48a0dad
updated with getConfig method f pr pulling ortb2 data
NikhilGopalChennissery Jul 11, 2023
2ab0a44
updated the precisoBidAdapter
NikhilGopalChennissery Jul 11, 2023
5096a18
updated the test cases
NikhilGopalChennissery Jul 11, 2023
257ab49
Merge branch 'prebid:master' into master
PrecisoSRL Jul 11, 2023
4dc1f74
Merge branch 'prebid:master' into master
PrecisoSRL Jul 12, 2023
63347d5
Merge branch 'prebid:master' into master
PrecisoSRL Jul 27, 2023
ccb571b
changed user sync url and also fixed the CORS error
NikhilGopalChennissery Aug 1, 2023
92e5fc6
removed test params from hello_world.html and 204 error fix
NikhilGopalChennissery Aug 15, 2023
aeb0324
changed responses fields in the precisoBidAdapter.js
NikhilGopalChennissery Aug 17, 2023
9ae4b1d
Merge branch 'prebid:master' into master
PrecisoSRL Aug 17, 2023
f03078a
error fix
NikhilGopalChennissery Aug 17, 2023
85727a8
removed test params
NikhilGopalChennissery Aug 18, 2023
44e0b59
reverted the test params
NikhilGopalChennissery Aug 21, 2023
1588358
modified the request
NikhilGopalChennissery Sep 5, 2023
2bb28b1
Merge branch 'master' into master
PrecisoSRL Sep 6, 2023
f70ec55
removed the empty line
NikhilGopalChennissery Sep 6, 2023
b8802dc
Merge branch 'master' of https://github.com/PrecisoSRL/Prebid.js
NikhilGopalChennissery Sep 6, 2023
e54f753
Merge branch 'prebid:master' into master
PrecisoSRL Sep 6, 2023
a6e429f
removed blank line in precisoBidAdapter_spec.js
NikhilGopalChennissery Sep 7, 2023
d7bc825
Merge branch 'master' of https://github.com/PrecisoSRL/Prebid.js
NikhilGopalChennissery Sep 7, 2023
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
80 changes: 49 additions & 31 deletions modules/precisoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logMessage } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { logMessage, isFn, deepAccess } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
Expand Down Expand Up @@ -33,26 +33,48 @@ export const spec = {
location = winTop.location;
logMessage(e);
};
let placements = [];
let imp = [];

let site = {
'domain': location.domain || '',
'page': location || ''
}

let request = {
'id': '123456',
'imp': imp,
id: '123456678',
imp: validBidRequests.map(request => {
const { bidId, sizes, mediaType } = request
const item = {
id: bidId,
region: request.params.region,
traffic: mediaType,
bidFloor: getBidFloor(request)
}

if (request.mediaTypes.banner) {
item.banner = {
format: (request.mediaTypes.banner.sizes || sizes).map(size => {
return { w: size[0], h: size[1] }
}),
}
}

if (request.schain) {
item.schain = request.schain;
}

return item
}),

'site': site,
'deviceWidth': winTop.screen.width,
'deviceHeight': winTop.screen.height,
'language': (navigator && navigator.language) ? navigator.language : '',
'secure': 1,
'host': location.host,
'page': location.pathname,
'coppa': config.getConfig('coppa') === true ? 1 : 0,
'placements': placements
'coppa': config.getConfig('coppa') === true ? 1 : 0
};

request.language.indexOf('-') != -1 && (request.language = request.language.split('-')[0])
if (bidderRequest) {
if (bidderRequest.uspConsent) {
Expand All @@ -66,32 +88,11 @@ export const spec = {
}
}

const len = validBidRequests.length;

for (let i = 0; i < len; i++) {
let bid = validBidRequests[i];
let traff = bid.params.traffic || BANNER
placements.push({
region: bid.params.region,
bidId: bid.bidId,
sizes: bid.mediaTypes && bid.mediaTypes[traff] && bid.mediaTypes[traff].sizes ? bid.mediaTypes[traff].sizes : [],
traffic: traff,
publisherId: bid.params.publisherId
});
imp.push({
id: bid.bidId,
sizes: bid.mediaTypes && bid.mediaTypes[traff] && bid.mediaTypes[traff].sizes ? bid.mediaTypes[traff].sizes : [],
traffic: traff,
publisherId: bid.params.publisherId
})
if (bid.schain) {
placements.schain = bid.schain;
}
}
return {
method: 'POST',
url: AD_URL,
data: request
data: request,

};
},

Expand Down Expand Up @@ -143,4 +144,21 @@ export const spec = {

};

function getBidFloor(bid) {
if (!isFn(bid.getFloor)) {
return deepAccess(bid, 'params.bidFloor', 0);
}

try {
const bidFloor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*',
});
return bidFloor.floor;
} catch (_) {
return 0
}
}

registerBidder(spec);
34 changes: 19 additions & 15 deletions test/spec/modules/precisoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect} from 'chai';
import {spec} from '../../../modules/precisoBidAdapter.js';
import { expect } from 'chai';
import { spec } from '../../../modules/precisoBidAdapter.js';
import { config } from '../../../src/config.js';

const DEFAULT_PRICE = 1
Expand All @@ -10,14 +10,19 @@ const BIDDER_CODE = 'preciso';

describe('PrecisoAdapter', function () {
let bid = {

bidId: '23fhj33i987f',
bidder: 'preciso',
mediaTypes: {
banner: {
sizes: [[DEFAULT_BANNER_WIDTH, DEFAULT_BANNER_HEIGHT]]
}
},
params: {
host: 'prebid',
sourceid: '0',
publisherId: '0',
traffic: 'banner',
mediaType: 'banner',

region: 'prebid-eu'

}
Expand Down Expand Up @@ -50,34 +55,31 @@ describe('PrecisoAdapter', function () {
it('Returns valid data if array of bids is valid', function () {
let data = serverRequest.data;
expect(data).to.be.an('object');
expect(data).to.have.all.keys('id', 'imp', 'site', 'deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements', 'coppa');

// expect(data).to.have.all.keys('bidId', 'imp', 'site', 'deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements', 'coppa');

expect(data.deviceWidth).to.be.a('number');
expect(data.deviceHeight).to.be.a('number');
expect(data.coppa).to.be.a('number');
expect(data.language).to.be.a('string');
expect(data.secure).to.be.within(0, 1);
expect(data.host).to.be.a('string');
expect(data.page).to.be.a('string');
let placement = data['placements'][0];
expect(placement).to.have.keys('region', 'bidId', 'traffic', 'sizes', 'publisherId');
expect(placement.bidId).to.equal('23fhj33i987f');
expect(placement.traffic).to.equal('banner');
expect(placement.region).to.equal('prebid-eu');
});
it('Returns empty data if no valid requests are passed', function () {
serverRequest = spec.buildRequests([]);
let data = serverRequest.data;
expect(data.placements).to.be.an('array').that.is.empty;
expect(data.imp).to.be.an('array').that.is.empty;
});
});

describe('with COPPA', function() {
beforeEach(function() {
describe('with COPPA', function () {
beforeEach(function () {
sinon.stub(config, 'getConfig')
.withArgs('coppa')
.returns(true);
});
afterEach(function() {
afterEach(function () {
config.getConfig.restore();
});

Expand All @@ -90,7 +92,9 @@ describe('PrecisoAdapter', function () {
describe('interpretResponse', function () {
it('should get correct bid response', function () {
let response = {
id: 'f6adb85f-4e19-45a0-b41e-2a5b9a48f23a',

bidderRequestId: 'f6adb85f-4e19-45a0-b41e-2a5b9a48f23a',

seatbid: [
{
bid: [
Expand Down