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

Preciso : Added new library to remove code duplication in bid adapter #11868

Merged
merged 20 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
17451f8
Preciso : Added new library to remove code duplication in bid adapter
NikhilGopalChennissery Jun 26, 2024
c8f17b7
Merge branch 'prebid:master' into master_jun_24
NikhilGopalChennissery Jun 26, 2024
23731e6
modified bidfloor mapping logic
NikhilGopalChennissery Jun 27, 2024
3db9592
Merge branch 'master_jun_24' of https://github.com/PrecisoSRL/Prebid.…
NikhilGopalChennissery Jun 27, 2024
ec467a9
Merge branch 'prebid:master' into master_jun_24
NikhilGopalChennissery Jun 27, 2024
b60e3d6
Merge branch 'prebid:master' into master_jun_24
NikhilGopalChennissery Jul 24, 2024
1e51330
error fix
NikhilGopalChennissery Jul 24, 2024
702eba7
error fix
NikhilGopalChennissery Jul 24, 2024
e0ee391
Merge branch 'prebid:master' into master_jun_24
NikhilGopalChennissery Jul 26, 2024
c174c9e
import bidUtils.js in IdxBidadapter to reduce the code duplicataion
NikhilGopalChennissery Aug 1, 2024
65af09e
import bidUtils.js in IdxBidadapter to reduce the code duplicataion
NikhilGopalChennissery Aug 1, 2024
d4c4bd7
Error fix
NikhilGopalChennissery Aug 1, 2024
c291e6d
Imported bidUtils library into redtram bid adapter
NikhilGopalChennissery Aug 6, 2024
510053a
import common library in mediabramaBidAdapter
NikhilGopalChennissery Aug 8, 2024
6324822
Merge branch 'master' into master_jun_24
NikhilGopalChennissery Aug 8, 2024
e9c773e
import common library in loganBidAdapter to remove code duplication
NikhilGopalChennissery Aug 8, 2024
dcb586f
Merge branch 'master_jun_24' of https://github.com/PrecisoSRL/Prebid.…
NikhilGopalChennissery Aug 8, 2024
8659a3a
removed storageManaser from library
NikhilGopalChennissery Aug 12, 2024
c2b8c27
renderer.js changes reverted
NikhilGopalChennissery Aug 16, 2024
0ccda46
Merge branch 'prebid:master' into master_jun_24
NikhilGopalChennissery Aug 16, 2024
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
168 changes: 168 additions & 0 deletions integrationExamples/gpt/precisoExample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<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, 600]
];
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'
}
}]
},
{
code: adslot2,
mediaTypes: {
banner: {
sizes: div_2_sizes
}
},
bids: [{
bidder: 'preciso',
params: {
publisherId: 'PRECISO_TEST00001',
host: 'prebid',
traffic: 'banner',
bidFloor: 0.28,
currency: 'INR'
}
}]
}
];



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>
104 changes: 104 additions & 0 deletions libraries/bidUtils/bidUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { convertOrtbRequestToProprietaryNative } from '../../src/native.js';
import { replaceAuctionPrice } from '../../src/utils.js';
import { getStorageManager } from '../../src/storageManager.js';
import { ajax } from '../../src/ajax.js';
import { MODULE_TYPE_UID } from '../../src/activities/modules.js';
import { consentCheck } from './bidUtilsCommon.js';

export const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: 'sharedId' });
NikhilGopalChennissery marked this conversation as resolved.
Show resolved Hide resolved

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,
},

},
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
};
};
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;
}
Loading