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

Sspbc Bid Adapter: update version and bugfixes #7584

Merged
merged 20 commits into from
Nov 1, 2021
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
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