-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Dgkeyword Rtd Provider: add new real-time data submodule #6410
Merged
osazos
merged 9 commits into
prebid:master
from
mediaconsortium-develop:feature/dgkeywordRtdProvider
May 26, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8f9b509
add dgkeywordRtdProvider
mediaconsortium-develop f28639a
change access url
mediaconsortium-develop ea77a52
we change not to access real url.
mediaconsortium-develop 45dbfa6
update test code.
mediaconsortium-develop ba54e75
update test code
mediaconsortium-develop d28a15a
Merge remote-tracking branch 'origin' into feature/dgkeywordRtdProvider
mediaconsortium-develop cdb6802
set keywords using setBidderConfig in ortb2.
mediaconsortium-develop 166c666
change test code for circle CI
mediaconsortium-develop 9369ed2
Merge branch 'master' into feature/dgkeywordRtdProvider
patmmccann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,132 @@ | ||
/** | ||
* This module adds dgkeyword provider to the real time data module | ||
* The {@link module:modules/realTimeData} module is required | ||
* The module will get keywords from 1plux profile api. | ||
* This module can work only with AppNexusBidAdapter. | ||
* @module modules/dgkeywordProvider | ||
* @requires module:modules/realTimeData | ||
*/ | ||
|
||
import * as utils from '../src/utils.js'; | ||
import { ajax } from '../src/ajax.js'; | ||
import { submodule } from '../src/hook.js'; | ||
import { getGlobal } from '../src/prebidGlobal.js'; | ||
|
||
/** | ||
* get keywords from api server. and set keywords. | ||
* @param {Object} reqBidsConfigObj | ||
* @param {function} callback | ||
* @param {Object} moduleConfig | ||
* @param {Object} userConsent | ||
*/ | ||
export function getDgKeywordsAndSet(reqBidsConfigObj, callback, moduleConfig, userConsent) { | ||
const URL = 'https://mediaconsortium.profiles.tagger.opecloud.com/api/v1?url='; | ||
const PROFILE_TIMEOUT_MS = 1000; | ||
const timeout = (moduleConfig && moduleConfig.params && moduleConfig.params.timeout && Number(moduleConfig.params.timeout) > 0) ? Number(moduleConfig.params.timeout) : PROFILE_TIMEOUT_MS; | ||
const url = (moduleConfig && moduleConfig.params && moduleConfig.params.url) ? moduleConfig.params.url : URL + encodeURIComponent(window.location.href); | ||
const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits; | ||
let isFinish = false; | ||
utils.logMessage('[dgkeyword sub module]', adUnits, timeout); | ||
let setKeywordTargetBidders = getTargetBidderOfDgKeywords(adUnits); | ||
if (setKeywordTargetBidders.length <= 0) { | ||
utils.logMessage('[dgkeyword sub module] no dgkeyword targets.'); | ||
callback(); | ||
} else { | ||
utils.logMessage('[dgkeyword sub module] dgkeyword targets:', setKeywordTargetBidders); | ||
utils.logMessage('[dgkeyword sub module] get targets from profile api start.'); | ||
ajax(url, { | ||
success: function(response) { | ||
const res = JSON.parse(response); | ||
if (!isFinish) { | ||
utils.logMessage('[dgkeyword sub module] get targets from profile api end.'); | ||
if (res) { | ||
let keywords = {}; | ||
if (res['s'] != null && res['s'].length > 0) { | ||
keywords['opeaud'] = res['s']; | ||
} | ||
if (res['t'] != null && res['t'].length > 0) { | ||
keywords['opectx'] = res['t']; | ||
} | ||
if (Object.keys(keywords).length > 0) { | ||
const targetBidKeys = {} | ||
for (let bid of setKeywordTargetBidders) { | ||
// set keywords to params | ||
bid.params.keywords = keywords; | ||
if (!targetBidKeys[bid.bidder]) { | ||
targetBidKeys[bid.bidder] = true; | ||
} | ||
} | ||
|
||
// set keywrods to ortb2 | ||
let addOrtb2 = {}; | ||
utils.deepSetValue(addOrtb2, 'site.keywords', keywords); | ||
utils.deepSetValue(addOrtb2, 'user.keywords', keywords); | ||
const ortb2 = {ortb2: addOrtb2}; | ||
getGlobal().setBidderConfig({ bidders: Object.keys(targetBidKeys), config: ortb2 }); | ||
} | ||
} | ||
isFinish = true; | ||
} | ||
callback(); | ||
}, | ||
error: function(errorStatus) { | ||
// error occur | ||
utils.logError('[dgkeyword sub module] profile api access error.', errorStatus); | ||
callback(); | ||
} | ||
}, null, { | ||
withCredentials: true, | ||
contentType: 'application/json', | ||
}); | ||
setTimeout(function () { | ||
if (!isFinish) { | ||
// profile api timeout | ||
utils.logInfo('[dgkeyword sub module] profile api timeout. [timeout: ' + timeout + 'ms]'); | ||
isFinish = true; | ||
} | ||
callback(); | ||
}, timeout); | ||
} | ||
} | ||
|
||
/** | ||
* get all bidder which hava {dgkeyword: true} in params | ||
* @param {Object} adUnits | ||
*/ | ||
export function getTargetBidderOfDgKeywords(adUnits) { | ||
let setKeywordTargetBidders = []; | ||
for (let adUnit of adUnits) { | ||
for (let bid of adUnit.bids) { | ||
if (bid.params && bid.params['dgkeyword'] === true) { | ||
delete bid.params['dgkeyword']; | ||
setKeywordTargetBidders.push(bid); | ||
} | ||
} | ||
} | ||
return setKeywordTargetBidders; | ||
} | ||
|
||
/** @type {RtdSubmodule} */ | ||
export const dgkeywordSubmodule = { | ||
/** | ||
* used to link submodule with realTimeData | ||
* @type {string} | ||
*/ | ||
name: 'dgkeyword', | ||
/** | ||
* get data and send back to realTimeData module | ||
* @function | ||
* @param {string[]} adUnitsCodes | ||
*/ | ||
getBidRequestData: getDgKeywordsAndSet, | ||
init: init, | ||
}; | ||
|
||
function init(moduleConfig) { | ||
return true; | ||
} | ||
|
||
function registerSubModule() { | ||
submodule('realTimeData', dgkeywordSubmodule); | ||
} | ||
registerSubModule(); |
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,35 @@ | ||
## Overview | ||
|
||
Module Name: Digital Garage Keyword Module | ||
Module Type: Rtd Provider | ||
Maintainer: mediaconsortium-develop@bi.garage.co.jp | ||
Remarks: This module can work only with AppNexusBidAdapter. | ||
## Integration | ||
|
||
1) Compile the Digital Garage Keyword Module and Appnexus Bid Adapter into your Prebid build: | ||
|
||
``` | ||
gulp build --modules="dgkeywordRtdProvider,appnexusBidAdapter,..." | ||
``` | ||
|
||
2) Use `setConfig` to instruct Prebid.js to initilize the dgkeyword module, as specified below. | ||
|
||
## Configuration | ||
|
||
This module is configured as part of the `realTimeData.dataProviders` | ||
|
||
```javascript | ||
var DGKEYWORD_TIMEOUT = 1000; | ||
pbjs.setConfig({ | ||
realTimeData: { | ||
auctionDelay: DGKEYWORD_TIMEOUT, | ||
dataProviders: [{ | ||
name: 'dgkeyword', | ||
waitForIt: true, | ||
params: { | ||
timeout: DGKEYWORD_TIMEOUT | ||
} | ||
}] | ||
} | ||
}); | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this line. Better documentation is needed here. I don't understand what your module does or how pubs are supposed to use it.
At a high level, RTD modules MUST be setting data in standard locations by default -- not bidder-specific locations. It is ok to also set data in bidder-specific params, but that should be considered secondary.
So please try again and describe the different use cases for this module, including how pubs interact with it and where the data ends up in the bidrequest/adunit object.