Skip to content

Commit 4835e08

Browse files
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
1 parent f649e11 commit 4835e08

File tree

11 files changed

+973
-606
lines changed

11 files changed

+973
-606
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<html>
2+
3+
<head>
4+
<link rel="icon" type="image/png" href="/favicon.png">
5+
6+
<!--script async src="//cdn.preciso.net/Preciso_Prebid/prebid.js"></script-->
7+
<script async src="../../build/dev/prebid.js"></script>
8+
<script>
9+
var div_1_sizes = [
10+
[300, 250],
11+
[300, 250]
12+
];
13+
var div_2_sizes = [
14+
[300, 250],
15+
[970, 250]
16+
];
17+
var PREBID_TIMEOUT = 1000;
18+
var FAILSAFE_TIMEOUT = 3000;
19+
var adslot1 = 'preciso-adslot-1';
20+
var adslot2 = 'preciso-adslot-2';
21+
22+
// define Ad units
23+
var adUnits = [
24+
{
25+
code: adslot1,
26+
mediaTypes: {
27+
banner: {
28+
sizes: div_1_sizes
29+
}
30+
},
31+
bids: [{
32+
bidder: 'preciso',
33+
params: {
34+
publisherId: 'PRECISO_TEST00001',
35+
traffic: 'banner',
36+
bidFloor: 0.12,
37+
currency: ['USD'],
38+
region: 'NPL'
39+
}
40+
}]
41+
},
42+
{
43+
code: adslot2,
44+
mediaTypes: {
45+
banner: {
46+
sizes: div_2_sizes
47+
}
48+
},
49+
bids: [{
50+
bidder: 'preciso',
51+
params: {
52+
publisherId: 'PRECISO_TEST00001',
53+
host: 'prebid',
54+
traffic: 'banner',
55+
bidFloor: 0.28,
56+
currency: ['INR'],
57+
region: 'NPL'
58+
}
59+
}]
60+
}
61+
];
62+
63+
64+
65+
var pbjs = pbjs || {};
66+
pbjs.que = pbjs.que || [];
67+
68+
pbjs.que.push(function () {
69+
pbjs.addAdUnits(adUnits);
70+
// Pbjs configurations
71+
pbjs.setConfig({
72+
userSync: {
73+
userIds: [{
74+
name: 'sharedId',
75+
storage: {
76+
name: '_sharedid',
77+
type: 'cookie',
78+
expires: 365
79+
}
80+
}],
81+
filterSettings: {
82+
iframe: {
83+
bidders: ['preciso'],
84+
filter: 'include'
85+
},
86+
image: {
87+
bidders: ['preciso'],
88+
filter: 'include'
89+
}
90+
}
91+
},
92+
realTimeData: {
93+
dataProviders: [{
94+
"name": "geolocation",
95+
"waitForIt": true,
96+
"params": {
97+
"requestPermission": true
98+
}
99+
}]
100+
},
101+
floors: {
102+
floorMin: 0.32,
103+
currency: ['USD']
104+
},
105+
ortb2: {
106+
bcat: ['IAB1-1'],
107+
badv: ['example.com'],
108+
wlang: ['fr', 'en']
109+
},
110+
enableTIDs: true
111+
});
112+
pbjs.setTargetingForGPTAsync();
113+
pbjs.requestBids({
114+
bidsBackHandler: function () {
115+
// call for the bid response which have the high bid price
116+
let ad1 = pbjs.getHighestCpmBids(adslot1)
117+
let ad2 = pbjs.getHighestCpmBids(adslot2)
118+
if (ad1 && ad1.length > 0) {
119+
var iframe1 = document.getElementById('preciso-iframe-1');
120+
var iframe1Doc = iframe1.contentWindow.document;
121+
try {
122+
pbjs.renderAd(iframe1Doc, ad1[0]['adId']);
123+
} catch (e) {
124+
console.log(e);
125+
}
126+
} else {
127+
console.log("No bids for the adslot : " + adslot1);
128+
};
129+
if (ad2 && ad2.length > 0) {
130+
var iframe2 = document.getElementById('preciso-iframe-2');
131+
var iframe2Doc = iframe2.contentWindow.document;
132+
try {
133+
pbjs.renderAd(iframe2Doc, ad2[0]['adId']);
134+
} catch (e) {
135+
console.log(e)
136+
}
137+
} else {
138+
console.log("No bids for the adslot : " + adslot2);
139+
};
140+
141+
var bids = pbjs.getBidResponses();
142+
console.log('Bids received Test test:', bids);
143+
pbjs.setTargetingForAst();
144+
console.log('Rendering ads...');
145+
},
146+
timeout: PREBID_TIMEOUT
147+
});
148+
149+
});
150+
151+
</script>
152+
153+
</head>
154+
155+
<body>
156+
<!-- Ad slot Creation -->
157+
<h2>Basic Prebid.js Example with Preciso Bidder</h2>
158+
<h3>Adslot-1</h3>
159+
<div id='div-1' style="display: inline-block;">
160+
<iframe id='preciso-iframe-1' style="min-width: 350px; min-height: 600px; padding: 0%;" scrolling="no"></iframe>
161+
</div>
162+
163+
<div id='div-2' style="margin-left: 30; vertical-align: top; display: inline-block;">
164+
<h3>Adslot-2</h3>
165+
<iframe id='preciso-iframe-2' style="min-width: 970px; min-height: 250px; " scrolling="no"></iframe>
166+
</div>
167+
168+
</body>
169+
170+
</html>

libraries/precisoUtils/bidUtils.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { convertOrtbRequestToProprietaryNative } from '../../src/native.js';
2+
import { replaceAuctionPrice } from '../../src/utils.js';
3+
import { ajax } from '../../src/ajax.js';
4+
import { consentCheck } from './bidUtilsCommon.js';
5+
6+
export const buildRequests = (endpoint) => (validBidRequests = [], bidderRequest) => {
7+
// convert Native ORTB definition to old-style prebid native definition
8+
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
9+
var city = Intl.DateTimeFormat().resolvedOptions().timeZone;
10+
let req = {
11+
// bidRequest: bidderRequest,
12+
id: validBidRequests[0].auctionId,
13+
cur: validBidRequests[0].params.currency || ['USD'],
14+
imp: validBidRequests.map(req => {
15+
const { bidId, sizes } = req
16+
const impValue = {
17+
id: bidId,
18+
bidfloor: req.params.bidFloor,
19+
bidfloorcur: req.params.currency
20+
}
21+
if (req.mediaTypes.banner) {
22+
impValue.banner = {
23+
format: (req.mediaTypes.banner.sizes || sizes).map(size => {
24+
return { w: size[0], h: size[1] }
25+
}),
26+
27+
}
28+
}
29+
return impValue
30+
}),
31+
user: {
32+
id: validBidRequests[0].userId.pubcid || '',
33+
buyeruid: validBidRequests[0].buyerUid || '',
34+
geo: {
35+
country: validBidRequests[0].params.region || city,
36+
region: validBidRequests[0].params.region || city,
37+
},
38+
39+
},
40+
device: validBidRequests[0].ortb2.device,
41+
site: validBidRequests[0].ortb2.site,
42+
source: validBidRequests[0].ortb2.source,
43+
bcat: validBidRequests[0].ortb2.bcat || validBidRequests[0].params.bcat,
44+
badv: validBidRequests[0].ortb2.badv || validBidRequests[0].params.badv,
45+
wlang: validBidRequests[0].ortb2.wlang || validBidRequests[0].params.wlang,
46+
};
47+
if (req.device && req.device != 'undefined') {
48+
req.device.geo = {
49+
country: req.user.geo.country,
50+
region: req.user.geo.region,
51+
52+
};
53+
};
54+
req.site.publisher = {
55+
publisherId: validBidRequests[0].params.publisherId
56+
};
57+
58+
// req.language.indexOf('-') != -1 && (req.language = req.language.split('-')[0])
59+
consentCheck(bidderRequest, req);
60+
return {
61+
method: 'POST',
62+
url: endpoint,
63+
data: req,
64+
65+
};
66+
}
67+
68+
export function interpretResponse(serverResponse) {
69+
const bidsValue = []
70+
const bidResponse = serverResponse.body
71+
bidResponse.seatbid.forEach(seat => {
72+
seat.bid.forEach(bid => {
73+
bidsValue.push({
74+
requestId: bid.impid,
75+
cpm: bid.price,
76+
width: bid.w,
77+
height: bid.h,
78+
creativeId: bid.crid,
79+
ad: macroReplace(bid.adm, bid.price),
80+
currency: 'USD',
81+
netRevenue: true,
82+
ttl: 300,
83+
meta: {
84+
advertiserDomains: bid.adomain || '',
85+
},
86+
})
87+
})
88+
})
89+
return bidsValue
90+
}
91+
92+
export function onBidWon(bid) {
93+
if (bid.nurl) {
94+
const resolvedNurl = replaceAuctionPrice(bid.nurl, bid.price);
95+
ajax(resolvedNurl);
96+
}
97+
}
98+
99+
/* replacing auction_price macro from adm */
100+
function macroReplace(adm, cpm) {
101+
let replacedadm = replaceAuctionPrice(adm, cpm);
102+
return replacedadm;
103+
}

0 commit comments

Comments
 (0)