Skip to content

Commit cb60a03

Browse files
authored
Merge branch 'master' into trustx-bidder-adapter
2 parents 8e0c80c + 3f78470 commit cb60a03

File tree

362 files changed

+10108
-3922
lines changed

Some content is hidden

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

362 files changed

+10108
-3922
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Prebid uses [Mocha](http://mochajs.org/) and [Chai](http://chaijs.com/) for unit
2222
provides mocks, stubs, and spies. [Karma](https://karma-runner.github.io/1.0/index.html) runs the tests and generates
2323
code coverage reports at `build/coverage/lcov/lcov-report/index.html`.
2424

25-
Tests are stored in the [test/spec](test/spec) directory. Tests for Adapters are located in [test/spec/adapters](test/spec/adapters).
25+
Tests are stored in the [test/spec](test/spec) directory. Tests for Adapters are located in [test/spec/modules](test/spec/modules).
2626
They can be run with the following commands:
2727

2828
- `gulp test` - run the test suite once (`npm test` is aliased to call `gulp test`)
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<html>
2+
<head>
3+
<title>PubMatic RTD Provider Example</title>
4+
<script async src="../../build/dev/prebid.js"></script>
5+
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
6+
<script>
7+
var FAILSAFE_TIMEOUT = 3300;
8+
var PREBID_TIMEOUT = 1000;
9+
10+
11+
var adUnits = [{
12+
code: 'div-gpt-ad-1460505748561-0',
13+
mediaTypes: {
14+
banner: {
15+
sizes: [[300, 250], [300,600]],
16+
pos: 7,
17+
}
18+
},
19+
bids: [
20+
{
21+
bidder: 'appnexus',
22+
params: {
23+
placementId: 13144370
24+
}
25+
}, {
26+
bidder: 'pubmatic',
27+
params: {
28+
publisherId: '103207',
29+
adUnit: 'dcomHomeTop-728x90',
30+
}
31+
},
32+
]
33+
}
34+
,
35+
{
36+
code: 'div-gpt-ad-1460505748561-1',
37+
mediaTypes: {
38+
banner: {
39+
sizes: [[728, 90]],
40+
}
41+
},
42+
bids: [
43+
{
44+
bidder: 'appnexus',
45+
params: {
46+
placementId: 13144370
47+
}
48+
}, {
49+
bidder: 'pubmatic',
50+
params: {
51+
publisherId: '103207',
52+
adUnit: 'dcomHomeTop-728x90',
53+
}
54+
}
55+
]
56+
}
57+
];
58+
59+
60+
var pbjs = pbjs || {};
61+
pbjs.que = pbjs.que || [];
62+
63+
64+
</script>
65+
66+
67+
<script>
68+
var googletag = googletag || {};
69+
googletag.cmd = googletag.cmd || [];
70+
var s1;
71+
googletag.cmd.push(function () {
72+
googletag.pubads().disableInitialLoad();
73+
});
74+
75+
76+
pbjs.que.push(function () {
77+
pbjs.setConfig({
78+
enableSendAllBids : true,
79+
enableTIDs: true,
80+
realTimeData: {
81+
auctionDelay: 500,
82+
dataProviders: [
83+
{
84+
name: 'pubmatic',
85+
waitForIt: true,
86+
params:{
87+
publisherId: '103207', // please contact PubMatic to get a publisherId for yourself
88+
profileId: '12', // please contact PubMatic to get a profileId for yourself
89+
}
90+
}
91+
]
92+
}
93+
})
94+
95+
96+
pbjs.addAdUnits(adUnits);
97+
pbjs.enableAnalytics({
98+
provider: 'pubmatic',
99+
options: {
100+
"publisherId": 5890 // please contact PubMatic to get a publisherId for yourself
101+
}
102+
});
103+
104+
105+
pbjs.requestBids({
106+
bidsBackHandler: sendAdserverRequest,
107+
timeout: PREBID_TIMEOUT
108+
});
109+
110+
111+
});
112+
113+
114+
115+
116+
function sendAdserverRequest() {
117+
if (pbjs.adserverRequestSent) return;
118+
pbjs.adserverRequestSent = true;
119+
googletag.cmd.push(function () {
120+
pbjs.que.push(function () {
121+
pbjs.setTargetingForGPTAsync();
122+
googletag.pubads().refresh();
123+
124+
125+
});
126+
});
127+
}
128+
129+
130+
</script>
131+
132+
133+
<script>
134+
googletag.cmd.push(function () {
135+
s1 = googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());
136+
s2 = googletag.defineSlot('/19968336/header-bid-tag-1', [[728, 90]], 'div-gpt-ad-1460505748561-1').addService(googletag.pubads());
137+
138+
139+
googletag.pubads().enableSingleRequest();
140+
googletag.enableServices();
141+
});
142+
143+
144+
145+
146+
function sendAdserverRequest() {
147+
if (pbjs.adserverRequestSent) return;
148+
pbjs.adserverRequestSent = true;
149+
googletag.cmd.push(function () {
150+
pbjs.que.push(function () {
151+
pbjs.setTargetingForGPTAsync();
152+
googletag.pubads().refresh();
153+
154+
155+
});
156+
});
157+
}
158+
</script>
159+
</head>
160+
161+
162+
<body>
163+
<h2>Prebid.js Test</h2>
164+
<h5>Div-1111</h5>
165+
<div id='div-gpt-ad-1460505748561-0'>
166+
<script type='text/javascript'>
167+
googletag.cmd.push(function () { googletag.display('div-gpt-ad-1460505748561-0'); });
168+
</script>
169+
</div>
170+
<br>
171+
172+
173+
<h5>Div 2</h5>
174+
<div id='div-gpt-ad-1460505748561-1'>
175+
<script type='text/javascript'>
176+
googletag.cmd.push(function () { googletag.display('div-gpt-ad-1460505748561-1'); });
177+
</script>
178+
</div>
179+
</body>
180+
</html>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { logInfo } from '../../src/utils.js';
2+
3+
// this allows the stubbing of functions during testing
4+
export const bidderTimeoutFunctions = {
5+
getDeviceType,
6+
checkVideo,
7+
getConnectionSpeed,
8+
calculateTimeoutModifier
9+
};
10+
11+
/**
12+
* Returns an array of a given object's own enumerable string-keyed property [key, value] pairs.
13+
* @param {Object} obj
14+
* @return {Array}
15+
*/
16+
const entries = Object.entries || function (obj) {
17+
const ownProps = Object.keys(obj);
18+
let i = ownProps.length;
19+
let resArray = new Array(i);
20+
while (i--) { resArray[i] = [ownProps[i], obj[ownProps[i]]]; }
21+
return resArray;
22+
};
23+
24+
function getDeviceType() {
25+
const userAgent = window.navigator.userAgent.toLowerCase();
26+
if ((/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(userAgent))) {
27+
return 5; // tablet
28+
}
29+
if ((/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(userAgent))) {
30+
return 4; // mobile
31+
}
32+
return 2; // personal computer
33+
}
34+
35+
function checkVideo(adUnits) {
36+
return adUnits.some((adUnit) => {
37+
return adUnit.mediaTypes && adUnit.mediaTypes.video;
38+
});
39+
}
40+
41+
function getConnectionSpeed() {
42+
const connection = window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection || {}
43+
const connectionType = connection.type || connection.effectiveType;
44+
45+
switch (connectionType) {
46+
case 'slow-2g':
47+
case '2g':
48+
return 'slow';
49+
50+
case '3g':
51+
return 'medium';
52+
53+
case 'bluetooth':
54+
case 'cellular':
55+
case 'ethernet':
56+
case 'wifi':
57+
case 'wimax':
58+
case '4g':
59+
return 'fast';
60+
}
61+
62+
return 'unknown';
63+
}
64+
65+
/**
66+
* Calculate the time to be added to the timeout
67+
* @param {Array} adUnits
68+
* @param {Object} rules
69+
* @return {number}
70+
*/
71+
function calculateTimeoutModifier(adUnits, rules) {
72+
if (!rules) {
73+
return 0;
74+
}
75+
76+
logInfo('Timeout rules', rules);
77+
let timeoutModifier = 0;
78+
let toAdd = 0;
79+
80+
if (rules.includesVideo) {
81+
const hasVideo = bidderTimeoutFunctions.checkVideo(adUnits);
82+
toAdd = rules.includesVideo[hasVideo] || 0;
83+
logInfo(`Adding ${toAdd} to timeout for includesVideo ${hasVideo}`)
84+
timeoutModifier += toAdd;
85+
}
86+
87+
if (rules.numAdUnits) {
88+
const numAdUnits = adUnits.length;
89+
if (rules.numAdUnits[numAdUnits]) {
90+
timeoutModifier += rules.numAdUnits[numAdUnits];
91+
} else {
92+
for (const [rangeStr, timeoutVal] of entries(rules.numAdUnits)) {
93+
const [lowerBound, upperBound] = rangeStr.split('-');
94+
if (parseInt(lowerBound) <= numAdUnits && numAdUnits <= parseInt(upperBound)) {
95+
logInfo(`Adding ${timeoutVal} to timeout for numAdUnits ${numAdUnits}`)
96+
timeoutModifier += timeoutVal;
97+
break;
98+
}
99+
}
100+
}
101+
}
102+
103+
if (rules.deviceType) {
104+
const deviceType = bidderTimeoutFunctions.getDeviceType();
105+
toAdd = rules.deviceType[deviceType] || 0;
106+
logInfo(`Adding ${toAdd} to timeout for deviceType ${deviceType}`)
107+
timeoutModifier += toAdd;
108+
}
109+
110+
if (rules.connectionSpeed) {
111+
const connectionSpeed = bidderTimeoutFunctions.getConnectionSpeed();
112+
toAdd = rules.connectionSpeed[connectionSpeed] || 0;
113+
logInfo(`Adding ${toAdd} to timeout for connectionSpeed ${connectionSpeed}`)
114+
timeoutModifier += toAdd;
115+
}
116+
117+
logInfo('timeout Modifier calculated', timeoutModifier);
118+
return timeoutModifier;
119+
}

0 commit comments

Comments
 (0)