Skip to content

Commit

Permalink
Merge branch 'prebid:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
samous authored Nov 6, 2023
2 parents 04ac209 + a069331 commit 4c46f1b
Show file tree
Hide file tree
Showing 302 changed files with 12,867 additions and 3,278 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/issue_tracker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@0914d50df753bbc42180d982a6550f195390069f
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
with:
app_id: ${{ secrets.ISSUE_APP_ID }}
private_key: ${{ secrets.ISSUE_APP_PEM }}
Expand Down
1 change: 0 additions & 1 deletion PR_REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Follow steps above for general review process. In addition, please verify the fo
- Adapters that accept a floor parameter must also support the [floors module](https://docs.prebid.org/dev-docs/modules/floors.html) -- look for a call to the `getFloor()` function.
- Adapters cannot accept an schain parameter. Rather, they must look for the schain parameter at bidRequest.schain.
- The bidderRequest.refererInfo.referer must be checked in addition to any bidder-specific parameter.
- If they're getting the COPPA flag, it must come from config.getConfig('coppa');
- Page position must come from bidrequest.mediaTypes.banner.pos or bidrequest.mediaTypes.video.pos
- Global OpenRTB fields should come from [getConfig('ortb2');](https://docs.prebid.org/dev-docs/publisher-api-reference/setConfig.html#setConfig-fpd):
- bcat, battr, badv
Expand Down
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"NATIVE",
"VIDEO"
"VIDEO",
"UID2_CSTG"
]
30 changes: 17 additions & 13 deletions integrationExamples/gpt/hello_world.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-->

<html>

<head>
<script async src="../../build/dev/prebid.js"></script>
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script>
Expand All @@ -19,9 +20,10 @@
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250], [300,600]],
sizes: [[300, 250]],
}
},

// Replace this object to test a new Adapter!
bids: [{
bidder: 'appnexus',
Expand All @@ -40,12 +42,13 @@
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(function() {
pbjs.que.push(function () {
pbjs.addAdUnits(adUnits);

pbjs.requestBids({
bidsBackHandler: sendAdserverRequest,
timeout: PREBID_TIMEOUT
Expand All @@ -55,15 +58,15 @@
function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function() {
pbjs.que.push(function() {
googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}

setTimeout(function() {
setTimeout(function () {
sendAdserverRequest();
}, FAILSAFE_TIMEOUT);

Expand All @@ -80,12 +83,13 @@
</head>

<body>
<h2>Prebid.js Test</h2>
<h5>Div-1</h5>
<div id='div-gpt-ad-1460505748561-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1460505748561-0'); });
</script>
</div>
<h2>Prebid.js Test</h2>
<h5>Div-1</h5>
<div id='div-gpt-ad-1460505748561-0'>
<script type='text/javascript'>
googletag.cmd.push(function () { googletag.display('div-gpt-ad-1460505748561-0'); });
</script>
</div>
</body>

</html>
40 changes: 25 additions & 15 deletions integrationExamples/gpt/prebidServer_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,41 @@

pbjs.que.push(function() {
var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: 'appnexus',
params: {
placementId: 13144370
}
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [600, 500]
}
},
bids: [
{
bidder: 'appnexus',
params: {
placementId: 12883451
}
]
}];
}
]
}];

pbjs.bidderSettings = {
appnexus: {
bidCpmAdjustment: function () {
return 10;
}
}
}
pbjs.setConfig({
bidderTimeout: 3000,
s2sConfig : {
accountId : '1',
enabled : true, //default value set to false
defaultVendor: 'appnexus',
defaultVendor: 'appnexuspsp',
bidders : ['appnexus'],
timeout : 1000, //default value is 1000
adapter : 'prebidServer', //if we have any other s2s adapter, default value is s2s
},
ortb2: {
test: 1
}
});

Expand Down
2 changes: 1 addition & 1 deletion integrationExamples/gpt/prebidServer_fledge_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
s2sConfig: [{
accountId : '1',
enabled : true,
defaultVendor: 'appnexus',
defaultVendor: 'appnexuspsp',
bidders : ['openx'],
timeout : 1500,
adapter : 'prebidServer'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {_each, deepAccess, getValueString, isArray, isStr, mergeDeep, isNumber} from '../../src/utils.js';
import {_each, deepAccess, isArray, isNumber, isStr, mergeDeep, logWarn} from '../../src/utils.js';
import {getAllOrtbKeywords} from '../keywords/keywords.js';
import {CLIENT_SECTIONS} from '../../src/fpd/oneClient.js';

Expand All @@ -12,6 +12,19 @@ const ORTB_SEG_PATHS = ['user.data'].concat(
CLIENT_SECTIONS.map((prefix) => `${prefix}.content.data`)
);

function getValueString(param, val, defaultValue) {
if (val === undefined || val === null) {
return defaultValue;
}
if (isStr(val)) {
return val;
}
if (isNumber(val)) {
return val.toString();
}
logWarn('Unsuported type for param: ' + param + ' required type: String');
}

/**
* Converts an object of arrays (either strings or numbers) into an array of objects containing key and value properties
* normally read from bidder params
Expand Down
25 changes: 25 additions & 0 deletions libraries/appnexusUtils/anUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Converts a string value in camel-case to underscore eg 'placementId' becomes 'placement_id'
* @param {string} value string value to convert
*/
import {deepClone, isPlainObject} from '../../src/utils.js';

export function convertCamelToUnderscore(value) {
return value.replace(/(?:^|\.?)([A-Z])/g, function (x, y) {
return '_' + y.toLowerCase();
}).replace(/^_/, '');
}

/**
* Creates an array of n length and fills each item with the given value
*/
export function fill(value, length) {
let newArray = [];

for (let i = 0; i < length; i++) {
let valueToPush = isPlainObject(value) ? deepClone(value) : value;
newArray.push(valueToPush);
}

return newArray;
}
19 changes: 19 additions & 0 deletions libraries/chunk/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* http://npm.im/chunk
* Returns an array with *size* chunks from given array
*
* Example:
* ['a', 'b', 'c', 'd', 'e'] chunked by 2 =>
* [['a', 'b'], ['c', 'd'], ['e']]
*/
export function chunk(array, size) {
let newArray = [];

for (let i = 0; i < Math.ceil(array.length / size); i++) {
let start = i * size;
let end = start + size;
newArray.push(array.slice(start, end));
}

return newArray;
}
37 changes: 37 additions & 0 deletions libraries/gptUtils/gptUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {find} from '../../src/polyfill.js';
import {compareCodeAndSlot, isGptPubadsDefined} from '../../src/utils.js';

/**
* Returns filter function to match adUnitCode in slot
* @param {string} adUnitCode AdUnit code
* @return {function} filter function
*/
export function isSlotMatchingAdUnitCode(adUnitCode) {
return (slot) => compareCodeAndSlot(slot, adUnitCode);
}

/**
* @summary Uses the adUnit's code in order to find a matching gpt slot object on the page
*/
export function getGptSlotForAdUnitCode(adUnitCode) {
let matchingSlot;
if (isGptPubadsDefined()) {
// find the first matching gpt slot on the page
matchingSlot = find(window.googletag.pubads().getSlots(), isSlotMatchingAdUnitCode(adUnitCode));
}
return matchingSlot;
}

/**
* @summary Uses the adUnit's code in order to find a matching gptSlot on the page
*/
export function getGptSlotInfoForAdUnitCode(adUnitCode) {
const matchingSlot = getGptSlotForAdUnitCode(adUnitCode);
if (matchingSlot) {
return {
gptSlot: matchingSlot.getAdUnitPath(),
divId: matchingSlot.getSlotElementId()
};
}
return {};
}
26 changes: 26 additions & 0 deletions libraries/htmlEscape/htmlEscape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Encode a string for inclusion in HTML.
* See https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss.html and
* https://codeql.github.com/codeql-query-help/javascript/js-bad-code-sanitization/
* @return {string}
*/
export const escapeUnsafeChars = (() => {
const escapes = {
'<': '\\u003C',
'>': '\\u003E',
'/': '\\u002F',
'\\': '\\\\',
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\0': '\\0',
'\u2028': '\\u2028',
'\u2029': '\\u2029'
};

return function (str) {
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, x => escapes[x]);
};
})();
29 changes: 29 additions & 0 deletions libraries/sizeUtils/sizeUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Read an adUnit object and return the sizes used in an [[728, 90]] format (even if they had [728, 90] defined)
* Preference is given to the `adUnit.mediaTypes.banner.sizes` object over the `adUnit.sizes`
* @param {object} adUnit one adUnit object from the normal list of adUnits
* @returns {Array.<number[]>} array of arrays containing numeric sizes
*/
export function getAdUnitSizes(adUnit) {
if (!adUnit) {
return;
}

let sizes = [];
if (adUnit.mediaTypes && adUnit.mediaTypes.banner && Array.isArray(adUnit.mediaTypes.banner.sizes)) {
let bannerSizes = adUnit.mediaTypes.banner.sizes;
if (Array.isArray(bannerSizes[0])) {
sizes = bannerSizes;
} else {
sizes.push(bannerSizes);
}
// TODO - remove this else block when we're ready to deprecate adUnit.sizes for bidders
} else if (Array.isArray(adUnit.sizes)) {
if (Array.isArray(adUnit.sizes[0])) {
sizes = adUnit.sizes;
} else {
sizes.push(adUnit.sizes);
}
}
return sizes;
}
36 changes: 36 additions & 0 deletions libraries/transformParamsUtils/convertTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {isFn} from '../../src/utils.js';

/**
* Try to convert a value to a type.
* If it can't be done, the value will be returned.
*
* @param {string} typeToConvert The target type. e.g. "string", "number", etc.
* @param {*} value The value to be converted into typeToConvert.
*/
function tryConvertType(typeToConvert, value) {
if (typeToConvert === 'string') {
return value && value.toString();
} else if (typeToConvert === 'number') {
return Number(value);
} else {
return value;
}
}

export function convertTypes(types, params) {
Object.keys(types).forEach(key => {
if (params[key]) {
if (isFn(types[key])) {
params[key] = types[key](params[key]);
} else {
params[key] = tryConvertType(types[key], params[key]);
}

// don't send invalid values
if (isNaN(params[key])) {
delete params.key;
}
}
});
return params;
}
14 changes: 14 additions & 0 deletions libraries/uid2Eids/uid2Eids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const UID2_EIDS = {
'uid2': {
source: 'uidapi.com',
atype: 3,
getValue: function(data) {
return data.id;
},
getUidExt: function(data) {
if (data.ext) {
return data.ext;
}
}
}
}
7 changes: 7 additions & 0 deletions libraries/urlUtils/urlUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function tryAppendQueryString(existingUrl, key, value) {
if (value) {
return existingUrl + key + '=' + encodeURIComponent(value) + '&';
}

return existingUrl;
}
Loading

0 comments on commit 4c46f1b

Please sign in to comment.