Skip to content

Commit

Permalink
Adprime Bid Adapter: add advertiserDomains, getFloor handler and vide…
Browse files Browse the repository at this point in the history
…o params support (#7263)

* initial

* fix

* remove redundant language mod, use player sizes in video traff

* test modify

* fix

* Adding Tests

* add keywords param

* log

* log

* log

* fix

* add idl

* add idl

* fix test

* lint

* lint

* fix

* lint

* lint

* lint

* lint

* add sync

* fix

* add video params, advertiserDomains and getFloor

* add audiences param

* fix test

Co-authored-by: Aigolkin1991 <[email protected]>
Co-authored-by: Aiholkin <[email protected]>
  • Loading branch information
3 people authored Aug 5, 2021
1 parent 67dba7f commit 3ce5f9c
Show file tree
Hide file tree
Showing 3 changed files with 484 additions and 8 deletions.
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 || [],
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

0 comments on commit 3ce5f9c

Please sign in to comment.