forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAS-15284 Adding Azerion's RTD module (#1)
* SAS-15284 Adding Azerion's RTD module - Added README.md, unit test for the module and the example of how to integrate it with google publisher tag. - Added the module name to the adloader allowlist and submodules. * SAS-15284 Fixing naming.
- Loading branch information
Showing
6 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<html> | ||
<head> | ||
<meta name="keywords" content="football basketball rugby tenis" /> | ||
<script async src="../../build/dev/prebid.js" async></script> | ||
<script | ||
async | ||
src="https://www.googletagservices.com/tag/js/gpt.js" | ||
></script> | ||
|
||
<script> | ||
const FAILSAFE_TIMEOUT = 1000; | ||
const PREBID_TIMEOUT = 1000; | ||
const TEST_DIV = "test-div"; | ||
const TEST_SIZES = [[300, 250]]; | ||
const TEST_OUTPUT = "azerion-segments"; | ||
const STORAGE_KEY = "ht-pa-v1-a"; | ||
</script> | ||
|
||
<script> | ||
var googletag = googletag || {}; | ||
googletag.cmd = googletag.cmd || []; | ||
googletag.cmd.push(function () { | ||
googletag | ||
.defineSlot("/19968336/header-bid-tag-0", TEST_SIZES, TEST_DIV) | ||
.addService(googletag.pubads()); | ||
googletag.pubads().disableInitialLoad(); | ||
googletag.pubads().enableSingleRequest(); | ||
googletag.enableServices(); | ||
}); | ||
</script> | ||
|
||
<script> | ||
var pbjs = pbjs || {}; | ||
pbjs.que = pbjs.que || []; | ||
pbjs.que.push(function () { | ||
pbjs.setConfig({ | ||
debug: true, | ||
realTimeData: { | ||
dataProviders: [ | ||
{ | ||
name: "azerion", | ||
waitForIt: true, | ||
params: { bidders: ["appnexus"] }, | ||
}, | ||
], | ||
}, | ||
}); | ||
pbjs.setBidderConfig({ bidders: ["appnexus"], config: {} }); | ||
pbjs.addAdUnits([ | ||
{ | ||
code: TEST_DIV, | ||
mediaTypes: { banner: { sizes: TEST_SIZES } }, | ||
bids: [{ bidder: "appnexus", params: { placementId: 13144370 } }], | ||
}, | ||
]); | ||
pbjs.requestBids({ | ||
bidsBackHandler: sendAdserverRequest, | ||
timeout: PREBID_TIMEOUT, | ||
}); | ||
}); | ||
|
||
function sendAdserverRequest() { | ||
const output = document.getElementById(TEST_OUTPUT); | ||
output.innerHTML = window.localStorage.getItem(STORAGE_KEY); | ||
|
||
if (pbjs.adserverRequestSent) return; | ||
pbjs.adserverRequestSent = true; | ||
googletag.cmd.push(function () { | ||
pbjs.que.push(function () { | ||
pbjs.setTargetingForGPTAsync(); | ||
googletag.pubads().refresh(); | ||
}); | ||
}); | ||
} | ||
setTimeout(sendAdserverRequest, FAILSAFE_TIMEOUT); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h2>Azerion RTD</h2> | ||
|
||
<div id="test-div"> | ||
<script> | ||
googletag.cmd.push(() => googletag.display(TEST_DIV)); | ||
</script> | ||
</div> | ||
|
||
Segments: | ||
<div id="azerion-segments"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* This module adds the Azerion provider to the real time data module of prebid. | ||
* | ||
* The {@link module:modules/realTimeData} module is required | ||
* @module modules/azerionRtdProvider | ||
* @requires module:modules/realTimeData | ||
*/ | ||
import { submodule } from '../src/hook.js'; | ||
import { mergeDeep } from '../src/utils.js'; | ||
import { getStorageManager } from '../src/storageManager.js'; | ||
import { loadExternalScript } from '../src/adloader.js'; | ||
import { MODULE_TYPE_RTD } from '../src/activities/modules.js'; | ||
|
||
/** | ||
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule | ||
*/ | ||
|
||
const REAL_TIME_MODULE = 'realTimeData'; | ||
const SUBREAL_TIME_MODULE = 'azerion'; | ||
export const STORAGE_KEY = 'ht-pa-v1-a'; | ||
|
||
export const storage = getStorageManager({ | ||
moduleType: MODULE_TYPE_RTD, moduleName: SUBREAL_TIME_MODULE | ||
}); | ||
|
||
/** | ||
* Get script url to load | ||
* | ||
* @param {Object} config | ||
* | ||
* @return {String} | ||
*/ | ||
function getScriptURL(config) { | ||
const VERSION = 'v1'; | ||
const key = config.params?.key; | ||
const publisherPath = key ? `${key}/` : ''; | ||
return `https://pa.hyth.io/js/${VERSION}/${publisherPath}htpa.min.js`; | ||
} | ||
|
||
/** | ||
* Attach script tag to DOM | ||
* | ||
* @param {Object} config | ||
* | ||
* @return {void} | ||
*/ | ||
export function attachScript(config) { | ||
const script = getScriptURL(config); | ||
loadExternalScript(script, SUBREAL_TIME_MODULE, () => { | ||
if (typeof window.azerionPublisherAudiences === 'function') { | ||
window.azerionPublisherAudiences(config.params?.process || {}); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Fetch audiences info from localStorage. | ||
* | ||
* @return {Array} Audience ids. | ||
*/ | ||
export function getAudiences() { | ||
try { | ||
const data = storage.getDataFromLocalStorage(STORAGE_KEY); | ||
return JSON.parse(data).map(({id}) => id); | ||
} catch (_) { | ||
return []; | ||
} | ||
} | ||
|
||
/** | ||
* Pass audience data to configured bidders, using ORTB2 | ||
* | ||
* @param {Object} reqBidsConfigObj | ||
* @param {Object} config | ||
* @param {Array} audiences | ||
* | ||
* @return {void} | ||
*/ | ||
export function setAudiencesToBidders(reqBidsConfigObj, config, audiences) { | ||
const defaultBidders = ['improvedigital']; | ||
const bidders = config.params?.bidders || defaultBidders; | ||
bidders.forEach((bidderCode) => mergeDeep(reqBidsConfigObj.ortb2Fragments.bidder, {[bidderCode]: { | ||
user: { | ||
data: [ | ||
{ name: 'azerion', ext: { segtax: 4 }, segment: audiences.map(id => ({id})) } | ||
] | ||
} | ||
}})); | ||
} | ||
|
||
/** | ||
* Module initialisation. | ||
* | ||
* @param {Object} config | ||
* @param {Object} userConsent | ||
* | ||
* @return {boolean} | ||
*/ | ||
function init(config, userConsent) { | ||
attachScript(config); | ||
return true; | ||
} | ||
|
||
/** | ||
* Real-time user audiences retrieval | ||
* | ||
* @param {Object} reqBidsConfigObj | ||
* @param {function} callback | ||
* @param {Object} config | ||
* @param {Object} userConsent | ||
* | ||
* @return {void} | ||
*/ | ||
export function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { | ||
const audiences = getAudiences(); | ||
if (audiences.length > 0) { | ||
setAudiencesToBidders(reqBidsConfigObj, config, audiences); | ||
} | ||
callback(); | ||
} | ||
|
||
/** @type {RtdSubmodule} */ | ||
export const azerionSubmodule = { | ||
name: SUBREAL_TIME_MODULE, | ||
init: init, | ||
getBidRequestData: getBidRequestData, | ||
}; | ||
|
||
submodule(REAL_TIME_MODULE, azerionSubmodule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
layout: page_v2 | ||
title: azerion RTD Provider | ||
display_name: Azerion RTD Provider | ||
description: Real Time audience generator. | ||
page_type: module | ||
module_type: rtd | ||
module_code: azerionRtdProvider | ||
enable_download: true | ||
vendor_specific: true | ||
sidebarType: 1 | ||
--- | ||
|
||
# Azerion RTD Provider | ||
|
||
Azerion RTD is designed to help publishers find its users interests | ||
while providing these interests to buyers in the bid request. All this without | ||
exposing data to thir-party services. | ||
|
||
{:.no_toc} | ||
|
||
- TOC | ||
{:toc} | ||
|
||
## Integration | ||
|
||
Compile the Azerion RTD module (`azerionRtdProvider`) into your Prebid build, | ||
along with the parent RTD Module (`rtdModule`): | ||
|
||
```bash | ||
gulp build --modules=rtdModule,azerionRtdProvider,appnexusBidAdapter,improvedigitalBidAdapter | ||
``` | ||
|
||
Set configuration via `pbjs.setConfig`. | ||
|
||
```js | ||
pbjs.setConfig( | ||
... | ||
realTimeData: { | ||
auctionDelay: 1000, | ||
dataProviders: [ | ||
{ | ||
name: 'azerion', | ||
waitForIt: true, | ||
params: { | ||
publisherId: 'publisherId', | ||
bidders: ['appnexus', 'improvedigital'], | ||
process: {} | ||
} | ||
} | ||
] | ||
} | ||
... | ||
} | ||
``` | ||
### Parameter Description | ||
{: .table .table-bordered .table-striped } | ||
| Name | Type | Description | Notes | | ||
| :--- | :------- | :------------------ | :--------------- | | ||
| name | `String` | RTD sub module name | Always "azerion" | | ||
| waitForIt | `Boolean` | Required to ensure that the auction is delayed for the module to respond. | Optional. Defaults to false but recommended to true. | | ||
| params.key | `String` | Publisher partner specific key | Optional | | ||
| params.bidders | `Array` | Bidders with which to share segment information | Optional. Defaults to "improvedigital". | | ||
| params.process | `Object` | Configuration for the publisher audiences script. | Optional. Defaults to `{}`. | | ||
### Configuration `process` Description | ||
{: .table .table-bordered .table-striped } | ||
| Name | Type | Description | Notes | | ||
| :------------- | :-------- | :----------------------------------------------- | :-------------------------- | | ||
| process.optout | `Boolean` | Disables the process of audiences for the users. | Optional. Defaults to false | | ||
## Testing | ||
To view an example: | ||
```bash | ||
gulp serve-fast --modules=rtdModule,azerionRtdProvider,appnexusBidAdapter,improvedigitalBidAdapter | ||
``` | ||
Access [http://localhost:9999/integrationExamples/gpt/azerionRtdProvider_example.html](http://localhost:9999/integrationExamples/gpt/azerionRtdProvider_example.html) | ||
in your browser. | ||
Run the unit tests: | ||
```bash | ||
npm test -- --file "test/spec/modules/azerionRtdProvider_spec.js" | ||
``` | ||
## Support | ||
If you require further assistance please contact [[email protected]](mailto:[email protected]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.