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 2 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
33 changes: 27 additions & 6 deletions integrationExamples/gpt/audigentSegments_example.html
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,11 +245,19 @@
auctionDelay: 1000
},
realTimeData: {
auctionDelay: 1000,
dataProviders: [{name: "audigent", waitForIt: true}]
auctionDelay: testAuctionDelay, // lower in real scenario to meet publisher spec
dataProviders: [
{
name: "audigent",
waitForIt: true,
segmentMap: bidSegmentMappers,
segmentCache: false
}
]
}
});
pbjs.addAdUnits(adUnits);

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

Expand Down
28 changes: 19 additions & 9 deletions modules/audigentRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const SUBMODULE_NAME = 'audigent';
const HALOID_LOCAL_NAME = 'auHaloId';
const SEG_LOCAL_NAME = '__adgntseg';

let segmentMap = {};

/**
* decorate adUnits with segment data
* @param {adUnit[]} adUnits
Expand All @@ -29,6 +31,9 @@ function addSegmentData(adUnits, data) {
if (adUnit.hasOwnProperty('bids')) {
adUnit.bids.forEach(bid => {
bid.audigent_segments = data;
if (segmentMap[bid.bidder] && data[bid.bidder]) {
segmentMap[bid.bidder](bid, data[bid.bidder]);
antlauzon marked this conversation as resolved.
Show resolved Hide resolved
}
})
}
})
Expand All @@ -46,13 +51,15 @@ function addSegmentData(adUnits, data) {
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.segmentCache) {
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;
}
}
}

Expand Down Expand Up @@ -89,9 +96,9 @@ function getSegments(reqBidsConfigObj, onDone, config, userConsent) {
* @param {Object} userIds
*/
function getSegmentsAsync(adUnits, onDone, config, userConsent, userIds) {
let reqParams = {}
let reqParams = {};
if (typeof config == 'object' && config != null && Object.keys(config).length > 0) {
reqParams = config.params
reqParams = config.params;
}

const url = `https://seg.halo.ad.gt/api/v1/rtb_segments`;
Expand Down Expand Up @@ -132,6 +139,9 @@ function getSegmentsAsync(adUnits, onDone, config, userConsent, userIds) {
* @return {boolean}
*/
export function init(config) {
if (config.segmentMap) {
segmentMap = config.segmentMap;
}
return true;
}

Expand Down
68 changes: 33 additions & 35 deletions modules/audigentRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,56 @@ the bid request cycle.

Compile the audigent RTD module into your Prebid build:

`gulp build --modules=userId,unifiedIdSystem,rtdModule,audigentRtdProvider,rubiconBidAdapter`
`gulp build --modules=userId,unifiedIdSystem,rtdModule,audigentRtdProvider,appnexusBidAdapter`

Configure Prebid to add the Audigent RTD Segment Handler:
```
pbjs.setConfig(
...
realTimeData: {
auctionDelay: 1000,
dataProviders: [
{
name: "audigent",
waitForIt: true
}
]
}
...
}
```

Audigent segments will then be attached to each bid request objects in
`bid.realTimeData.audigent_segments`

The format of the segments is a per-SSP mapping:
The format of returned segments is a segment type mapping.

```
{
'appnexus': ['anseg1', 'anseg2'],
'google': ['gseg1', 'gseg2']
'appnexus': ['anseg1', 'anseg2'],
'pubmatic': ['pseg1', 'pseg2'],
'spotx': ['sseg1', 'sseg2']
}
```

If a given SSP's API backend supports segment fields, they can then be
attached prior to the bid request being sent:
Define a function that will map segment types to a specific bidder's request
format by name. Supply this function to the Audigent data provider as
segmentMapper. In this example, we add segments to an appnexus bid request
in the format accepted by their adapter.

```
pbjs.requestBids({bidsBackHandler: addAudigentSegments});

function addAudigentSegments() {
for (i = 0; i < adUnits.length; i++) {
let adUnit = adUnits[i];
for (j = 0; j < adUnit.bids.length; j++) {
adUnit.bids[j].userId.lipb.segments = adUnit.bids[j].audigent_segments['rubicon'];
}
}
var bidSegmentMappers = {
appnexus: function(bid, segments) {
if (bid.params.user.segments) {
existing_segments = bid.params.user.segments;
}
bid.params.user.segments = existing_segments.concat(segments);
}
}

pbjs.setConfig(
...
realTimeData: {
auctionDelay: auctionDelay,
dataProviders: [
{
name: "audigent",
waitForIt: true,
segmentMap: bidSegmentMappers,
segmentCache: false
}
]
}
...
}
```

### Testing

To view an example of available segments returned by Audigent's backends:

`gulp serve --modules=userId,unifiedIdSystem,rtdModule,audigentRtdProvider,rubiconBidAdapter`
`gulp serve --modules=userId,unifiedIdSystem,rtdModule,audigentRtdProvider,appnexusBidAdapter`

and then point your browser at:

Expand Down