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: improvee native support , matching site/placement, & other maintenance #7963

Merged
merged 35 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1a37b62
Merge pull request #1 from prebid/master
wojciech-bialy-wpm Aug 18, 2020
5a90ba4
Update tests for sspBC adapter
wojciech-bialy-wpm Nov 16, 2020
2183a85
Merge pull request #9 from prebid/master
wojciech-bialy-wpm May 20, 2021
767334b
Merge pull request #11 from prebid/master
wojciech-bialy-wpm Jun 1, 2021
97d7ccf
Merge pull request #13 from prebid/master
wojciech-bialy-wpm Jul 29, 2021
8856c36
Merge pull request #15 from prebid/master
wojciech-bialy-wpm Sep 21, 2021
754df70
Merge pull request #16 from prebid/master
wojciech-bialy-wpm Oct 7, 2021
273e7db
[sspbc-adapter] 5.3 updates: content-type for notifications
Oct 8, 2021
08c90fb
[sspbc-adapter] pass CTA to native bid
Oct 14, 2021
363d342
[sspbc-5.3] keep pbsize for detected adunits
Oct 14, 2021
22b2afc
[sspbc-5.3] increment adaptor ver
Oct 14, 2021
62dad10
[sspbc-adapter] maintenance update to sspBCBidAdapter
Oct 14, 2021
65a7738
remove yarn.lock
Oct 14, 2021
d224072
Merge pull request #17 from prebid/master
wojciech-bialy-wpm Oct 14, 2021
cf9f3e0
Delete package-lock.json
wojciech-bialy-wpm Oct 25, 2021
1721574
remove package-lock.jsonfrom pull request
Oct 25, 2021
ee21d84
update sspbc-5.3 branch
Oct 25, 2021
170fdcd
Merge branch 'master' of https://github.com/prebid/Prebid.js into ssp…
Oct 25, 2021
26ca477
[sspbc-adapter] send pageViewId in request
Oct 25, 2021
2a8278b
[sspbc-adapter] update pageViewId test
Oct 25, 2021
14ac217
Merge pull request #19 from prebid/master
wojciech-bialy-wpm Nov 16, 2021
6d5bbd3
[sspbc-adapter] add viewabiility tracker to native ads
Nov 16, 2021
75174f6
[sspbc-adapter] add support for bid.admNative property
Nov 16, 2021
7891a9e
[sspbc-adapter] ensure that placement id length is always 3 (improves…
Nov 18, 2021
ad6a21a
[sspbc-adapter] read publisher id and custom ad label, then send them…
Nov 18, 2021
e422156
[sspbc-adapter] adlabel and pubid are set as empty strings, if not pr…
Nov 18, 2021
9a792f0
[sspbc-adapter] jstracker data fix
Nov 22, 2021
9ea4c7c
[sspbc-adapter] jstracker data fix
Nov 22, 2021
4461f6f
[sspbc-adapter] send tagid in notifications
Nov 24, 2021
ca7c5b4
[sspbc-adapter] add gvlid to spec; prepare getUserSyncs for iframe + …
Nov 26, 2021
56bbd8f
[sspbc-adapter] fix notification payload
wojciech-bialy-wpm Dec 17, 2021
51a7ca2
[sspbc-adapter] fix notification payload, fix tests
wojciech-bialy-wpm Dec 17, 2021
2ab4e9e
[sspbc-adapter] add userIds to ortb request
wojciech-bialy-wpm Dec 28, 2021
fbc8a40
[sspbc-adapter] update to 4.1, change request to be ortb 2.6 compliant
wojciech-bialy-wpm Jan 11, 2022
94432b9
[sspbc-adapter] update tests
wojciech-bialy-wpm Jan 24, 2022
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
73 changes: 53 additions & 20 deletions modules/sspBCBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ const BIDDER_CODE = 'sspBC';
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 TRACKER_URL = 'https://bdr.wpcdn.pl/tag/jstracker.js';
const GVLID = 676;
const TMAX = 450;
const BIDDER_VERSION = '5.3';
const BIDDER_VERSION = '5.41';
const W = window;
const { navigator } = W;
const oneCodeDetection = {};
Expand All @@ -29,8 +31,8 @@ const getNotificationPayload = bidData => {
const result = {
requestId: undefined,
siteId: [],
adUnit: [],
slotId: [],
tagid: [],
}
bids.forEach(bid => {
let params = isArray(bid.params) ? bid.params[0] : bid.params;
Expand All @@ -55,7 +57,7 @@ const getNotificationPayload = bidData => {
result.adomain = meta.advertiserDomains && meta.advertiserDomains[0];
result.networkName = meta.networkName;
}
result.adUnit.push(bid.adUnitCode)
result.tagid.push(bid.adUnitCode);
result.requestId = bid.auctionId || result.requestId;
result.timeout = bid.timeout || result.timeout;
})
Expand Down Expand Up @@ -123,7 +125,16 @@ const applyClientHints = ortbRequest => {
]
}];

ortbRequest.user = Object.assign(ortbRequest.user, { data });
const ch = { data };
ortbRequest.user = { ...ortbRequest.user, ...ch };
};

const applyUserIds = (validBidRequest, ortbRequest) => {
const eids = validBidRequest.userIdAsEids
if (eids && eids.length) {
const ids = { eids };
ortbRequest.user = { ...ortbRequest.user, ...ids };
}
};

/**
Expand All @@ -135,8 +146,8 @@ const applyGdpr = (bidderRequest, ortbRequest) => {
if (gdprConsent) {
const { apiVersion, gdprApplies, consentString } = gdprConsent;
consentApiVersion = apiVersion;
ortbRequest.regs = Object.assign(ortbRequest.regs, { '[ortb_extensions.gdpr]': gdprApplies ? 1 : 0 });
ortbRequest.user = Object.assign(ortbRequest.user, { '[ortb_extensions.consent]': consentString });
ortbRequest.regs = Object.assign(ortbRequest.regs, { 'gdpr': gdprApplies ? 1 : 0 });
ortbRequest.user = Object.assign(ortbRequest.user, { 'consent': consentString });
}
}

Expand Down Expand Up @@ -299,7 +310,7 @@ const mapImpression = slot => {
ext.data = Object.assign({ pbsize: adUnitsCalled[adUnitCode] }, ext.data);

const imp = {
id: id && siteId ? id : 'bidid-' + bidId,
id: id && siteId ? id.padStart(3, '0') : 'bidid-' + bidId,
banner: mapBanner(slot),
native: mapNative(slot),
video: mapVideo(slot),
Expand Down Expand Up @@ -342,7 +353,7 @@ const isVideoAd = bid => {
const isNativeAd = bid => {
const xmlTester = new RegExp(/^{['"]native['"]/);

return bid.adm && bid.adm.match(xmlTester);
return bid.admNative || (bid.adm && bid.adm.match(xmlTester));
}

const parseNative = nativeData => {
Expand Down Expand Up @@ -450,12 +461,10 @@ const renderCreative = (site, auctionId, bid, seat, request) => {
window.gdpr = ${JSON.stringify(request.gdprConsent)};
window.page = "${site.page}";
window.ref = "${site.ref}";
window.adlabel = "${site.adLabel ? site.adLabel : ''}";
window.pubid = "${site.publisherId ? site.publisherId : ''}";
`;

if (gam) {
adcode += `window.gam = ${JSON.stringify(gam)};`;
}

adcode += `</script>
</head>
<body>
Expand All @@ -469,6 +478,7 @@ const renderCreative = (site, auctionId, bid, seat, request) => {

const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
aliases: [],
supportedMediaTypes: [BANNER, NATIVE, VIDEO],
isBidRequestValid(bid) {
Expand Down Expand Up @@ -513,6 +523,7 @@ const spec = {

applyGdpr(bidderRequest, payload);
applyClientHints(payload);
applyUserIds(validBidRequests[0], payload);

return {
method: 'POST',
Expand Down Expand Up @@ -558,10 +569,14 @@ const spec = {
/*
bid response might include ext object containing siteId / slotId, as detected by OneCode
update site / slot data in this case

ext also might contain publisherId and custom ad label
*/
const { siteid, slotid } = ext;
const { siteid, slotid, pubid, adlabel } = ext;
site.id = siteid || site.id;
site.slot = slotid || site.slot;
site.publisherId = pubid;
site.adLabel = adlabel;
}

if (bidRequest && site.id && !strIncludes(site.id, 'bidid')) {
Expand Down Expand Up @@ -598,10 +613,28 @@ const spec = {
bid.mediaType = 'native';
// check native object
try {
const nativeData = JSON.parse(serverBid.adm).native;
const nativeData = serverBid.admNative || JSON.parse(serverBid.adm).native;
bid.native = parseNative(nativeData);
bid.width = 1;
bid.height = 1;

// append viewability tracker
const jsData = {
rid: bidRequest.auctionId,
crid: bid.creativeId,
adunit: bidRequest.adUnitCode,
url: bid.native.clickUrl,
vendor: seat,
site: site.id,
slot: site.slot,
cpm: bid.cpm.toPrecision(4),
}
const jsTracker = '<script type="text/javascript" async="true" src="' + TRACKER_URL + '" ' + Object.keys(jsData).reduce((acc, current) => { return acc + ` data-wpar-${current}="${jsData[current]}"` }, '') + '><\/script>';
if (bid.native.javascriptTrackers) {
bid.native.javascriptTrackers.push(jsTracker);
} else {
bid.native.javascriptTrackers = [jsTracker];
}
} catch (err) {
logWarn('Could not parse native data', serverBid.adm);
bid.cpm = 0;
Expand All @@ -624,15 +657,15 @@ const spec = {

return bids;
},
getUserSyncs(syncOptions) {
getUserSyncs(syncOptions, serverResponses, gdprConsent) {
let mySyncs = [];
if (syncOptions.iframeEnabled && consentApiVersion != 1) {
return [{
mySyncs.push({
type: 'iframe',
url: `${SYNC_URL}?tcf=${consentApiVersion}`,
}];
} else {
logWarn('sspBC adapter requires iframe based user sync.');
}
});
};
return mySyncs;
},

onTimeout(timeoutData) {
Expand Down
14 changes: 7 additions & 7 deletions test/spec/modules/sspBCBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ describe('SSPBC adapter', function () {
});

it('should send gdpr data', function () {
expect(payload.regs).to.be.an('object').and.to.have.property('[ortb_extensions.gdpr]', 1);
expect(payload.user).to.be.an('object').and.to.have.property('[ortb_extensions.consent]', bidRequest.gdprConsent.consentString);
expect(payload.regs).to.be.an('object').and.to.have.property('gdpr', 1);
expect(payload.user).to.be.an('object').and.to.have.property('consent', bidRequest.gdprConsent.consentString);
});

it('should send net info and pvid', function () {
Expand Down Expand Up @@ -653,7 +653,7 @@ describe('SSPBC adapter', function () {

let nativeBid = resultNative[0];
expect(nativeBid).to.have.keys('bidderCode', 'cpm', 'creativeId', 'currency', 'width', 'height', 'meta', 'mediaType', 'netRevenue', 'requestId', 'ttl', 'native');
expect(nativeBid.native).to.have.keys('image', 'icon', 'title', 'sponsoredBy', 'body', 'clickUrl', 'impressionTrackers');
expect(nativeBid.native).to.have.keys('image', 'icon', 'title', 'sponsoredBy', 'body', 'clickUrl', 'impressionTrackers', 'javascriptTrackers');
});
});

Expand All @@ -668,8 +668,8 @@ describe('SSPBC adapter', function () {
});

it('should send no syncs, if frame sync is not allowed', function () {
expect(syncResultImage).to.be.undefined;
expect(syncResultNone).to.be.undefined;
expect(syncResultImage).to.have.length(0); ;
expect(syncResultNone).to.have.length(0); ;
});
});

Expand All @@ -686,7 +686,7 @@ describe('SSPBC adapter', function () {
let notificationPayload = spec.onBidWon(bid);
expect(notificationPayload).to.have.property('event').that.equals('bidWon');
expect(notificationPayload).to.have.property('requestId').that.equals(bid.auctionId);
expect(notificationPayload).to.have.property('adUnit').that.deep.equals([bid.adUnitCode]);
expect(notificationPayload).to.have.property('tagid').that.deep.equals([bid.adUnitCode]);
expect(notificationPayload).to.have.property('siteId').that.is.an('array');
expect(notificationPayload).to.have.property('slotId').that.is.an('array');
});
Expand All @@ -707,7 +707,7 @@ describe('SSPBC adapter', function () {

expect(notificationPayload).to.have.property('event').that.equals('timeout');
expect(notificationPayload).to.have.property('requestId').that.equals(bids_timeouted[0].auctionId);
expect(notificationPayload).to.have.property('adUnit').that.deep.equals([bids_timeouted[0].adUnitCode, bids_timeouted[1].adUnitCode]);
expect(notificationPayload).to.have.property('tagid').that.deep.equals([bids_timeouted[0].adUnitCode, bids_timeouted[1].adUnitCode]);
});
});
});