forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preciso : Added new library to remove code duplication in bid adapter (…
…prebid#11868) * Preciso : Added new library to remove code duplication in bid adapter * modified bidfloor mapping logic * error fix * error fix * import bidUtils.js in IdxBidadapter to reduce the code duplicataion * import bidUtils.js in IdxBidadapter to reduce the code duplicataion * Error fix * Imported bidUtils library into redtram bid adapter * import common library in mediabramaBidAdapter * import common library in loganBidAdapter to remove code duplication * removed storageManaser from library * renderer.js changes reverted
- Loading branch information
1 parent
f649e11
commit 4835e08
Showing
11 changed files
with
973 additions
and
606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<html> | ||
|
||
<head> | ||
<link rel="icon" type="image/png" href="/favicon.png"> | ||
|
||
<!--script async src="//cdn.preciso.net/Preciso_Prebid/prebid.js"></script--> | ||
<script async src="../../build/dev/prebid.js"></script> | ||
<script> | ||
var div_1_sizes = [ | ||
[300, 250], | ||
[300, 250] | ||
]; | ||
var div_2_sizes = [ | ||
[300, 250], | ||
[970, 250] | ||
]; | ||
var PREBID_TIMEOUT = 1000; | ||
var FAILSAFE_TIMEOUT = 3000; | ||
var adslot1 = 'preciso-adslot-1'; | ||
var adslot2 = 'preciso-adslot-2'; | ||
|
||
// define Ad units | ||
var adUnits = [ | ||
{ | ||
code: adslot1, | ||
mediaTypes: { | ||
banner: { | ||
sizes: div_1_sizes | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'preciso', | ||
params: { | ||
publisherId: 'PRECISO_TEST00001', | ||
traffic: 'banner', | ||
bidFloor: 0.12, | ||
currency: ['USD'], | ||
region: 'NPL' | ||
} | ||
}] | ||
}, | ||
{ | ||
code: adslot2, | ||
mediaTypes: { | ||
banner: { | ||
sizes: div_2_sizes | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'preciso', | ||
params: { | ||
publisherId: 'PRECISO_TEST00001', | ||
host: 'prebid', | ||
traffic: 'banner', | ||
bidFloor: 0.28, | ||
currency: ['INR'], | ||
region: 'NPL' | ||
} | ||
}] | ||
} | ||
]; | ||
|
||
|
||
|
||
var pbjs = pbjs || {}; | ||
pbjs.que = pbjs.que || []; | ||
|
||
pbjs.que.push(function () { | ||
pbjs.addAdUnits(adUnits); | ||
// Pbjs configurations | ||
pbjs.setConfig({ | ||
userSync: { | ||
userIds: [{ | ||
name: 'sharedId', | ||
storage: { | ||
name: '_sharedid', | ||
type: 'cookie', | ||
expires: 365 | ||
} | ||
}], | ||
filterSettings: { | ||
iframe: { | ||
bidders: ['preciso'], | ||
filter: 'include' | ||
}, | ||
image: { | ||
bidders: ['preciso'], | ||
filter: 'include' | ||
} | ||
} | ||
}, | ||
realTimeData: { | ||
dataProviders: [{ | ||
"name": "geolocation", | ||
"waitForIt": true, | ||
"params": { | ||
"requestPermission": true | ||
} | ||
}] | ||
}, | ||
floors: { | ||
floorMin: 0.32, | ||
currency: ['USD'] | ||
}, | ||
ortb2: { | ||
bcat: ['IAB1-1'], | ||
badv: ['example.com'], | ||
wlang: ['fr', 'en'] | ||
}, | ||
enableTIDs: true | ||
}); | ||
pbjs.setTargetingForGPTAsync(); | ||
pbjs.requestBids({ | ||
bidsBackHandler: function () { | ||
// call for the bid response which have the high bid price | ||
let ad1 = pbjs.getHighestCpmBids(adslot1) | ||
let ad2 = pbjs.getHighestCpmBids(adslot2) | ||
if (ad1 && ad1.length > 0) { | ||
var iframe1 = document.getElementById('preciso-iframe-1'); | ||
var iframe1Doc = iframe1.contentWindow.document; | ||
try { | ||
pbjs.renderAd(iframe1Doc, ad1[0]['adId']); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} else { | ||
console.log("No bids for the adslot : " + adslot1); | ||
}; | ||
if (ad2 && ad2.length > 0) { | ||
var iframe2 = document.getElementById('preciso-iframe-2'); | ||
var iframe2Doc = iframe2.contentWindow.document; | ||
try { | ||
pbjs.renderAd(iframe2Doc, ad2[0]['adId']); | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
} else { | ||
console.log("No bids for the adslot : " + adslot2); | ||
}; | ||
|
||
var bids = pbjs.getBidResponses(); | ||
console.log('Bids received Test test:', bids); | ||
pbjs.setTargetingForAst(); | ||
console.log('Rendering ads...'); | ||
}, | ||
timeout: PREBID_TIMEOUT | ||
}); | ||
|
||
}); | ||
|
||
</script> | ||
|
||
</head> | ||
|
||
<body> | ||
<!-- Ad slot Creation --> | ||
<h2>Basic Prebid.js Example with Preciso Bidder</h2> | ||
<h3>Adslot-1</h3> | ||
<div id='div-1' style="display: inline-block;"> | ||
<iframe id='preciso-iframe-1' style="min-width: 350px; min-height: 600px; padding: 0%;" scrolling="no"></iframe> | ||
</div> | ||
|
||
<div id='div-2' style="margin-left: 30; vertical-align: top; display: inline-block;"> | ||
<h3>Adslot-2</h3> | ||
<iframe id='preciso-iframe-2' style="min-width: 970px; min-height: 250px; " scrolling="no"></iframe> | ||
</div> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { convertOrtbRequestToProprietaryNative } from '../../src/native.js'; | ||
import { replaceAuctionPrice } from '../../src/utils.js'; | ||
import { ajax } from '../../src/ajax.js'; | ||
import { consentCheck } from './bidUtilsCommon.js'; | ||
|
||
export const buildRequests = (endpoint) => (validBidRequests = [], bidderRequest) => { | ||
// convert Native ORTB definition to old-style prebid native definition | ||
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests); | ||
var city = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
let req = { | ||
// bidRequest: bidderRequest, | ||
id: validBidRequests[0].auctionId, | ||
cur: validBidRequests[0].params.currency || ['USD'], | ||
imp: validBidRequests.map(req => { | ||
const { bidId, sizes } = req | ||
const impValue = { | ||
id: bidId, | ||
bidfloor: req.params.bidFloor, | ||
bidfloorcur: req.params.currency | ||
} | ||
if (req.mediaTypes.banner) { | ||
impValue.banner = { | ||
format: (req.mediaTypes.banner.sizes || sizes).map(size => { | ||
return { w: size[0], h: size[1] } | ||
}), | ||
|
||
} | ||
} | ||
return impValue | ||
}), | ||
user: { | ||
id: validBidRequests[0].userId.pubcid || '', | ||
buyeruid: validBidRequests[0].buyerUid || '', | ||
geo: { | ||
country: validBidRequests[0].params.region || city, | ||
region: validBidRequests[0].params.region || city, | ||
}, | ||
|
||
}, | ||
device: validBidRequests[0].ortb2.device, | ||
site: validBidRequests[0].ortb2.site, | ||
source: validBidRequests[0].ortb2.source, | ||
bcat: validBidRequests[0].ortb2.bcat || validBidRequests[0].params.bcat, | ||
badv: validBidRequests[0].ortb2.badv || validBidRequests[0].params.badv, | ||
wlang: validBidRequests[0].ortb2.wlang || validBidRequests[0].params.wlang, | ||
}; | ||
if (req.device && req.device != 'undefined') { | ||
req.device.geo = { | ||
country: req.user.geo.country, | ||
region: req.user.geo.region, | ||
|
||
}; | ||
}; | ||
req.site.publisher = { | ||
publisherId: validBidRequests[0].params.publisherId | ||
}; | ||
|
||
// req.language.indexOf('-') != -1 && (req.language = req.language.split('-')[0]) | ||
consentCheck(bidderRequest, req); | ||
return { | ||
method: 'POST', | ||
url: endpoint, | ||
data: req, | ||
|
||
}; | ||
} | ||
|
||
export function interpretResponse(serverResponse) { | ||
const bidsValue = [] | ||
const bidResponse = serverResponse.body | ||
bidResponse.seatbid.forEach(seat => { | ||
seat.bid.forEach(bid => { | ||
bidsValue.push({ | ||
requestId: bid.impid, | ||
cpm: bid.price, | ||
width: bid.w, | ||
height: bid.h, | ||
creativeId: bid.crid, | ||
ad: macroReplace(bid.adm, bid.price), | ||
currency: 'USD', | ||
netRevenue: true, | ||
ttl: 300, | ||
meta: { | ||
advertiserDomains: bid.adomain || '', | ||
}, | ||
}) | ||
}) | ||
}) | ||
return bidsValue | ||
} | ||
|
||
export function onBidWon(bid) { | ||
if (bid.nurl) { | ||
const resolvedNurl = replaceAuctionPrice(bid.nurl, bid.price); | ||
ajax(resolvedNurl); | ||
} | ||
} | ||
|
||
/* replacing auction_price macro from adm */ | ||
function macroReplace(adm, cpm) { | ||
let replacedadm = replaceAuctionPrice(adm, cpm); | ||
return replacedadm; | ||
} |
Oops, something went wrong.