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

Adprime Bid Adapter: add advertiserDomains, getFloor handler and video params support #7263

Merged
merged 32 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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: 172 additions & 0 deletions modules/adprimeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'adprime';
const AD_URL = 'https://delta.adprime.com/pbjs';
const SYNC_URL = 'https://delta.adprime.com';

function isBidResponseValid(bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId ||
!bid.ttl || !bid.currency || !bid.meta) {
return false;
}
switch (bid.mediaType) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad);
case VIDEO:
return Boolean(bid.vastUrl);
case NATIVE:
return Boolean(bid.native && bid.native.title && bid.native.image && bid.native.impressionTrackers);
default:
return false;
}
}

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

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

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],

isBidRequestValid: (bid) => {
return Boolean(bid.bidId && bid.params && bid.params.placementId);
},

buildRequests: (validBidRequests = [], bidderRequest) => {
let winTop = window;
let location;
try {
location = new URL(bidderRequest.refererInfo.referer)
winTop = window.top;
} catch (e) {
location = winTop.location;
utils.logMessage(e);
};
let placements = [];
let request = {
deviceWidth: winTop.screen.width,
deviceHeight: winTop.screen.height,
language: (navigator && navigator.language) ? navigator.language.split('-')[0] : '',
secure: 1,
host: location.host,
page: location.pathname,
placements: placements
};
if (bidderRequest) {
if (bidderRequest.uspConsent) {
request.ccpa = bidderRequest.uspConsent;
}
if (bidderRequest.gdprConsent) {
request.gdpr = bidderRequest.gdprConsent
}
}
const len = validBidRequests.length;

for (let i = 0; i < len; i++) {
let bid = validBidRequests[i];
const { mediaTypes } = bid;
const placement = {};
let sizes
let identeties = {}
if (mediaTypes) {
if (mediaTypes[BANNER] && mediaTypes[BANNER].sizes) {
placement.adFormat = BANNER;
sizes = mediaTypes[BANNER].sizes
} else if (mediaTypes[VIDEO] && mediaTypes[VIDEO].playerSize) {
placement.adFormat = VIDEO;
sizes = mediaTypes[VIDEO].playerSize
placement.minduration = mediaTypes[VIDEO].minduration;
placement.maxduration = mediaTypes[VIDEO].maxduration;
placement.mimes = mediaTypes[VIDEO].mimes;
placement.protocols = mediaTypes[VIDEO].protocols;
placement.startdelay = mediaTypes[VIDEO].startdelay;
placement.placement = mediaTypes[VIDEO].placement;
placement.skip = mediaTypes[VIDEO].skip;
placement.skipafter = mediaTypes[VIDEO].skipafter;
placement.minbitrate = mediaTypes[VIDEO].minbitrate;
placement.maxbitrate = mediaTypes[VIDEO].maxbitrate;
placement.delivery = mediaTypes[VIDEO].delivery;
placement.playbackmethod = mediaTypes[VIDEO].playbackmethod;
placement.api = mediaTypes[VIDEO].api;
placement.linearity = mediaTypes[VIDEO].linearity;
} else {
placement.adFormat = NATIVE;
placement.native = mediaTypes[NATIVE];
}
}
if (bid.userId && bid.userId.idl_env) {
identeties.identityLink = bid.userId.idl_env
}

placements.push({
...placement,
placementId: bid.params.placementId,
bidId: bid.bidId,
sizes: sizes || [],
wPlayer: sizes ? sizes[0] : 0,
hPlayer: sizes ? sizes[1] : 0,
schain: bid.schain || {},
keywords: bid.params.keywords || [],
audiences: bid.params.audiences || [],
FilipStamenkovic marked this conversation as resolved.
Show resolved Hide resolved
identeties,
bidFloor: getBidFloor(bid)
});
}
return {
method: 'POST',
url: AD_URL,
data: request
};
},

interpretResponse: (serverResponse) => {
let response = [];
for (let i = 0; i < serverResponse.body.length; i++) {
let resItem = serverResponse.body[i];
if (isBidResponseValid(resItem)) {
const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : [];
resItem.meta = { ...resItem.meta, advertiserDomains };

response.push(resItem);
}
}
return response;
},

getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
let syncUrl = SYNC_URL
if (gdprConsent && gdprConsent.consentString) {
if (typeof gdprConsent.gdprApplies === 'boolean') {
syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
} else {
syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
}
}
if (uspConsent && uspConsent.consentString) {
syncUrl += `&ccpa_consent=${uspConsent.consentString}`;
}
return [{
type: 'image',
url: syncUrl
}];
}

};

registerBidder(spec);
14 changes: 6 additions & 8 deletions modules/adprimeBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ Module that connects to adprime demand sources
{
bidder: 'adprime',
params: {
placementId: 0,
traffic: 'banner',
keywords: ['cat_1', 'cat_2']

placementId: 'testBanner',
keywords: ['cat_1', 'cat_2'],
audiences: ['aud_1', 'aud_2']
}
}
]
Expand All @@ -45,10 +44,9 @@ Module that connects to adprime demand sources
{
bidder: 'adprime',
params: {
placementId: 0,
traffic: 'video',
keywords: ['cat_1', 'cat_2']

placementId: 'testVideo',
keywords: ['cat_1', 'cat_2'],
audiences: ['aud_1', 'aud_2']
}
}
]
Expand Down
Loading