From c4eb7428eec2ea10d12d1b3b8e637bdf9a313bfe Mon Sep 17 00:00:00 2001 From: Anthony Lauzon Date: Tue, 20 Oct 2020 10:25:46 -0500 Subject: [PATCH] Audigent RTD Provider HaloId Support & RTD Phase 3 Compliance (#5777) * real time data module, browsi sub module for real time data, new hook bidsBackCallback, fix for config unsubscribe * change timeout&primary ad server only to auctionDelay update docs * support multiple providers * change promise to callbacks configure submodule on submodules.json * bug fixes * use Prebid ajax * tests fix * browsi real time data provider improvements * real time data module, browsi sub module for real time data, new hook bidsBackCallback, fix for config unsubscribe * change timeout&primary ad server only to auctionDelay update docs * support multiple providers * change promise to callbacks configure submodule on submodules.json * bug fixes * use Prebid ajax * tests fix * browsi real time data provider improvements * RTD module extend #4610 * add hook for submodule init variables naming * RTD bug fix * remove auction delay and related hooks * update audigent rtd provider * style update * change onDone() logic * RTD phase 3 * return on data unavailable * api endpoint update * update audigent RTD provider for new spec * design changes * fix loop continuation * proper fix this time * linter * update rtd parameters, onDone semantics * reduce loops * documentation update * working update to rtd3 spec, update segment example, documentation * remove unused vars, reference module name * resolve haloid for segments * update documentation to markdown * update description in documentation * minify optimizations Co-authored-by: omerdotan Co-authored-by: bretg --- .../gpt/audigentSegments_example.html | 86 ++++++--- modules/audigentRtdProvider.js | 174 +++++++++--------- modules/audigentRtdProvider.md | 34 +++- package-lock.json | 47 ++--- 4 files changed, 202 insertions(+), 139 deletions(-) diff --git a/integrationExamples/gpt/audigentSegments_example.html b/integrationExamples/gpt/audigentSegments_example.html index 7739b558327..1536ece9ab7 100644 --- a/integrationExamples/gpt/audigentSegments_example.html +++ b/integrationExamples/gpt/audigentSegments_example.html @@ -84,11 +84,10 @@ { code: 'test-div', mediaTypes: { - banner: { - sizes: [[300,250],[300,600],[728,90]] - } + banner: { + sizes: [[300,250],[300,600],[728,90]] + } }, - bids: [ { bidder: 'rubicon', @@ -120,20 +119,9 @@ consentManagement: { cmpApi: 'iab', timeout: 1000, - allowAuctionWithoutConsent: true + defaultGdprScope: true }, - // consentManagement: { - // cmpApi: 'static', - // consentData: { - // consentString: 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA' - // vendorData: { - // purposeConsents: { - // '1': true - // } - // } - // } - // }, - usersync: { + userSync: { userIds: [{ name: "unifiedId", params: { @@ -145,6 +133,16 @@ name: "unifiedid", expires: 30 }, + }, { + name: "intentIqId", + params: { + partner: 0, //Set your real IntentIQ partner ID here for production. + }, + storage: { + type: "cookie", + name: "intentIqId", + expires: 30 + }, }, { name: "id5Id", params: { @@ -157,6 +155,18 @@ refreshInSeconds: 8*3600 // Refresh frequency of cookies, defaulting to 'expires' }, + }, { + name: "merkleId", + params: { + ptk: '12345678-aaaa-bbbb-cccc-123456789abc', //Set your real merkle partner key here + pubid: 'EXAMPLE' //Set your real merkle publisher id here + }, + storage: { + type: "html5", + name: "merkleId", + expires: 30 + }, + }, { name: "parrableId", params: { @@ -174,7 +184,7 @@ // foo: '9879878907987', // bar:'93939' // } - }, { + }, { name: 'identityLink', params: { pid: '14' // Set your real identityLink placement ID here @@ -184,13 +194,46 @@ name: 'idl_env', expires: 30 } + }, { + name: "sharedId", + params: { + syncTime: 60 // in seconds, default is 24 hours + }, + storage: { + type: "cookie", + name: "sharedid", + expires: 28 + } + }, { + name: 'lotamePanoramaId' + }, { + name: "liveIntentId", + params: { + publisherId: "9896876" + }, + storage: { + type: "cookie", + name: "_li_pbid", + expires: 28 + } + }, { + name: "zeotapIdPlus" + }, { + name: 'haloId', + storage: { + type: "cookie", + name: "haloId", + expires: 28 + } + }, { + name: "quantcastId" }], syncDelay: 5000, - auctionDelay: 1000 + auctionDelay: 1000 }, realTimeData: { auctionDelay: 1000, - dataProviders: [{name: "audigent"}] + dataProviders: [{name: "audigent", waitForIt: true}] } }); pbjs.addAdUnits(adUnits); @@ -199,7 +242,7 @@ function sendAdserverRequest() { document.getElementById('tdid').innerHTML = adUnits[0].bids[0].userId['tdid']; - document.getElementById('audigent_segments').innerHTML = JSON.stringify(adUnits[0].bids[0].realTimeData.audigent_segments); + document.getElementById('audigent_segments').innerHTML = JSON.stringify(adUnits[0].bids[0].audigent_segments); if (pbjs.adserverRequestSent) return; pbjs.adserverRequestSent = true; @@ -246,6 +289,7 @@

Audigent Segments Prebid

googletag.cmd.push(function() { googletag.display('test-div'); }); + TDID:
diff --git a/modules/audigentRtdProvider.js b/modules/audigentRtdProvider.js index 0f32c84962f..09b76cac0df 100644 --- a/modules/audigentRtdProvider.js +++ b/modules/audigentRtdProvider.js @@ -5,17 +5,6 @@ * @module modules/audigentRtdProvider * @requires module:modules/realTimeData */ - -/** - * @typedef {Object} ModuleParams - * @property {string} siteKey - * @property {string} pubKey - * @property {string} url - * @property {?string} keyName - * @property {number} auctionDelay - */ - -import {config} from '../src/config.js'; import {getGlobal} from '../src/prebidGlobal.js'; import * as utils from '../src/utils.js'; import {submodule} from '../src/hook.js'; @@ -26,116 +15,131 @@ const storage = getStorageManager(); /** @type {string} */ const MODULE_NAME = 'realTimeData'; - -/** @type {ModuleParams} */ -let _moduleParams = {}; +const SUBMODULE_NAME = 'audigent'; +const HALOID_LOCAL_NAME = 'auHaloId'; +const SEG_LOCAL_NAME = '__adgntseg'; /** - * XMLHttpRequest to get data form audigent server - * @param {string} url server url with query params + * decorate adUnits with segment data + * @param {adUnit[]} adUnits + * @param {Object} data */ +function addSegmentData(adUnits, data) { + adUnits.forEach(adUnit => { + if (adUnit.hasOwnProperty('bids')) { + adUnit.bids.forEach(bid => { + bid.audigent_segments = data; + }) + } + }) -export function setData(data) { - storage.setDataInLocalStorage('__adgntseg', JSON.stringify(data)); + return adUnits; } -function getSegments(adUnits, onDone) { - try { - let jsonData = storage.getDataFromLocalStorage('__adgntseg'); - if (jsonData) { - let data = JSON.parse(jsonData); - if (data.audigent_segments) { - let dataToReturn = adUnits.reduce((rp, cau) => { - const adUnitCode = cau && cau.code; - if (!adUnitCode) { return rp } - rp[adUnitCode] = data; - return rp; - }, {}); - - onDone(dataToReturn); - return; - } +/** + * segment retrieval from audigent's backends + * @param {Object} reqBidsConfigObj + * @param {function} onDone + * @param {Object} config + * @param {Object} userConsent + */ +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; } - getSegmentsAsync(adUnits, onDone); - } catch (e) { - getSegmentsAsync(adUnits, onDone); } -} -function getSegmentsAsync(adUnits, onDone) { const userIds = (getGlobal()).getUserIds(); - let tdid = null; + if (typeof userIds == 'undefined' || userIds == null) { + onDone(); + return; + } - if (userIds && userIds['tdid']) { - tdid = userIds['tdid']; + let haloId = storage.getDataFromLocalStorage(HALOID_LOCAL_NAME); + if (haloId) { + userIds.haloId = haloId; + getSegmentsAsync(adUnits, onDone, config, userConsent, userIds); } else { - onDone({}); + var script = document.createElement('script') + script.type = 'text/javascript'; + + script.onload = function() { + userIds.haloId = storage.getDataFromLocalStorage(HALOID_LOCAL_NAME); + getSegmentsAsync(adUnits, onDone, config, userConsent, userIds); + } + + script.src = 'https://id.halo.ad.gt/api/v1/haloid'; + document.getElementsByTagName('head')[0].appendChild(script); } +} - const url = `https://seg.ad.gt/api/v1/rtb_segments?tdid=${tdid}`; +/** + * async segment retrieval from audigent's backends + * @param {adUnit[]} adUnits + * @param {function} onDone + * @param {Object} config + * @param {Object} userConsent + * @param {Object} userIds + */ +function getSegmentsAsync(adUnits, onDone, config, userConsent, userIds) { + let reqParams = {} + if (typeof config == 'object' && config != null && Object.keys(config).length > 0) { + reqParams = config.params + } + const url = `https://seg.halo.ad.gt/api/v1/rtb_segments`; ajax(url, { success: function (response, req) { if (req.status === 200) { try { const data = JSON.parse(response); if (data && data.audigent_segments) { - setData(data); - let dataToReturn = adUnits.reduce((rp, cau) => { - const adUnitCode = cau && cau.code; - if (!adUnitCode) { return rp } - rp[adUnitCode] = data; - return rp; - }, {}); - - onDone(dataToReturn); + addSegmentData(adUnits, data.audigent_segments); + onDone(); + storage.setDataInLocalStorage(SEG_LOCAL_NAME, JSON.stringify(data)); } else { - onDone({}); + onDone(); } } catch (err) { utils.logError('unable to parse audigent segment data'); - onDone({}) + onDone(); } } else if (req.status === 204) { - // unrecognized site key - onDone({}); + // unrecognized partner config + onDone(); } }, error: function () { - onDone({}); + onDone(); utils.logError('unable to get audigent segment data'); } - } + }, + JSON.stringify({'userIds': userIds, 'config': reqParams}), + {contentType: 'application/json'} ); } +/** + * module init + * @param {Object} config + * @return {boolean} + */ +export function init(config) { + return true; +} + /** @type {RtdSubmodule} */ export const audigentSubmodule = { - /** - * used to link submodule with realTimeData - * @type {string} - */ - name: 'audigent', - /** - * get data and send back to realTimeData module - * @function - * @param {adUnit[]} adUnits - * @param {function} onDone - */ - getData: getSegments + name: SUBMODULE_NAME, + getBidRequestData: getSegments, + init: init }; -export function init(config) { - const confListener = config.getConfig(MODULE_NAME, ({realTimeData}) => { - try { - _moduleParams = realTimeData.dataProviders && realTimeData.dataProviders.filter(pr => pr.name && pr.name.toLowerCase() === 'audigent')[0].params; - _moduleParams.auctionDelay = realTimeData.auctionDelay; - } catch (e) { - _moduleParams = {}; - } - confListener(); - }); -} - -submodule('realTimeData', audigentSubmodule); -init(config); +submodule(MODULE_NAME, audigentSubmodule); diff --git a/modules/audigentRtdProvider.md b/modules/audigentRtdProvider.md index 47bcbbbf951..03e647f651d 100644 --- a/modules/audigentRtdProvider.md +++ b/modules/audigentRtdProvider.md @@ -1,18 +1,40 @@ +## Audigent Real-time Data Submodule + Audigent is a next-generation data management platform and a first-of-a-kind "data agency" containing some of the most exclusive content-consuming audiences across desktop, mobile and social platforms. -This real-time data module provides first-party Audigent segments that can be +This real-time data module provides quality user segmentation that can be attached to bid request objects destined for different SSPs in order to optimize targeting. Audigent maintains a large database of first-party Tradedesk Unified -ID to third party segment mappings that can now be queried at bid-time. +ID, Audigent Halo ID and other id provider mappings to various third-party +segment types that are utilizable across different SSPs. With this module, +these segments can be retrieved and supplied to the SSP in real-time during +the bid request cycle. -Usage: +### Usage Compile the audigent RTD module into your Prebid build: `gulp build --modules=userId,unifiedIdSystem,rtdModule,audigentRtdProvider,rubiconBidAdapter` +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` @@ -35,13 +57,15 @@ 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].realTimeData.audigent_segments['rubicon']; + adUnit.bids[j].userId.lipb.segments = adUnit.bids[j].audigent_segments['rubicon']; } } } ``` -To view an example of the segments returned by Audigent's backends: +### Testing + +To view an example of available segments returned by Audigent's backends: `gulp serve --modules=userId,unifiedIdSystem,rtdModule,audigentRtdProvider,rubiconBidAdapter` diff --git a/package-lock.json b/package-lock.json index 1784b885be9..81ff16fdc5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "4.8.0-pre", + "version": "4.11.0-pre", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -7796,13 +7796,22 @@ "function-bind": "^1.1.1", "has": "^1.0.3", "has-symbols": "^1.0.1", - "is-callable": "^1.2.0", - "is-regex": "^1.1.0", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", "object-inspect": "^1.7.0", "object-keys": "^1.1.1", - "object.assign": "^4.1.0", - "string.prototype.trimend": "^1.0.1", - "string.prototype.trimstart": "^1.0.1" + "object.assign": "^4.1.0" + }, + "dependencies": { + "is-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + } } }, "es-array-method-boxes-properly": { @@ -7838,6 +7847,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "dev": true, "requires": { "is-callable": "^1.1.4", "is-date-object": "^1.0.1", @@ -12076,7 +12086,7 @@ "integrity": "sha512-vlKW17SNq44owv5AQR3Cq0bQPEb8+kF3UKZ2fiZNOWtztYE5i0CzCZxFDwO58qAOWtxdBRVO/V5Qin1wjCqFYQ==", "dev": true, "requires": { - "has-symbols": "^1.0.1" + "has": "^1.0.3" } }, "is-relative": { @@ -17484,7 +17494,8 @@ "object-inspect": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz", - "integrity": "sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA==" + "integrity": "sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA==", + "dev": true }, "object-is": { "version": "1.1.2", @@ -20696,26 +20707,6 @@ "es-abstract": "^1.17.0-next.1" } }, - "string.prototype.trimend": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz", - "integrity": "sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==", - "dev": true, - "requires": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5" - } - }, - "string.prototype.trimstart": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz", - "integrity": "sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==", - "dev": true, - "requires": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5" - } - }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",