Skip to content

Commit

Permalink
Merge pull request #2 from prebid/master
Browse files Browse the repository at this point in the history
rebase
  • Loading branch information
patmmccann authored Mar 30, 2021
2 parents 35de176 + 971b515 commit 078473b
Show file tree
Hide file tree
Showing 47 changed files with 2,095 additions and 367 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ prebid.requestBids({

$ git clone https://github.com/prebid/Prebid.js.git
$ cd Prebid.js
$ npm install
$ npm ci

*Note:* You need to have `NodeJS` 12.16.1 or greater installed.

*Note:* In the 1.24.0 release of Prebid.js we have transitioned to using gulp 4.0 from using gulp 3.9.1. To comply with gulp's recommended setup for 4.0, you'll need to have `gulp-cli` installed globally prior to running the general `npm install`. This shouldn't impact any other projects you may work on that use an earlier version of gulp in its setup.
*Note:* In the 1.24.0 release of Prebid.js we have transitioned to using gulp 4.0 from using gulp 3.9.1. To comply with gulp's recommended setup for 4.0, you'll need to have `gulp-cli` installed globally prior to running the general `npm ci`. This shouldn't impact any other projects you may work on that use an earlier version of gulp in its setup.

If you have a previous version of `gulp` installed globally, you'll need to remove it before installing `gulp-cli`. You can check if this is installed by running `gulp -v` and seeing the version that's listed in the `CLI` field of the output. If you have the `gulp` package installed globally, it's likely the same version that you'll see in the `Local` field. If you already have `gulp-cli` installed, it should be a lower major version (it's at version `2.0.1` at the time of the transition).

Expand Down Expand Up @@ -265,7 +265,7 @@ directory you will have sourcemaps available in your browser's developer tools.

To run the example file, go to:

+ `http://localhost:9999/integrationExamples/gpt/pbjs_example_gpt.html`
+ `http://localhost:9999/integrationExamples/gpt/hello_world.html`

As you make code changes, the bundles will be rebuilt and the page reloaded automatically.

Expand Down
112 changes: 112 additions & 0 deletions integrationExamples/gpt/adUnitFloors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<!--
This page calls a single bidder for a single ad slot.
It is a specialized example for adding floors to bids using the priceFloors Module
It also makes a good test page for new adapter PR submissions. Simply set your server's Bid Params object in the
bids array inside the adUnits, and it will use your adapter to load an ad.
NOTE that many ad servers won't send back an ad if the URL is localhost... so you might need to
set an alias in your /etc/hosts file so that you can load this page from a different domain.
-->

<html>

<head>
<script async src="../../build/dist/prebid.js"></script>
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
var FAILSAFE_TIMEOUT = 3300;
var PREBID_TIMEOUT = 1000;
var adUnits = [{
code: 'div-gpt-ad-51545-0',
sizes: [[300, 250], [600, 500]],
mediaTypes: {
banner: {
sizes: [[300, 250], [600, 500]]
}
},
// Replace this object to test a new Adapter!
bids: [{
bidder: 'ix',
params: {
siteId: '300',
size: [300, 250]
}
}]
}];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
</script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(function () {
pbjs.addAdUnits(adUnits);
pbjs.setConfig({
floors: {
enforcement: {
floorDeals: false, //default to false
bidAdjustment: true
},
data: { // default if endpoint doesn't return in time
currency: 'USD',
skipRate: 5,
modelVersion: 'BlackBerryZap',
schema: {
fields: ['gptSlot', 'mediaType', 'size']
},
values: {
'*|banner|600x500': 6.5,
'*|banner|300x250': 3.25,
'*|video': 3.5
}
}
}
});
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest,
timeout: PREBID_TIMEOUT
});
});

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>
googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-51545-0').addService(googletag.pubads());

googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>

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

</html>

7 changes: 1 addition & 6 deletions integrationExamples/gpt/creative_rendering.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<!-- #1 deprecated method - use preferred method below instead-->
<script>
try{ window.top.$$PREBID_GLOBAL$$.renderAd(document, '%%PATTERN:hb_adid%%'); } catch(e) {/*ignore*/}
</script>

<!-- #2 preferred method for showing ad - handles cases when $$PREBID_GLOBAL$$ is not in the top window -->
<!-- preferred method for showing ad - handles cases when $$PREBID_GLOBAL$$ is not in the top window -->
<script>
var w = window;
for (i = 0; i < 10; i++) {
Expand Down
3 changes: 3 additions & 0 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@
{
name: "criteo"
},
{
name: "uid2"
}
],
syncDelay: 5000,
auctionDelay: 1000
Expand Down
68 changes: 65 additions & 3 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { OUTSTREAM } from '../src/video.js';

export const BIDDER_CODE = 'adagio';
export const LOG_PREFIX = 'Adagio:';
export const VERSION = '2.7.0';
export const VERSION = '2.8.0';
export const FEATURES_VERSION = '1';
export const ENDPOINT = 'https://mp.4dex.io/prebid';
export const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE, VIDEO];
Expand All @@ -23,7 +23,7 @@ export const ADAGIO_LOCALSTORAGE_KEY = 'adagioScript';
export const GVLID = 617;
export const storage = getStorageManager(GVLID, 'adagio');
export const RENDERER_URL = 'https://script.4dex.io/outstream-player.js';

export const MAX_SESS_DURATION = 30 * 60 * 1000;
export const ADAGIO_PUBKEY = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9el0+OEn6fvEh1RdVHQu4cnT0
jFSzIbGJJyg3cKqvtE6A0iaz9PkIdJIvSSSNrmJv+lRGKPEyRA/VnzJIieL39Ngl
Expand Down Expand Up @@ -62,6 +62,8 @@ export const ORTB_VIDEO_PARAMS = {

let currentWindow;

const EXT_DATA = {}

export function adagioScriptFromLocalStorageCb(ls) {
try {
if (!ls) {
Expand Down Expand Up @@ -108,6 +110,9 @@ export function getAdagioScript() {
// It's an antipattern regarding the TCF2 enforcement logic
// but it's the only way to respect the user choice update.
window.localStorage.removeItem(ADAGIO_LOCALSTORAGE_KEY);
// Extra data from external script.
// This key is removed only if localStorage is not accessible.
window.localStorage.removeItem('adagio');
}
});
}
Expand All @@ -131,6 +136,37 @@ function isSafeFrameWindow() {
return !!(ws.$sf && ws.$sf.ext);
}

// Get localStorage "adagio" data to be passed to the request
export function prepareExchange(storageValue) {
const adagioStorage = JSON.parse(storageValue, function(name, value) {
if (!name.startsWith('_') || name === '') {
return value;
}
});
let random = utils.deepAccess(adagioStorage, 'session.rnd');
let newSession = false;

if (internal.isNewSession(adagioStorage)) {
newSession = true;
random = Math.random();
}

const data = {
session: {
new: newSession,
rnd: random
}
}

utils.mergeDeep(EXT_DATA, adagioStorage, data);

internal.enqueue({
action: 'session',
ts: Date.now(),
data: EXT_DATA
});
}

function initAdagio() {
if (canAccessTopWindow()) {
currentWindow = (canAccessTopWindow()) ? utils.getWindowTop() : utils.getWindowSelf();
Expand All @@ -146,6 +182,14 @@ function initAdagio() {
w.ADAGIO.versions.adagioBidderAdapter = VERSION;
w.ADAGIO.isSafeFrameWindow = isSafeFrameWindow();

storage.getDataFromLocalStorage('adagio', (storageData) => {
try {
internal.prepareExchange(storageData);
} catch (e) {
utils.logError(LOG_PREFIX, e);
}
});

getAdagioScript();
}

Expand Down Expand Up @@ -561,6 +605,21 @@ function isRendererPreferredFromPublisher(bidRequest) {
);
}

/**
*
* @param {object} adagioStorage
* @returns {boolean}
*/
function isNewSession(adagioStorage) {
const now = Date.now();
const { lastActivityTime, vwSmplg } = utils.deepAccess(adagioStorage, 'session', {});
return (
!utils.isNumber(lastActivityTime) ||
!utils.isNumber(vwSmplg) ||
(now - lastActivityTime) > MAX_SESS_DURATION
)
}

export const internal = {
enqueue,
getOrAddAdagioAdUnit,
Expand All @@ -577,7 +636,9 @@ export const internal = {
getCurrentWindow,
supportIObs,
canAccessTopWindow,
isRendererPreferredFromPublisher
isRendererPreferredFromPublisher,
isNewSession,
prepareExchange
};

function _getGdprConsent(bidderRequest) {
Expand Down Expand Up @@ -918,6 +979,7 @@ export const spec = {
site: site,
pageviewId: pageviewId,
adUnits: groupedAdUnits[organizationId],
data: EXT_DATA,
regs: {
gdpr: gdprConsent,
coppa: coppa,
Expand Down
79 changes: 79 additions & 0 deletions modules/addefendBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'addefend';

export const spec = {
code: BIDDER_CODE,
hostname: 'https://addefend-platform.com',

getHostname() {
return this.hostname;
},
isBidRequestValid: function(bid) {
return (bid.sizes !== undefined && bid.bidId !== undefined && bid.params !== undefined &&
(bid.params.pageId !== undefined && (typeof bid.params.pageId === 'string')) &&
(bid.params.placementId !== undefined && (typeof bid.params.placementId === 'string')));
},
buildRequests: function(validBidRequests, bidderRequest) {
let bid = {
v: $$PREBID_GLOBAL$$.version,
auctionId: false,
pageId: false,
gdpr_consent: bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString ? bidderRequest.gdprConsent.consentString : '',
referer: bidderRequest.refererInfo.referer,
bids: [],
};

for (var i = 0; i < validBidRequests.length; i++) {
let vb = validBidRequests[i];
let o = vb.params;
bid.auctionId = vb.auctionId;
o.bidId = vb.bidId;
o.transactionId = vb.transactionId;
o.sizes = [];
if (o.trafficTypes) {
bid.trafficTypes = o.trafficTypes;
}
delete o.trafficTypes;

bid.pageId = o.pageId;
delete o.pageId;

if (vb.sizes && Array.isArray(vb.sizes)) {
for (var j = 0; j < vb.sizes.length; j++) {
let s = vb.sizes[j];
if (Array.isArray(s) && s.length == 2) {
o.sizes.push(s[0] + 'x' + s[1]);
}
}
}
bid.bids.push(o);
}
return [{
method: 'POST',
url: this.getHostname() + '/bid',
options: { withCredentials: true },
data: bid
}];
},
interpretResponse: function(serverResponse, request) {
const requiredKeys = ['requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', 'netRevenue', 'currency', 'advertiserDomains'];
const validBidResponses = [];
serverResponse = serverResponse.body;
if (serverResponse && (serverResponse.length > 0)) {
serverResponse.forEach((bid) => {
const bidResponse = {};
for (const requiredKey of requiredKeys) {
if (!bid.hasOwnProperty(requiredKey)) {
return [];
}
bidResponse[requiredKey] = bid[requiredKey];
}
validBidResponses.push(bidResponse);
});
}
return validBidResponses;
}
}

registerBidder(spec);
Loading

0 comments on commit 078473b

Please sign in to comment.