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

Sharethrough Bid Adapter: add GDPR and GPP support #10388

Merged
merged 6 commits into from
Aug 24, 2023
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
172 changes: 102 additions & 70 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deepAccess, generateUUID, inIframe } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { deepAccess, generateUUID, inIframe } from '../src/utils.js';

const VERSION = '4.3.0';
const BIDDER_CODE = 'sharethrough';
Expand All @@ -18,14 +18,14 @@ export const sharethroughAdapterSpec = {
code: BIDDER_CODE,
supportedMediaTypes: [VIDEO, BANNER],
gvlid: 80,
isBidRequestValid: bid => !!bid.params.pkey && bid.bidder === BIDDER_CODE,
isBidRequestValid: (bid) => !!bid.params.pkey && bid.bidder === BIDDER_CODE,

buildRequests: (bidRequests, bidderRequest) => {
const timeout = bidderRequest.timeout;
const firstPartyData = bidderRequest.ortb2 || {};

const nonHttp = sharethroughInternal.getProtocol().indexOf('http') < 0;
const secure = nonHttp || (sharethroughInternal.getProtocol().indexOf('https') > -1);
const secure = nonHttp || sharethroughInternal.getProtocol().indexOf('https') > -1;

const req = {
id: generateUUID(),
Expand Down Expand Up @@ -79,64 +79,79 @@ export const sharethroughAdapterSpec = {
req.regs.ext.us_privacy = bidderRequest.uspConsent;
}

const imps = bidRequests.map(bidReq => {
const impression = { ext: {} };

// mergeDeep(impression, bidReq.ortb2Imp); // leaving this out for now as we may want to leave stuff out on purpose
const tid = deepAccess(bidReq, 'ortb2Imp.ext.tid');
if (tid) impression.ext.tid = tid;
const gpid = deepAccess(bidReq, 'ortb2Imp.ext.gpid', deepAccess(bidReq, 'ortb2Imp.ext.data.pbadslot'));
if (gpid) impression.ext.gpid = gpid;

const videoRequest = deepAccess(bidReq, 'mediaTypes.video');
if (bidderRequest?.gppConsent?.gppString) {
req.regs.gpp = bidderRequest.gppConsent.gppString;
req.regs.gpp_sid = bidderRequest.gppConsent.applicableSections;
} else if (bidderRequest?.ortb2?.regs?.gpp) {
req.regs.ext.gpp = bidderRequest.ortb2.regs.gpp;
req.regs.ext.gpp_sid = bidderRequest.ortb2.regs.gpp_sid;
}

if (videoRequest) {
// default playerSize, only change this if we know width and height are properly defined in the request
let [w, h] = [640, 360];
if (videoRequest.playerSize && videoRequest.playerSize[0] && videoRequest.playerSize[0][0] && videoRequest.playerSize[0][1]) {
[w, h] = videoRequest.playerSize[0];
const imps = bidRequests
.map((bidReq) => {
const impression = { ext: {} };

// mergeDeep(impression, bidReq.ortb2Imp); // leaving this out for now as we may want to leave stuff out on purpose
const tid = deepAccess(bidReq, 'ortb2Imp.ext.tid');
if (tid) impression.ext.tid = tid;
const gpid = deepAccess(bidReq, 'ortb2Imp.ext.gpid', deepAccess(bidReq, 'ortb2Imp.ext.data.pbadslot'));
if (gpid) impression.ext.gpid = gpid;

const videoRequest = deepAccess(bidReq, 'mediaTypes.video');

if (videoRequest) {
// default playerSize, only change this if we know width and height are properly defined in the request
let [w, h] = [640, 360];
if (
videoRequest.playerSize &&
videoRequest.playerSize[0] &&
videoRequest.playerSize[0][0] &&
videoRequest.playerSize[0][1]
) {
[w, h] = videoRequest.playerSize[0];
}

impression.video = {
pos: nullish(videoRequest.pos, 0),
topframe: inIframe() ? 0 : 1,
skip: nullish(videoRequest.skip, 0),
linearity: nullish(videoRequest.linearity, 1),
minduration: nullish(videoRequest.minduration, 5),
maxduration: nullish(videoRequest.maxduration, 60),
playbackmethod: videoRequest.playbackmethod || [2],
api: getVideoApi(videoRequest),
mimes: videoRequest.mimes || ['video/mp4'],
protocols: getVideoProtocols(videoRequest),
w,
h,
startdelay: nullish(videoRequest.startdelay, 0),
skipmin: nullish(videoRequest.skipmin, 0),
skipafter: nullish(videoRequest.skipafter, 0),
placement: videoRequest.context === 'instream' ? 1 : +deepAccess(videoRequest, 'placement', 4),
};

if (videoRequest.delivery) impression.video.delivery = videoRequest.delivery;
if (videoRequest.companiontype) impression.video.companiontype = videoRequest.companiontype;
if (videoRequest.companionad) impression.video.companionad = videoRequest.companionad;
} else {
impression.banner = {
pos: deepAccess(bidReq, 'mediaTypes.banner.pos', 0),
topframe: inIframe() ? 0 : 1,
format: bidReq.sizes.map((size) => ({ w: +size[0], h: +size[1] })),
};
}

impression.video = {
pos: nullish(videoRequest.pos, 0),
topframe: inIframe() ? 0 : 1,
skip: nullish(videoRequest.skip, 0),
linearity: nullish(videoRequest.linearity, 1),
minduration: nullish(videoRequest.minduration, 5),
maxduration: nullish(videoRequest.maxduration, 60),
playbackmethod: videoRequest.playbackmethod || [2],
api: getVideoApi(videoRequest),
mimes: videoRequest.mimes || ['video/mp4'],
protocols: getVideoProtocols(videoRequest),
w,
h,
startdelay: nullish(videoRequest.startdelay, 0),
skipmin: nullish(videoRequest.skipmin, 0),
skipafter: nullish(videoRequest.skipafter, 0),
placement: videoRequest.context === 'instream' ? 1 : +deepAccess(videoRequest, 'placement', 4),
return {
id: bidReq.bidId,
tagid: String(bidReq.params.pkey),
secure: secure ? 1 : 0,
bidfloor: getBidRequestFloor(bidReq),
...impression,
};
})
.filter((imp) => !!imp);

if (videoRequest.delivery) impression.video.delivery = videoRequest.delivery;
if (videoRequest.companiontype) impression.video.companiontype = videoRequest.companiontype;
if (videoRequest.companionad) impression.video.companionad = videoRequest.companionad;
} else {
impression.banner = {
pos: deepAccess(bidReq, 'mediaTypes.banner.pos', 0),
topframe: inIframe() ? 0 : 1,
format: bidReq.sizes.map(size => ({ w: +size[0], h: +size[1] })),
};
}

return {
id: bidReq.bidId,
tagid: String(bidReq.params.pkey),
secure: secure ? 1 : 0,
bidfloor: getBidRequestFloor(bidReq),
...impression,
};
}).filter(imp => !!imp);

return imps.map(impression => {
return imps.map((impression) => {
return {
method: 'POST',
url: STR_ENDPOINT,
Expand All @@ -149,11 +164,17 @@ export const sharethroughAdapterSpec = {
},

interpretResponse: ({ body }, req) => {
if (!body || !body.seatbid || body.seatbid.length === 0 || !body.seatbid[0].bid || body.seatbid[0].bid.length === 0) {
if (
!body ||
!body.seatbid ||
body.seatbid.length === 0 ||
!body.seatbid[0].bid ||
body.seatbid[0].bid.length === 0
) {
return [];
}

return body.seatbid[0].bid.map(bid => {
return body.seatbid[0].bid.map((bid) => {
// Spec: https://docs.prebid.org/dev-docs/bidder-adaptor.html#interpreting-the-response
const response = {
requestId: bid.impid,
Expand Down Expand Up @@ -195,25 +216,36 @@ export const sharethroughAdapterSpec = {
});
},

getUserSyncs: (syncOptions, serverResponses) => {
const shouldCookieSync = syncOptions.pixelEnabled && deepAccess(serverResponses, '0.body.cookieSyncUrls') !== undefined;
getUserSyncs: (syncOptions, serverResponses, gdprConsent, gppConsent) => {
const shouldCookieSync =
syncOptions.pixelEnabled && deepAccess(serverResponses, '0.body.cookieSyncUrls') !== undefined;

let syncurl = '';

return shouldCookieSync
? serverResponses[0].body.cookieSyncUrls.map(url => ({ type: 'image', url: url }))
: [];
// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
syncurl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
}
if (gppConsent) {
syncurl += '&gpp=' + encodeURIComponent(gppConsent?.gppString);
syncurl += '&gpp_sid=' + encodeURIComponent(gppConsent?.applicableSections?.join(','));
}

return shouldCookieSync ? serverResponses[0].body.cookieSyncUrls.map((url) => (
{ type: 'image',
url: url + syncurl
})) : [];
},

// Empty implementation for prebid core to be able to find it
onTimeout: (data) => {
},
onTimeout: (data) => {},

// Empty implementation for prebid core to be able to find it
onBidWon: (bid) => {
},
onBidWon: (bid) => {},

// Empty implementation for prebid core to be able to find it
onSetTargeting: (bid) => {
},
onSetTargeting: (bid) => {},
};

function getVideoApi({ api }) {
Expand All @@ -240,7 +272,7 @@ function getBidRequestFloor(bid) {
const floorInfo = bid.getFloor({
currency: 'USD',
mediaType: bid.mediaTypes && bid.mediaTypes.video ? 'video' : 'banner',
size: bid.sizes.map(size => ({ w: size[0], h: size[1] })),
size: bid.sizes.map((size) => ({ w: size[0], h: size[1] })),
});
if (typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) {
floor = parseFloat(floorInfo.floor);
Expand Down
Loading