Skip to content

Commit 4992c8c

Browse files
Merge pull request #36 from prebid/master
Update remote repository
2 parents 10a6dc0 + aa118c7 commit 4992c8c

28 files changed

+2132
-356
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta http-equiv="Delegate-CH" content="sec-ch-ua-full-version-list https://cloud.51degrees.com; sec-ch-ua-model https://cloud.51degrees.com; sec-ch-ua-platform https://cloud.51degrees.com; sec-ch-ua-platform-version https://cloud.51degrees.com">
5+
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
6+
<script async src="../../build/dev/prebid.js"></script>
7+
<meta charset="utf-8">
8+
<style>
9+
body {
10+
color: #555;
11+
font-family: sans-serif;
12+
}
13+
</style>
14+
<script>
15+
var PREBID_TIMEOUT = 1000;
16+
var FAILSAFE_TIMEOUT = 3000;
17+
18+
var googletag = googletag || {};
19+
googletag.cmd = googletag.cmd || [];
20+
21+
var pbjs = pbjs || {};
22+
pbjs.que = pbjs.que || [];
23+
24+
function initAdserver() {
25+
if (pbjs.initAdserverSet) return;
26+
27+
googletag.cmd.push(function () {
28+
pbjs.que.push(function () {
29+
pbjs.setTargetingForGPTAsync();
30+
googletag.pubads().refresh();
31+
});
32+
});
33+
34+
pbjs.initAdserverSet = true;
35+
}
36+
37+
pbjs.que.push(function () {
38+
var adUnits = [{
39+
code: 'div-banner-native-1',
40+
mediaTypes: {
41+
banner: {
42+
sizes: [
43+
[300, 250]
44+
]
45+
},
46+
native: {
47+
type: 'image'
48+
},
49+
},
50+
bids: [{
51+
bidder: 'appnexus',
52+
params: {
53+
placementId: 13232392,
54+
}
55+
}]
56+
},
57+
{
58+
code: 'div-banner-native-2',
59+
mediaTypes: {
60+
banner: {
61+
sizes: [
62+
[300, 250]
63+
]
64+
},
65+
native: {
66+
title: {
67+
required: true
68+
},
69+
image: {
70+
required: true
71+
},
72+
sponsoredBy: {
73+
required: true
74+
}
75+
}
76+
},
77+
bids: [{
78+
bidder: 'appnexus',
79+
params: {
80+
placementId: 13232392,
81+
}
82+
}]
83+
}
84+
];
85+
86+
pbjs.setConfig({
87+
debug: true, // use only for testing, remove in production
88+
realTimeData: {
89+
auctionDelay: 1000, // should be set lower in production use
90+
dataProviders: [
91+
{
92+
name: '51Degrees',
93+
waitForIt: true,
94+
params: {
95+
// Get your resource key from https://configure.51degrees.com/tWrhNfY6
96+
resourceKey: '<YOUR_RESOURCE_KEY>',
97+
// alternatively, you can use the on-premise version of the 51Degrees service and connect to your chosen end point
98+
// onPremiseJSUrl: 'https://localhost/51Degrees.core.js'
99+
}
100+
}
101+
]
102+
},
103+
});
104+
105+
pbjs.addAdUnits(adUnits);
106+
107+
pbjs.onEvent('bidRequested', function (data) {
108+
try {
109+
fod.complete(() => {
110+
document.getElementById('enriched-51').style.display = 'block';
111+
document.getElementById('enriched-51-data').textContent = JSON.stringify(data.ortb2.device, null, 2);
112+
});
113+
} catch (e) {
114+
console.error('Error while trying to display enriched data', e);
115+
}
116+
});
117+
118+
pbjs.requestBids({
119+
timeout: PREBID_TIMEOUT,
120+
bidsBackHandler: function (bidResponses) {
121+
initAdserver();
122+
}
123+
});
124+
});
125+
setTimeout(initAdserver, FAILSAFE_TIMEOUT);
126+
</script>
127+
128+
<script>
129+
googletag.cmd.push(function () {
130+
googletag
131+
.defineSlot(
132+
'/19968336/prebid_multiformat_test', [
133+
[300, 250],
134+
[360, 360]
135+
],
136+
'div-banner-native-1'
137+
)
138+
.addService(googletag.pubads());
139+
140+
googletag
141+
.defineSlot(
142+
'/19968336/prebid_multiformat_test', [
143+
[300, 250],
144+
[360, 360]
145+
],
146+
'div-banner-native-2'
147+
)
148+
.addService(googletag.pubads());
149+
150+
googletag.pubads().disableInitialLoad();
151+
googletag.pubads().enableSingleRequest();
152+
googletag.enableServices();
153+
});
154+
</script>
155+
<title>51Degrees RTD submodule example - Prebid.js</title>
156+
</head>
157+
<body>
158+
<h2>51Degrees RTD submodule - example of usage</h2>
159+
160+
<h3>div-banner-native-1</h3>
161+
<div id='div-banner-native-1'>
162+
<p>No response</p>
163+
<script type='text/javascript'>
164+
googletag.cmd.push(function () {
165+
googletag.display('div-banner-native-1');
166+
});
167+
</script>
168+
</div>
169+
170+
<h3>div-banner-native-2</h3>
171+
<div id='div-banner-native-2'>
172+
<p>No response</p>
173+
<script type='text/javascript'>
174+
googletag.cmd.push(function () {
175+
googletag.display('div-banner-native-2');
176+
});
177+
</script>
178+
</div>
179+
180+
<div id="debug">
181+
<h3>Testing/Debugging Guidance</h3>
182+
<ol>
183+
<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!)
184+
<li>Make sure you have replaced <code>&lt;YOUR RESOURCE KEY&gt;</code> in this example code with the one you have obtained
185+
from the <a href="https://configure.51degrees.com/tWrhNfY6" target="blank;">51Degrees Configurator Tool</a></li>
186+
<li>Open DevTools Console in your browser and refresh the page</li>
187+
<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>
188+
</ol>
189+
190+
</div>
191+
<div id="enriched-51" style="display: none">
192+
<h3>Enriched ORTB2 device data</h3>
193+
<pre id="enriched-51-data"></pre>
194+
</div>
195+
</body>
196+
</html>

modules/1plusXRtdProvider.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { submodule } from '../src/hook.js';
2+
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';
23
import { ajax } from '../src/ajax.js';
4+
import { getStorageManager, STORAGE_TYPE_COOKIES, STORAGE_TYPE_LOCALSTORAGE } from '../src/storageManager.js';
35
import {
46
logMessage, logError,
57
deepAccess, deepSetValue, mergeDeep,
@@ -13,6 +15,9 @@ const ORTB2_NAME = '1plusX.com'
1315
const PAPI_VERSION = 'v1.0';
1416
const LOG_PREFIX = '[1plusX RTD Module]: ';
1517
const OPE_FPID = 'ope_fpid'
18+
19+
export const fpidStorage = getStorageManager({ moduleType: MODULE_TYPE_RTD, moduleName: MODULE_NAME });
20+
1621
export const segtaxes = {
1722
// cf. https://github.com/InteractiveAdvertisingBureau/openrtb/pull/108
1823
AUDIENCE: 526,
@@ -53,7 +58,19 @@ export const extractConfig = (moduleConfig, reqBidsConfigObj) => {
5358
throw new Error('No bidRequestConfig bidder found in moduleConfig bidders');
5459
}
5560

56-
return { customerId, timeout, bidders };
61+
const fpidStorageType = deepAccess(moduleConfig, 'params.fpidStorageType',
62+
STORAGE_TYPE_LOCALSTORAGE)
63+
64+
if (
65+
fpidStorageType !== STORAGE_TYPE_COOKIES &&
66+
fpidStorageType !== STORAGE_TYPE_LOCALSTORAGE
67+
) {
68+
throw new Error(
69+
`fpidStorageType must be ${STORAGE_TYPE_LOCALSTORAGE} or ${STORAGE_TYPE_COOKIES}`
70+
)
71+
}
72+
73+
return { customerId, timeout, bidders, fpidStorageType };
5774
}
5875

5976
/**
@@ -81,16 +98,20 @@ export const extractConsent = ({ gdpr }) => {
8198
}
8299

83100
/**
84-
* Extracts the OPE first party id field from local storage
101+
* Extracts the OPE first party id field
102+
* @param {string} fpidStorageType indicates where fpid should be read from
85103
* @returns fpid string if found, else null
86104
*/
87-
export const extractFpid = () => {
105+
export const extractFpid = (fpidStorageType) => {
88106
try {
89-
const fpid = window.localStorage.getItem(OPE_FPID);
90-
if (fpid) {
91-
return fpid;
107+
switch (fpidStorageType) {
108+
case STORAGE_TYPE_COOKIES: return fpidStorage.getCookie(OPE_FPID)
109+
case STORAGE_TYPE_LOCALSTORAGE: return fpidStorage.getDataFromLocalStorage(OPE_FPID)
110+
default: {
111+
logError(`Got unknown fpidStorageType ${fpidStorageType}. Aborting...`)
112+
return null
113+
}
92114
}
93-
return null;
94115
} catch (error) {
95116
return null;
96117
}
@@ -231,10 +252,10 @@ const init = (config, userConsent) => {
231252
const getBidRequestData = (reqBidsConfigObj, callback, moduleConfig, userConsent) => {
232253
try {
233254
// Get the required config
234-
const { customerId, bidders } = extractConfig(moduleConfig, reqBidsConfigObj);
255+
const { customerId, bidders, fpidStorageType } = extractConfig(moduleConfig, reqBidsConfigObj);
235256
const { ortb2Fragments: { bidder: biddersOrtb2 } } = reqBidsConfigObj;
236257
// Get PAPI URL
237-
const papiUrl = getPapiUrl(customerId, extractConsent(userConsent) || {}, extractFpid())
258+
const papiUrl = getPapiUrl(customerId, extractConsent(userConsent) || {}, extractFpid(fpidStorageType))
238259
// Call PAPI
239260
getTargetingDataFromPapi(papiUrl)
240261
.then((papiResponse) => {

modules/1plusXRtdProvider.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ pbjs.setConfig({
4545

4646
### Parameters
4747

48-
| Name | Type | Description | Default |
49-
| :---------------- | :------------ | :--------------------------------------------------------------- |:----------------- |
50-
| name | String | Real time data module name | Always '1plusX' |
51-
| waitForIt | Boolean | Should be `true` if there's an `auctionDelay` defined (optional) | `false` |
52-
| params | Object | | |
53-
| params.customerId | String | Your 1plusX customer id | |
54-
| params.bidders | Array<string> | List of bidders for which you would like data to be set | |
55-
| params.timeout | Integer | timeout (ms) | 1000ms |
56-
48+
| Name | Type | Description | Default |
49+
| :------------------------ | :------------ | :--------------------------------------------------------------- |:----------------- |
50+
| name | String | Real time data module name | Always '1plusX' |
51+
| waitForIt | Boolean | Should be `true` if there's an `auctionDelay` defined (optional) | `false` |
52+
| params | Object | | |
53+
| params.customerId | String | Your 1plusX customer id | |
54+
| params.bidders | Array<string> | List of bidders for which you would like data to be set | |
55+
| params.timeout | Integer | timeout (ms) | 1000ms |
56+
| params.fpidStorageType | String | Specifies where the 1plusX fpid should be read from. Either | html5 |
57+
| | | "html5" (local storage) or "cookie" (first party cookie) | |
5758
## Testing
5859

5960
To view an example of how the 1plusX RTD module works :

0 commit comments

Comments
 (0)