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

SAS-15284 Adding Azerion's RTD module #1

Merged
merged 2 commits into from
Feb 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
91 changes: 91 additions & 0 deletions integrationExamples/gpt/azerionRtdProvider_example.html
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>
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"airgridRtdProvider",
"akamaiDapRtdProvider",
"arcspanRtdProvider",
"azerionRtdProvider",
"blueconicRtdProvider",
"brandmetricsRtdProvider",
"browsiRtdProvider",
Expand Down
129 changes: 129 additions & 0 deletions modules/azerionRtdProvider.js
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);
94 changes: 94 additions & 0 deletions modules/azerionRtdProvider.md
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]).
1 change: 1 addition & 0 deletions src/adloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const _approvedLoadExternalJSList = [
'hadron',
'medianet',
'improvedigital',
'azerion',
'aaxBlockmeter',
'confiant',
'arcspan',
Expand Down
Loading