Skip to content

Commit

Permalink
Sspbc Bid Adapter: update version and bugfixes (prebid#7584)
Browse files Browse the repository at this point in the history
* Update tests for sspBC adapter

Update tests for sspBC adapter:
- change userSync test (due to tcf param appended in v4.6)
- add tests for onBidWon and onTimeout

* [sspbc-adapter] 5.3 updates: content-type for notifications

* [sspbc-adapter] pass CTA to native bid

* [sspbc-5.3] keep pbsize for detected adunits

* [sspbc-5.3] increment adaptor ver

* [sspbc-adapter] maintenance update to sspBCBidAdapter

* remove yarn.lock

* Delete package-lock.json

* remove package-lock.jsonfrom pull request

* [sspbc-adapter] send pageViewId in request

* [sspbc-adapter] update pageViewId test

Co-authored-by: Wojciech Biały <wb@WojciechBialy.local>
  • Loading branch information
2 people authored and Chris Pabst committed Jan 10, 2022
1 parent 9fc5102 commit 599f5ea
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
37 changes: 34 additions & 3 deletions modules/sspBCBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const BIDDER_URL = 'https://ssp.wp.pl/bidder/';
const SYNC_URL = 'https://ssp.wp.pl/bidder/usersync';
const NOTIFY_URL = 'https://ssp.wp.pl/bidder/notify';
const TMAX = 450;
const BIDDER_VERSION = '5.2';
const BIDDER_VERSION = '5.3';
const W = window;
const { navigator } = W;
const oneCodeDetection = {};
const adUnitsCalled = {};
const adSizesCalled = {};
const pageView = {};
var consentApiVersion;

/**
Expand Down Expand Up @@ -70,6 +72,7 @@ const cookieSupport = () => {
};

const applyClientHints = ortbRequest => {
const { location } = document;
const { connection = {}, deviceMemory, userAgentData = {} } = navigator;
const viewport = W.visualViewport || false;
const segments = [];
Expand All @@ -85,6 +88,16 @@ const applyClientHints = ortbRequest => {
'CH-isMobile': userAgentData.mobile,
};

/**
Check / generate page view id
Should be generated dureing first call to applyClientHints(),
and re-generated if pathname has changed
*/
if (!pageView.id || location.pathname !== pageView.path) {
pageView.path = location.pathname;
pageView.id = Math.floor(1E20 * Math.random());
}

Object.keys(hints).forEach(key => {
const hint = hints[key];

Expand All @@ -100,6 +113,14 @@ const applyClientHints = ortbRequest => {
id: '12',
name: 'NetInfo',
segment: segments,
}, {
id: '7',
name: 'pvid',
segment: [
{
value: `${pageView.id}`
}
]
}];

ortbRequest.user = Object.assign(ortbRequest.user, { data });
Expand Down Expand Up @@ -129,6 +150,7 @@ const setOnAny = (collection, key) => collection.reduce((prev, next) => prev ||
*/
const sendNotification = payload => {
ajax(NOTIFY_URL, null, JSON.stringify(payload), {
contentType: 'application/json',
withCredentials: false,
method: 'POST',
crossOrigin: true
Expand Down Expand Up @@ -267,8 +289,14 @@ const mapImpression = slot => {
send this info as ext.pbsize
*/
const slotSize = slot.sizes.length ? slot.sizes.reduce((prev, next) => prev[0] * prev[1] <= next[0] * next[1] ? next : prev).join('x') : '1x1';
adSizesCalled[slotSize] = adSizesCalled[slotSize] ? adSizesCalled[slotSize] += 1 : 1;
ext.data = Object.assign({ pbsize: `${slotSize}_${adSizesCalled[slotSize]}` }, ext.data);

if (!adUnitsCalled[adUnitCode]) {
// this is a new adunit - assign & save pbsize
adSizesCalled[slotSize] = adSizesCalled[slotSize] ? adSizesCalled[slotSize] += 1 : 1;
adUnitsCalled[adUnitCode] = `${slotSize}_${adSizesCalled[slotSize]}`
}

ext.data = Object.assign({ pbsize: adUnitsCalled[adUnitCode] }, ext.data);

const imp = {
id: id && siteId ? id : 'bidid-' + bidId,
Expand Down Expand Up @@ -325,6 +353,9 @@ const parseNative = nativeData => {
case 0:
result.title = asset.title.text;
break;
case 1:
result.cta = asset.data.value;
break;
case 2:
result.icon = {
url: asset.img.url,
Expand Down
36 changes: 33 additions & 3 deletions test/spec/modules/sspBCBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,33 @@ describe('SSPBC adapter', function () {
expect(payload.user).to.be.an('object').and.to.have.property('[ortb_extensions.consent]', bidRequest.gdprConsent.consentString);
});

it('should send net info and pvid', function () {
expect(payload.user).to.be.an('object').and.to.have.property('data').that.is.an('array');

const userData = payload.user.data;
expect(userData.length).to.equal(2);

const netInfo = userData[0];
expect(netInfo.id).to.equal('12');
expect(netInfo.name).to.equal('NetInfo');
expect(netInfo).to.have.property('segment').that.is.an('array');

const pvid = userData[1];
expect(pvid.id).to.equal('7');
expect(pvid.name).to.equal('pvid');
expect(pvid).to.have.property('segment').that.is.an('array');
expect(pvid.segment[0]).to.have.property('value');
});

it('pvid should be constant on a single page view', function () {
const userData1 = payload.user.data;
const userData2 = payloadNative.user.data;
const pvid1 = userData1[1];
const pvid2 = userData2[1];

expect(pvid1.segment[0].value).to.equal(pvid2.segment[0].value);
});

it('should build correct native payload', function () {
const nativeAssets = payloadNative.imp && payloadNative.imp[0].native.request;

Expand All @@ -543,13 +570,16 @@ describe('SSPBC adapter', function () {
expect(videoAssets).to.have.property('api').that.is.an('array');
});

it('should create auxilary placement identifier (size_numUsed)', function () {
it('should create auxilary placement identifier (size_numUsed), that is constant for a given adUnit', function () {
const extAssets1 = payload.imp && payload.imp[0].ext.data;
const extAssets2 = payloadSingle.imp && payloadSingle.imp[0].ext.data;

// note that payload comes from first, and payloadSingle from second auction in the test run
/*
note that payload comes from first, and payloadSingle from second auction in the test run
also, since both have same adUnitName, value of pbsize property should be the same
*/
expect(extAssets1).to.have.property('pbsize').that.equals('750x200_1')
expect(extAssets2).to.have.property('pbsize').that.equals('750x200_2')
expect(extAssets2).to.have.property('pbsize').that.equals('750x200_1')
});
});

Expand Down

0 comments on commit 599f5ea

Please sign in to comment.