Skip to content

Commit 078473b

Browse files
authored
Merge pull request #2 from prebid/master
rebase
2 parents 35de176 + 971b515 commit 078473b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2095
-367
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ prebid.requestBids({
112112

113113
$ git clone https://github.com/prebid/Prebid.js.git
114114
$ cd Prebid.js
115-
$ npm install
115+
$ npm ci
116116

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

119-
*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.
119+
*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.
120120

121121
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).
122122

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

266266
To run the example file, go to:
267267

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

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

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!--
2+
This page calls a single bidder for a single ad slot.
3+
It is a specialized example for adding floors to bids using the priceFloors Module
4+
It also makes a good test page for new adapter PR submissions. Simply set your server's Bid Params object in the
5+
bids array inside the adUnits, and it will use your adapter to load an ad.
6+
NOTE that many ad servers won't send back an ad if the URL is localhost... so you might need to
7+
set an alias in your /etc/hosts file so that you can load this page from a different domain.
8+
-->
9+
10+
<html>
11+
12+
<head>
13+
<script async src="../../build/dist/prebid.js"></script>
14+
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
15+
<script>
16+
var FAILSAFE_TIMEOUT = 3300;
17+
var PREBID_TIMEOUT = 1000;
18+
var adUnits = [{
19+
code: 'div-gpt-ad-51545-0',
20+
sizes: [[300, 250], [600, 500]],
21+
mediaTypes: {
22+
banner: {
23+
sizes: [[300, 250], [600, 500]]
24+
}
25+
},
26+
// Replace this object to test a new Adapter!
27+
bids: [{
28+
bidder: 'ix',
29+
params: {
30+
siteId: '300',
31+
size: [300, 250]
32+
}
33+
}]
34+
}];
35+
var pbjs = pbjs || {};
36+
pbjs.que = pbjs.que || [];
37+
</script>
38+
<script>
39+
var googletag = googletag || {};
40+
googletag.cmd = googletag.cmd || [];
41+
googletag.cmd.push(function () {
42+
googletag.pubads().disableInitialLoad();
43+
});
44+
45+
pbjs.que.push(function () {
46+
pbjs.addAdUnits(adUnits);
47+
pbjs.setConfig({
48+
floors: {
49+
enforcement: {
50+
floorDeals: false, //default to false
51+
bidAdjustment: true
52+
},
53+
data: { // default if endpoint doesn't return in time
54+
currency: 'USD',
55+
skipRate: 5,
56+
modelVersion: 'BlackBerryZap',
57+
schema: {
58+
fields: ['gptSlot', 'mediaType', 'size']
59+
},
60+
values: {
61+
'*|banner|600x500': 6.5,
62+
'*|banner|300x250': 3.25,
63+
'*|video': 3.5
64+
}
65+
}
66+
}
67+
});
68+
pbjs.requestBids({
69+
bidsBackHandler: sendAdserverRequest,
70+
timeout: PREBID_TIMEOUT
71+
});
72+
});
73+
74+
function sendAdserverRequest() {
75+
if (pbjs.adserverRequestSent) return;
76+
pbjs.adserverRequestSent = true;
77+
googletag.cmd.push(function () {
78+
pbjs.que.push(function () {
79+
pbjs.setTargetingForGPTAsync();
80+
googletag.pubads().refresh();
81+
});
82+
});
83+
}
84+
85+
setTimeout(function () {
86+
sendAdserverRequest();
87+
}, FAILSAFE_TIMEOUT);
88+
89+
</script>
90+
91+
<script>
92+
googletag.cmd.push(function () {
93+
googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-51545-0').addService(googletag.pubads());
94+
95+
googletag.pubads().enableSingleRequest();
96+
googletag.enableServices();
97+
});
98+
</script>
99+
</head>
100+
101+
<body>
102+
<h2>Prebid.js Test</h2>
103+
<h5>Div-1</h5>
104+
<div id='div-gpt-ad-51545-0'>
105+
<script type='text/javascript'>
106+
googletag.cmd.push(function () { googletag.display('div-gpt-ad-51545-0'); });
107+
</script>
108+
</div>
109+
</body>
110+
111+
</html>
112+

integrationExamples/gpt/creative_rendering.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
<!-- #1 deprecated method - use preferred method below instead-->
2-
<script>
3-
try{ window.top.$$PREBID_GLOBAL$$.renderAd(document, '%%PATTERN:hb_adid%%'); } catch(e) {/*ignore*/}
4-
</script>
5-
6-
<!-- #2 preferred method for showing ad - handles cases when $$PREBID_GLOBAL$$ is not in the top window -->
1+
<!-- preferred method for showing ad - handles cases when $$PREBID_GLOBAL$$ is not in the top window -->
72
<script>
83
var w = window;
94
for (i = 0; i < 10; i++) {

integrationExamples/gpt/userId_example.html

+3
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@
277277
{
278278
name: "criteo"
279279
},
280+
{
281+
name: "uid2"
282+
}
280283
],
281284
syncDelay: 5000,
282285
auctionDelay: 1000

modules/adagioBidAdapter.js

+65-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { OUTSTREAM } from '../src/video.js';
1414

1515
export const BIDDER_CODE = 'adagio';
1616
export const LOG_PREFIX = 'Adagio:';
17-
export const VERSION = '2.7.0';
17+
export const VERSION = '2.8.0';
1818
export const FEATURES_VERSION = '1';
1919
export const ENDPOINT = 'https://mp.4dex.io/prebid';
2020
export const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE, VIDEO];
@@ -23,7 +23,7 @@ export const ADAGIO_LOCALSTORAGE_KEY = 'adagioScript';
2323
export const GVLID = 617;
2424
export const storage = getStorageManager(GVLID, 'adagio');
2525
export const RENDERER_URL = 'https://script.4dex.io/outstream-player.js';
26-
26+
export const MAX_SESS_DURATION = 30 * 60 * 1000;
2727
export const ADAGIO_PUBKEY = `-----BEGIN PUBLIC KEY-----
2828
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9el0+OEn6fvEh1RdVHQu4cnT0
2929
jFSzIbGJJyg3cKqvtE6A0iaz9PkIdJIvSSSNrmJv+lRGKPEyRA/VnzJIieL39Ngl
@@ -62,6 +62,8 @@ export const ORTB_VIDEO_PARAMS = {
6262

6363
let currentWindow;
6464

65+
const EXT_DATA = {}
66+
6567
export function adagioScriptFromLocalStorageCb(ls) {
6668
try {
6769
if (!ls) {
@@ -108,6 +110,9 @@ export function getAdagioScript() {
108110
// It's an antipattern regarding the TCF2 enforcement logic
109111
// but it's the only way to respect the user choice update.
110112
window.localStorage.removeItem(ADAGIO_LOCALSTORAGE_KEY);
113+
// Extra data from external script.
114+
// This key is removed only if localStorage is not accessible.
115+
window.localStorage.removeItem('adagio');
111116
}
112117
});
113118
}
@@ -131,6 +136,37 @@ function isSafeFrameWindow() {
131136
return !!(ws.$sf && ws.$sf.ext);
132137
}
133138

139+
// Get localStorage "adagio" data to be passed to the request
140+
export function prepareExchange(storageValue) {
141+
const adagioStorage = JSON.parse(storageValue, function(name, value) {
142+
if (!name.startsWith('_') || name === '') {
143+
return value;
144+
}
145+
});
146+
let random = utils.deepAccess(adagioStorage, 'session.rnd');
147+
let newSession = false;
148+
149+
if (internal.isNewSession(adagioStorage)) {
150+
newSession = true;
151+
random = Math.random();
152+
}
153+
154+
const data = {
155+
session: {
156+
new: newSession,
157+
rnd: random
158+
}
159+
}
160+
161+
utils.mergeDeep(EXT_DATA, adagioStorage, data);
162+
163+
internal.enqueue({
164+
action: 'session',
165+
ts: Date.now(),
166+
data: EXT_DATA
167+
});
168+
}
169+
134170
function initAdagio() {
135171
if (canAccessTopWindow()) {
136172
currentWindow = (canAccessTopWindow()) ? utils.getWindowTop() : utils.getWindowSelf();
@@ -146,6 +182,14 @@ function initAdagio() {
146182
w.ADAGIO.versions.adagioBidderAdapter = VERSION;
147183
w.ADAGIO.isSafeFrameWindow = isSafeFrameWindow();
148184

185+
storage.getDataFromLocalStorage('adagio', (storageData) => {
186+
try {
187+
internal.prepareExchange(storageData);
188+
} catch (e) {
189+
utils.logError(LOG_PREFIX, e);
190+
}
191+
});
192+
149193
getAdagioScript();
150194
}
151195

@@ -561,6 +605,21 @@ function isRendererPreferredFromPublisher(bidRequest) {
561605
);
562606
}
563607

608+
/**
609+
*
610+
* @param {object} adagioStorage
611+
* @returns {boolean}
612+
*/
613+
function isNewSession(adagioStorage) {
614+
const now = Date.now();
615+
const { lastActivityTime, vwSmplg } = utils.deepAccess(adagioStorage, 'session', {});
616+
return (
617+
!utils.isNumber(lastActivityTime) ||
618+
!utils.isNumber(vwSmplg) ||
619+
(now - lastActivityTime) > MAX_SESS_DURATION
620+
)
621+
}
622+
564623
export const internal = {
565624
enqueue,
566625
getOrAddAdagioAdUnit,
@@ -577,7 +636,9 @@ export const internal = {
577636
getCurrentWindow,
578637
supportIObs,
579638
canAccessTopWindow,
580-
isRendererPreferredFromPublisher
639+
isRendererPreferredFromPublisher,
640+
isNewSession,
641+
prepareExchange
581642
};
582643

583644
function _getGdprConsent(bidderRequest) {
@@ -918,6 +979,7 @@ export const spec = {
918979
site: site,
919980
pageviewId: pageviewId,
920981
adUnits: groupedAdUnits[organizationId],
982+
data: EXT_DATA,
921983
regs: {
922984
gdpr: gdprConsent,
923985
coppa: coppa,

modules/addefendBidAdapter.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import {registerBidder} from '../src/adapters/bidderFactory.js';
2+
3+
const BIDDER_CODE = 'addefend';
4+
5+
export const spec = {
6+
code: BIDDER_CODE,
7+
hostname: 'https://addefend-platform.com',
8+
9+
getHostname() {
10+
return this.hostname;
11+
},
12+
isBidRequestValid: function(bid) {
13+
return (bid.sizes !== undefined && bid.bidId !== undefined && bid.params !== undefined &&
14+
(bid.params.pageId !== undefined && (typeof bid.params.pageId === 'string')) &&
15+
(bid.params.placementId !== undefined && (typeof bid.params.placementId === 'string')));
16+
},
17+
buildRequests: function(validBidRequests, bidderRequest) {
18+
let bid = {
19+
v: $$PREBID_GLOBAL$$.version,
20+
auctionId: false,
21+
pageId: false,
22+
gdpr_consent: bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString ? bidderRequest.gdprConsent.consentString : '',
23+
referer: bidderRequest.refererInfo.referer,
24+
bids: [],
25+
};
26+
27+
for (var i = 0; i < validBidRequests.length; i++) {
28+
let vb = validBidRequests[i];
29+
let o = vb.params;
30+
bid.auctionId = vb.auctionId;
31+
o.bidId = vb.bidId;
32+
o.transactionId = vb.transactionId;
33+
o.sizes = [];
34+
if (o.trafficTypes) {
35+
bid.trafficTypes = o.trafficTypes;
36+
}
37+
delete o.trafficTypes;
38+
39+
bid.pageId = o.pageId;
40+
delete o.pageId;
41+
42+
if (vb.sizes && Array.isArray(vb.sizes)) {
43+
for (var j = 0; j < vb.sizes.length; j++) {
44+
let s = vb.sizes[j];
45+
if (Array.isArray(s) && s.length == 2) {
46+
o.sizes.push(s[0] + 'x' + s[1]);
47+
}
48+
}
49+
}
50+
bid.bids.push(o);
51+
}
52+
return [{
53+
method: 'POST',
54+
url: this.getHostname() + '/bid',
55+
options: { withCredentials: true },
56+
data: bid
57+
}];
58+
},
59+
interpretResponse: function(serverResponse, request) {
60+
const requiredKeys = ['requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', 'netRevenue', 'currency', 'advertiserDomains'];
61+
const validBidResponses = [];
62+
serverResponse = serverResponse.body;
63+
if (serverResponse && (serverResponse.length > 0)) {
64+
serverResponse.forEach((bid) => {
65+
const bidResponse = {};
66+
for (const requiredKey of requiredKeys) {
67+
if (!bid.hasOwnProperty(requiredKey)) {
68+
return [];
69+
}
70+
bidResponse[requiredKey] = bid[requiredKey];
71+
}
72+
validBidResponses.push(bidResponse);
73+
});
74+
}
75+
return validBidResponses;
76+
}
77+
}
78+
79+
registerBidder(spec);

0 commit comments

Comments
 (0)