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

Audigent RTD configurable per-bidder segment mappings #5903

Merged
merged 26 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from 19 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<html>
<head>
<script>

(function(window, document) {
if (!window.__cmp) {
window.__cmp = (function() {
Expand Down Expand Up @@ -90,11 +91,9 @@
},
bids: [
{
bidder: 'rubicon',
bidder: 'appnexus',
params: {
accountId: '1001',
siteId: '113932',
zoneId: '535510'
placementId: 13144370
}
}
]
Expand All @@ -108,11 +107,25 @@

<script>
var googletag = googletag || {};
var testAuctionDelay = 1000;
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad();
});

var bidSegmentMappers = {
appnexus: function(bid, segments) {
if (!bid.params) {
bid.params = {}
}
if (!bid.params.user) {
bid.params.user = {}
}

bid.params.user.segments = segments;
}
}

pbjs.que.push(function() {
pbjs.setConfig({
debug: true,
Expand Down Expand Up @@ -232,17 +245,33 @@
auctionDelay: 1000
},
realTimeData: {
auctionDelay: 1000,
dataProviders: [{name: "audigent", waitForIt: true}]
auctionDelay: testAuctionDelay, // lower in real scenario to meet publisher spec
dataProviders: [
{
name: "audigent",
antlauzon marked this conversation as resolved.
Show resolved Hide resolved
waitForIt: true,
params: {
mapSegments: {
appnexus: true
},
segmentCache: false,
requestParams: {
publisherId: 0
}
}

}
]
}
});
pbjs.addAdUnits(adUnits);

pbjs.requestBids({bidsBackHandler: sendAdserverRequest});
});

function sendAdserverRequest() {
document.getElementById('tdid').innerHTML = adUnits[0].bids[0].userId['tdid'];
antlauzon marked this conversation as resolved.
Show resolved Hide resolved
document.getElementById('audigent_segments').innerHTML = JSON.stringify(adUnits[0].bids[0].audigent_segments);
document.getElementById('audigent_segments').innerHTML = JSON.stringify(adUnits[0].bids[0].params.user.segments);

if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
Expand Down Expand Up @@ -294,7 +323,7 @@ <h2>Audigent Segments Prebid</h2>
<div id='tdid'>
</div>

Audigent Segments:
Audigent Segments (Appnexus):
<div id='audigent_segments'>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"rtdModule": [
"browsiRtdProvider",
"audigentRtdProvider",
"haloRtdProvider",
"jwplayerRtdProvider",
"reconciliationRtdProvider"
]
Expand Down
76 changes: 0 additions & 76 deletions modules/audigentRtdProvider.md

This file was deleted.

105 changes: 80 additions & 25 deletions modules/audigentRtdProvider.js → modules/haloRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,77 @@ import {submodule} from '../src/hook.js';
import {ajax} from '../src/ajax.js';
import { getStorageManager } from '../src/storageManager.js';

const storage = getStorageManager();
export const storage = getStorageManager();

/** @type {string} */
const MODULE_NAME = 'realTimeData';
const SUBMODULE_NAME = 'audigent';
const HALOID_LOCAL_NAME = 'auHaloId';
const SEG_LOCAL_NAME = '__adgntseg';
const SUBMODULE_NAME = 'halo';
const ERR_MSG = 'AUDIGENT_ERR';

export const HALOID_LOCAL_NAME = 'auHaloId';
export const SEG_LOCAL_NAME = '__adgntseg';

const set = (obj, path, val) => {
const keys = path.split('.');
const lastKey = keys.pop();
const lastObj = keys.reduce((obj, key) => obj[key] = obj[key] || {}, obj);
lastObj[lastKey] = lastObj[lastKey] || val;
};

/** bid adapter format segment augmentation functions */
const segmentMappers = {
appnexus: function(bid, segments) {
set(bid, 'params.user.segments', []);
let appnexusSegments = [];
segments.forEach(segment => {
if (typeof segment.value != 'undefined' && segment.value != null) {
let appnexusSegment = {'id': segment.id, 'value': segment.value};
appnexusSegments.push(appnexusSegment);
}
})
bid.params.user.segments = bid.params.user.segments.concat(appnexusSegments);
},
generic: function(bid, segments) {
bid.segments = segments;
antlauzon marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* decorate adUnits with segment data
* @param {adUnit[]} adUnits
* @param {Object} data
*/
function addSegmentData(adUnits, data) {
export function addSegmentData(adUnits, segmentData, config) {
adUnits.forEach(adUnit => {
if (adUnit.hasOwnProperty('bids')) {
adUnit.bids.forEach(bid => {
bid.audigent_segments = data;
})
try {
set(bid, 'fpd.user.data', []);
if (Array.isArray(bid.fpd.user.data)) {
bid.fpd.user.data.forEach(fpdData => {
if (fpdData.name) { config.params.mapSegments[fpdData.name] = true; }
let segments = segmentData[fpdData.id] || segmentData[fpdData.name] || [];
fpdData.segment = (fpdData.segment || []).concat(segments);
});
}
} catch (err) {
utils.logError(ERR_MSG);
antlauzon marked this conversation as resolved.
Show resolved Hide resolved
}

try {
if (config.params.mapSegments && config.params.mapSegments[bid.bidder] && segmentData[bid.bidder]) {
if (typeof config.params.mapSegments[bid.bidder] == 'function') {
config.params.mapSegments[bid.bidder](bid, segmentData[bid.bidder]);
} else if (segmentMappers[bid.bidder]) {
segmentMappers[bid.bidder](bid, segmentData[bid.bidder]);
}
}
} catch (err) {
utils.logError(ERR_MSG);
}
});
}
})
});

return adUnits;
}
Expand All @@ -43,16 +93,20 @@ function addSegmentData(adUnits, data) {
* @param {Object} config
* @param {Object} userConsent
*/
function getSegments(reqBidsConfigObj, onDone, config, userConsent) {
export function getSegments(reqBidsConfigObj, onDone, config, userConsent) {
const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits;

let jsonData = storage.getDataFromLocalStorage(SEG_LOCAL_NAME);
if (jsonData) {
let data = JSON.parse(jsonData);
if (data.audigent_segments) {
addSegmentData(adUnits, data.audigent_segments);
onDone();
return;
if (config.params.segmentCache) {
let jsonData = storage.getDataFromLocalStorage(SEG_LOCAL_NAME);

if (jsonData) {
let data = JSON.parse(jsonData);

if (data.audigent_segments) {
addSegmentData(adUnits, data.audigent_segments, config);
onDone();
return;
}
}
}

Expand Down Expand Up @@ -88,20 +142,20 @@ function getSegments(reqBidsConfigObj, onDone, config, userConsent) {
* @param {Object} userConsent
* @param {Object} userIds
*/
function getSegmentsAsync(adUnits, onDone, config, userConsent, userIds) {
let reqParams = {}
export function getSegmentsAsync(adUnits, onDone, config, userConsent, userIds) {
let reqParams = {};
if (typeof config == 'object' && config != null && Object.keys(config).length > 0) {
reqParams = config.params
reqParams = config.params.requestParams;
antlauzon marked this conversation as resolved.
Show resolved Hide resolved
}

const url = `https://seg.halo.ad.gt/api/v1/rtb_segments`;
const url = `http://127.0.0.1:5000/api/v1/rtb_segments`;
antlauzon marked this conversation as resolved.
Show resolved Hide resolved
ajax(url, {
success: function (response, req) {
if (req.status === 200) {
try {
const data = JSON.parse(response);
if (data && data.audigent_segments) {
addSegmentData(adUnits, data.audigent_segments);
addSegmentData(adUnits, data.audigent_segments, config);
onDone();
storage.setDataInLocalStorage(SEG_LOCAL_NAME, JSON.stringify(data));
} else {
Expand All @@ -128,18 +182,19 @@ function getSegmentsAsync(adUnits, onDone, config, userConsent, userIds) {

/**
* module init
* @param {Object} config
* @param {Object} provider
* @param {Objkect} userConsent
* @return {boolean}
*/
export function init(config) {
function init(provider, userConsent) {
return true;
}

/** @type {RtdSubmodule} */
export const audigentSubmodule = {
export const haloSubmodule = {
name: SUBMODULE_NAME,
getBidRequestData: getSegments,
init: init
};

submodule(MODULE_NAME, audigentSubmodule);
submodule(MODULE_NAME, haloSubmodule);
Loading