Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Hugh0222/Prebid.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hugh.qu committed Dec 11, 2024
2 parents 4273be8 + bbd6677 commit d949c07
Show file tree
Hide file tree
Showing 299 changed files with 12,083 additions and 4,448 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Prebid.js is open source software that is offered for free as a convenience. Whi

*Note:* Requires Prebid.js v1.38.0+

Prebid.js depends on Babel and some Babel Plugins in order to run correctly in the browser. Here are some examples for
Prebid.js depends on Babel and some Babel Plugins in order to run correctly in the browser. Here are some examples for
configuring webpack to work with Prebid.js.

With Babel 7:
Expand All @@ -37,7 +37,7 @@ module.exports = {
mode: 'production',
module: {
rules: [

// this rule can be excluded if you don't require babel-loader for your other application files
{
test: /\.m?js$/,
Expand All @@ -46,7 +46,7 @@ module.exports = {
loader: 'babel-loader',
}
},

// this separate rule is required to make sure that the Prebid.js files are babel-ified. this rule will
// override the regular exclusion from above (for being inside node_modules).
{
Expand All @@ -71,15 +71,15 @@ Or for Babel 6:
// you must manually install and specify the presets and plugins yourself
options: {
plugins: [
"transform-object-assign", // required (for IE support) and "babel-plugin-transform-object-assign"
"transform-object-assign", // required (for IE support) and "babel-plugin-transform-object-assign"
// must be installed as part of your package.
require('prebid.js/plugins/pbjsGlobals.js') // required!
],
presets: [
["env", { // you can use other presets if you wish.
"targets": { // this example is using "babel-presets-env", which must be installed if you
"browsers": [ // follow this example.
... // your browser targets. they should probably match the targets you're using for the rest
... // your browser targets. they should probably match the targets you're using for the rest
// of your application
]
}
Expand Down Expand Up @@ -143,7 +143,7 @@ This will run testing but not linting. A web server will start at `http://localh

Development may be a bit slower but if you prefer linting and additional watch files you can also still run just:

$ gulp serve
$ gulp serve


### Build Optimization
Expand All @@ -162,11 +162,11 @@ Building with just these adapters will result in a smaller bundle which should a
- Then run the build:

$ gulp build --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter

Alternatively, a `.json` file can be specified that contains a list of modules you would like to include.

$ gulp build --modules=modules.json

With `modules.json` containing the following
```json modules.json
[
Expand Down Expand Up @@ -202,7 +202,7 @@ gulp bundle --tag one --modules=one.json
gulp bundle --tag two --modules=two.json
```

This generates slightly larger files, but has the advantage of being much faster to run (after the initial `gulp build`). It's also the method used by [the Prebid.org download page](https://docs.prebid.org/download.html).
This generates slightly larger files, but has the advantage of being much faster to run (after the initial `gulp build`). It's also the method used by [the Prebid.org download page](https://docs.prebid.org/download.html).

<a name="Run"></a>

Expand Down Expand Up @@ -378,7 +378,7 @@ For instructions on writing tests for Prebid.js, see [Testing Prebid.js](https:/

### Supported Browsers

Prebid.js is supported on IE11 and modern browsers until 5.x. 6.x+ transpiles to target >0.25%; not Opera Mini; not IE11.
Prebid.js is supported on IE11 and modern browsers until 5.x. 6.x+ transpiles to target >0.25%; not Opera Mini; not IE11.

### Governance
Review our governance model [here](https://github.com/prebid/Prebid.js/tree/master/governance.md).
Expand Down
7 changes: 3 additions & 4 deletions integrationExamples/gpt/51DegreesRtdProvider_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
name: '51Degrees',
waitForIt: true,
params: {
// Get your resource key from https://configure.51degrees.com/tWrhNfY6
// Get your resource key from https://configure.51degrees.com/HNZ75HT1
resourceKey: '<YOUR_RESOURCE_KEY>',
// alternatively, you can use the on-premise version of the 51Degrees service and connect to your chosen end point
// onPremiseJSUrl: 'https://localhost/51Degrees.core.js'
Expand Down Expand Up @@ -181,12 +181,11 @@ <h3>div-banner-native-2</h3>
<h3>Testing/Debugging Guidance</h3>
<ol>
<li>Make sure you have <code>debug: true</code> under <code>pbjs.setConfig</code> in this example code (be sure to remove it for production!)
<li>Make sure you have replaced <code>&lt;YOUR RESOURCE KEY&gt;</code> in this example code with the one you have obtained
from the <a href="https://configure.51degrees.com/tWrhNfY6" target="blank;">51Degrees Configurator Tool</a></li>
<li>Make sure you have replaced <code>&lt;YOUR RESOURCE KEY&gt;</code> in this example code with the one you have obtained
from the <a href="https://configure.51degrees.com/HNZ75HT1" target="blank;">51Degrees Configurator Tool</a></li>
<li>Open DevTools Console in your browser and refresh the page</li>
<li>Observe the enriched ortb device data shown below and also in the console as part of the <code>[51Degrees RTD Submodule]: reqBidsConfigObj:</code> message (under <code>reqBidsConfigObj.global.device</code>)</li>
</ol>

</div>
<div id="enriched-51" style="display: none">
<h3>Enriched ORTB2 device data</h3>
Expand Down
114 changes: 114 additions & 0 deletions integrationExamples/gpt/rewardedInterestIdSystem_example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>Rewarded Interest ID Example</title>
<script>
const FAILSAFE_TIMEOUT = 2000;
const adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600], [728, 90]]
},
},
bids: [
{
bidder: 'rubicon',
params: {
accountId: '1001',
siteId: '113932',
zoneId: '535510'
}
}
]
}
];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
</script>
<script src="../../build/dev/prebid.js" async></script>

<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(function () {
pbjs.setConfig({
debug: true,
userSync: {
userIds: [
{
name: 'rewardedInterestId',
},
],
syncDelay: 5000,
auctionDelay: 1000,
}
});
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest
});
});

function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}

setTimeout(function () {
sendAdserverRequest();
}, FAILSAFE_TIMEOUT);
</script>

<script>
(function () {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
gads.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<script>
googletag.cmd.push(function () {
googletag.defineSlot('/112115922/FL_PB_MedRect', [[300, 250], [300, 600], [728, 90]], 'test-div').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>

<body>
<script>
pbjs.que.push(function () {
pbjs.getUserIdsAsync().then(ids => {
document.getElementById('ids-div').innerHTML = JSON.stringify(ids, null, ' ');
document.getElementById('eids-div').innerHTML = JSON.stringify(pbjs.getUserIdsAsEids(), null, ' ');
});
});
</script>

<h2>Rewarded Interest ID Example</h2>

<h4>Generated IDs:</h4>
<pre id="ids-div" style="border:1px solid #333; padding:5px; overflow: auto"></pre>

<h4>Generated EIDs</h4>
<pre id="eids-div" style="border:1px solid #333; padding:5px; overflow: auto"></pre>
</body>

</html>
2 changes: 1 addition & 1 deletion libraries/advangUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function isVideoBid(bid) {

export function getBannerBidFloor(bid) {
let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'banner', size: '*' }) : {};
return floorInfo.floor || getBannerBidParam(bid, 'bidfloor');
return floorInfo?.floor || getBannerBidParam(bid, 'bidfloor');
}

export function getVideoBidFloor(bid) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/appnexusUtils/anKeywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function getANMapFromOrtbSegments(ortb2) {
let ortbSegsArrObj = deepAccess(ortb2, path) || [];
ortbSegsArrObj.forEach(segObj => {
// only read segment data from known sources
const segtax = ORTB_SEGTAX_KEY_MAP[deepAccess(segObj, 'ext.segtax')];
const segtax = ORTB_SEGTAX_KEY_MAP[segObj?.ext?.segtax];
if (segtax) {
segObj.segment.forEach(seg => {
// if source was in multiple locations of ortb or had multiple segments in same area, stack them together into an array
Expand Down
70 changes: 70 additions & 0 deletions libraries/biddoInvamiaUtils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Helper function to build request payload for banner ads.
* @param {Object} bidRequest - The bid request object.
* @param {string} endpointUrl - The endpoint URL specific to the bidder.
* @returns {Array} An array of server requests.
*/
export function buildBannerRequests(bidRequest, endpointUrl) {
const serverRequests = [];
const sizes = bidRequest.mediaTypes.banner.sizes;

sizes.forEach(([width, height]) => {
bidRequest.params.requestedSizes = [width, height];

const payload = {
ctype: 'div',
pzoneid: bidRequest.params.zoneId,
width,
height,
};

const payloadString = Object.keys(payload)
.map((key) => `${key}=${encodeURIComponent(payload[key])}`)
.join('&');

serverRequests.push({
method: 'GET',
url: endpointUrl,
data: payloadString,
bidderRequest: bidRequest,
});
});

return serverRequests;
}

/**
* Helper function to interpret server response for banner ads.
* @param {Object} serverResponse - The server response object.
* @param {Object} bidderRequest - The matched bid request for this response.
* @returns {Array} An array of bid responses.
*/
export function interpretBannerResponse(serverResponse, bidderRequest) {
const response = serverResponse.body;
const bidResponses = [];

if (response && response.template && response.template.html) {
const { bidId } = bidderRequest;
const [width, height] = bidderRequest.params.requestedSizes;

const bidResponse = {
requestId: bidId,
cpm: response.hb.cpm,
creativeId: response.banner.hash,
currency: 'USD',
netRevenue: response.hb.netRevenue,
ttl: 600,
ad: response.template.html,
mediaType: 'banner',
meta: {
advertiserDomains: response.hb.adomains || [],
},
width,
height,
};

bidResponses.push(bidResponse);
}

return bidResponses;
}
78 changes: 78 additions & 0 deletions libraries/braveUtils/buildAndInterpret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { isEmpty, parseUrl } from '../../src/utils.js';
import {config} from '../../src/config.js';
import { createNativeRequest, createBannerRequest, createVideoRequest } from './index.js';
import { convertOrtbRequestToProprietaryNative } from '../../src/native.js';

export const buildRequests = (validBidRequests, bidderRequest, endpointURL, defaultCur) => {
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
if (!validBidRequests.length || !bidderRequest) return [];

const endpoint = endpointURL.replace('hash', validBidRequests[0].params.placementId);
const imp = validBidRequests.map((br) => {
const impObject = { id: br.bidId, secure: 1 };
if (br.mediaTypes.banner) impObject.banner = createBannerRequest(br);
else if (br.mediaTypes.video) impObject.video = createVideoRequest(br);
else if (br.mediaTypes.native) impObject.native = { id: br.transactionId, ver: '1.2', request: createNativeRequest(br) };
return impObject;
});

const page = bidderRequest.refererInfo.page || bidderRequest.refererInfo.topmostLocation;
const data = {
id: bidderRequest.bidderRequestId,
cur: [defaultCur],
device: { w: screen.width, h: screen.height, language: navigator.language?.split('-')[0], ua: navigator.userAgent },
site: { domain: parseUrl(page).hostname, page: page },
tmax: bidderRequest.timeout,
imp,
};

if (bidderRequest.refererInfo.ref) data.site.ref = bidderRequest.refererInfo.ref;
if (bidderRequest.gdprConsent) {
data.regs = { ext: { gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0 } };
data.user = { ext: { consent: bidderRequest.gdprConsent.consentString || '' } };
}
if (bidderRequest.uspConsent) data.regs.ext.us_privacy = bidderRequest.uspConsent;
if (config.getConfig('coppa')) data.regs.coppa = 1;
if (validBidRequests[0].schain) data.source = { ext: { schain: validBidRequests[0].schain } };

return { method: 'POST', url: endpoint, data };
};

export const interpretResponse = (serverResponse, defaultCur, parseNative) => {
if (!serverResponse || isEmpty(serverResponse.body)) return [];

let bids = [];
serverResponse.body.seatbid.forEach(response => {
response.bid.forEach(bid => {
const mediaType = bid.ext?.mediaType || 'banner';

const bidObj = {
requestId: bid.impid,
cpm: bid.price,
width: bid.w,
height: bid.h,
ttl: 1200,
currency: defaultCur,
netRevenue: true,
creativeId: bid.crid,
dealId: bid.dealid || null,
mediaType,
};

switch (mediaType) {
case 'video':
bidObj.vastUrl = bid.adm;
break;
case 'native':
bidObj.native = parseNative(bid.adm);
break;
default:
bidObj.ad = bid.adm;
}

bids.push(bidObj);
});
});

return bids;
};
Loading

0 comments on commit d949c07

Please sign in to comment.