Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update remote repository #36

Merged
merged 12 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions integrationExamples/gpt/51DegreesRtdProvider_example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<!DOCTYPE html>
<html lang="en">
<head>
<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">
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script async src="../../build/dev/prebid.js"></script>
<meta charset="utf-8">
<style>
body {
color: #555;
font-family: sans-serif;
}
</style>
<script>
var PREBID_TIMEOUT = 1000;
var FAILSAFE_TIMEOUT = 3000;

var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

function initAdserver() {
if (pbjs.initAdserverSet) return;

googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});

pbjs.initAdserverSet = true;
}

pbjs.que.push(function () {
var adUnits = [{
code: 'div-banner-native-1',
mediaTypes: {
banner: {
sizes: [
[300, 250]
]
},
native: {
type: 'image'
},
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13232392,
}
}]
},
{
code: 'div-banner-native-2',
mediaTypes: {
banner: {
sizes: [
[300, 250]
]
},
native: {
title: {
required: true
},
image: {
required: true
},
sponsoredBy: {
required: true
}
}
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13232392,
}
}]
}
];

pbjs.setConfig({
debug: true, // use only for testing, remove in production
realTimeData: {
auctionDelay: 1000, // should be set lower in production use
dataProviders: [
{
name: '51Degrees',
waitForIt: true,
params: {
// Get your resource key from https://configure.51degrees.com/tWrhNfY6
resourceKey: '<YOUR_RESOURCE_KEY>',
// alternatively, you can use the on-premise version of the 51Degrees service and connect to your chosen end point
// onPremiseJSUrl: 'https://localhost/51Degrees.core.js'
}
}
]
},
});

pbjs.addAdUnits(adUnits);

pbjs.onEvent('bidRequested', function (data) {
try {
fod.complete(() => {
document.getElementById('enriched-51').style.display = 'block';
document.getElementById('enriched-51-data').textContent = JSON.stringify(data.ortb2.device, null, 2);
});
} catch (e) {
console.error('Error while trying to display enriched data', e);
}
});

pbjs.requestBids({
timeout: PREBID_TIMEOUT,
bidsBackHandler: function (bidResponses) {
initAdserver();
}
});
});
setTimeout(initAdserver, FAILSAFE_TIMEOUT);
</script>

<script>
googletag.cmd.push(function () {
googletag
.defineSlot(
'/19968336/prebid_multiformat_test', [
[300, 250],
[360, 360]
],
'div-banner-native-1'
)
.addService(googletag.pubads());

googletag
.defineSlot(
'/19968336/prebid_multiformat_test', [
[300, 250],
[360, 360]
],
'div-banner-native-2'
)
.addService(googletag.pubads());

googletag.pubads().disableInitialLoad();
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<title>51Degrees RTD submodule example - Prebid.js</title>
</head>
<body>
<h2>51Degrees RTD submodule - example of usage</h2>

<h3>div-banner-native-1</h3>
<div id='div-banner-native-1'>
<p>No response</p>
<script type='text/javascript'>
googletag.cmd.push(function () {
googletag.display('div-banner-native-1');
});
</script>
</div>

<h3>div-banner-native-2</h3>
<div id='div-banner-native-2'>
<p>No response</p>
<script type='text/javascript'>
googletag.cmd.push(function () {
googletag.display('div-banner-native-2');
});
</script>
</div>

<div id="debug">
<h3>Testing/Debugging Guidance</h3>
<ol>
<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!)
<li>Make sure you have replaced <code>&lt;YOUR RESOURCE KEY&gt;</code> in this example code with the one you have obtained
from the <a href="https://configure.51degrees.com/tWrhNfY6" target="blank;">51Degrees Configurator Tool</a></li>
<li>Open DevTools Console in your browser and refresh the page</li>
<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>
</ol>

</div>
<div id="enriched-51" style="display: none">
<h3>Enriched ORTB2 device data</h3>
<pre id="enriched-51-data"></pre>
</div>
</body>
</html>
39 changes: 30 additions & 9 deletions modules/1plusXRtdProvider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { submodule } from '../src/hook.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';
import { ajax } from '../src/ajax.js';
import { getStorageManager, STORAGE_TYPE_COOKIES, STORAGE_TYPE_LOCALSTORAGE } from '../src/storageManager.js';
import {
logMessage, logError,
deepAccess, deepSetValue, mergeDeep,
Expand All @@ -13,6 +15,9 @@ const ORTB2_NAME = '1plusX.com'
const PAPI_VERSION = 'v1.0';
const LOG_PREFIX = '[1plusX RTD Module]: ';
const OPE_FPID = 'ope_fpid'

export const fpidStorage = getStorageManager({ moduleType: MODULE_TYPE_RTD, moduleName: MODULE_NAME });

export const segtaxes = {
// cf. https://github.com/InteractiveAdvertisingBureau/openrtb/pull/108
AUDIENCE: 526,
Expand Down Expand Up @@ -53,7 +58,19 @@ export const extractConfig = (moduleConfig, reqBidsConfigObj) => {
throw new Error('No bidRequestConfig bidder found in moduleConfig bidders');
}

return { customerId, timeout, bidders };
const fpidStorageType = deepAccess(moduleConfig, 'params.fpidStorageType',
STORAGE_TYPE_LOCALSTORAGE)

if (
fpidStorageType !== STORAGE_TYPE_COOKIES &&
fpidStorageType !== STORAGE_TYPE_LOCALSTORAGE
) {
throw new Error(
`fpidStorageType must be ${STORAGE_TYPE_LOCALSTORAGE} or ${STORAGE_TYPE_COOKIES}`
)
}

return { customerId, timeout, bidders, fpidStorageType };
}

/**
Expand Down Expand Up @@ -81,16 +98,20 @@ export const extractConsent = ({ gdpr }) => {
}

/**
* Extracts the OPE first party id field from local storage
* Extracts the OPE first party id field
* @param {string} fpidStorageType indicates where fpid should be read from
* @returns fpid string if found, else null
*/
export const extractFpid = () => {
export const extractFpid = (fpidStorageType) => {
try {
const fpid = window.localStorage.getItem(OPE_FPID);
if (fpid) {
return fpid;
switch (fpidStorageType) {
case STORAGE_TYPE_COOKIES: return fpidStorage.getCookie(OPE_FPID)
case STORAGE_TYPE_LOCALSTORAGE: return fpidStorage.getDataFromLocalStorage(OPE_FPID)
default: {
logError(`Got unknown fpidStorageType ${fpidStorageType}. Aborting...`)
return null
}
}
return null;
} catch (error) {
return null;
}
Expand Down Expand Up @@ -231,10 +252,10 @@ const init = (config, userConsent) => {
const getBidRequestData = (reqBidsConfigObj, callback, moduleConfig, userConsent) => {
try {
// Get the required config
const { customerId, bidders } = extractConfig(moduleConfig, reqBidsConfigObj);
const { customerId, bidders, fpidStorageType } = extractConfig(moduleConfig, reqBidsConfigObj);
const { ortb2Fragments: { bidder: biddersOrtb2 } } = reqBidsConfigObj;
// Get PAPI URL
const papiUrl = getPapiUrl(customerId, extractConsent(userConsent) || {}, extractFpid())
const papiUrl = getPapiUrl(customerId, extractConsent(userConsent) || {}, extractFpid(fpidStorageType))
// Call PAPI
getTargetingDataFromPapi(papiUrl)
.then((papiResponse) => {
Expand Down
19 changes: 10 additions & 9 deletions modules/1plusXRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ pbjs.setConfig({

### Parameters

| Name | Type | Description | Default |
| :---------------- | :------------ | :--------------------------------------------------------------- |:----------------- |
| name | String | Real time data module name | Always '1plusX' |
| waitForIt | Boolean | Should be `true` if there's an `auctionDelay` defined (optional) | `false` |
| params | Object | | |
| params.customerId | String | Your 1plusX customer id | |
| params.bidders | Array<string> | List of bidders for which you would like data to be set | |
| params.timeout | Integer | timeout (ms) | 1000ms |

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

To view an example of how the 1plusX RTD module works :
Expand Down
Loading