forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 5
First commit to user id module #35
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b5b5b03
OpenX: Analytics Adapter update
108b257
OX UserId Module - first commit
579be7f
Updated API calls per https://openxtechinc.atlassian.net/browse/OAPLT…
6382886
updated bid adapter query param per https://openxtechinc.atlassian.ne…
eab0eca
Updated openRtbBidAdapter per changes from https://github.com/openx/p…
823868e
bump adapter version
3963299
added config for eids
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 hidden or 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,126 @@ | ||
| /** | ||
| * This module adds OpenAudience to the User ID module | ||
| * The {@link module:modules/userId} module is required | ||
| * @module modules/openAudienceIdSystem | ||
| * @requires module:modules/userId | ||
| */ | ||
|
|
||
| import * as utils from '../src/utils.js' | ||
| import {ajax} from '../src/ajax.js'; | ||
| import {submodule} from '../src/hook.js'; | ||
| import {uspDataHandler} from '../src/adapterManager.js'; | ||
|
|
||
| export const OA_URL = 'https://oajs.openx.net/beacon'; | ||
|
|
||
| // Module types | ||
| /** | ||
| * @typedef {Object} OpenAudienceConfig | ||
| * @property {string} resourceId The OpenAudience resource id | ||
| */ | ||
|
|
||
| /** | ||
| * @typedef {Object} OpenAudienceIdObject | ||
| * @property {Array<string>} oa_ids A list of OpenAudience Ids | ||
| */ | ||
|
|
||
| /** @type {Submodule} */ | ||
| export const openAudienceSubmodule = { | ||
| /** | ||
| * used to link submodule with config | ||
| * @type {string} | ||
| */ | ||
| name: 'openAudience', | ||
| /** | ||
| * decode the stored id value for passing to bid requests | ||
| * @function | ||
| * @param {string} value | ||
| * @returns {{oaid:string}} | ||
| */ | ||
|
|
||
| /** | ||
| * | ||
| * @param {OpenAudienceIdObject|undefined} storedIdObj The current cached object | ||
| * @param {OpenAudienceConfig|undefined} configParams | ||
| * @returns {{oa: OpenAudienceIdObject}} | ||
| */ | ||
| decode(storedIdObj, configParams) { | ||
| return { 'oa': storedIdObj }; | ||
| }, | ||
|
|
||
| /** | ||
| * performs action to obtain id and return a value in the callback's response argument | ||
| * @param {OpenAudienceConfig} configParams | ||
| * @param {ConsentData|undefined} consentData | ||
| * @param {(OpenAudienceIdObject|undefined)} cacheIdObj | ||
| * @return {(IdResponse|undefined)} A response object that contains id and/or callback. | ||
| */ | ||
| getId(configParams, consentData, cacheIdObj) { | ||
| if (!configParams || typeof configParams.resourceId !== 'string') { | ||
| utils.logError('openAudience submodule requires resource id to be defined'); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| return {callback: getOaIds}; | ||
|
|
||
| /** | ||
| * Requests for OpenAudienceIDs through oajs and fallback directly to API. | ||
| * @param callback | ||
| */ | ||
| function getOaIds(callback) { | ||
| // If oajs is available, use it to retrieve id object. If not, fall back to API. | ||
| if (window.oajs) { | ||
jimee02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| window.oajs.getIds(callback); | ||
| } else { | ||
| let params = { | ||
| rid: configParams.resourceId, | ||
| ...getConsentQueryParams(consentData, uspDataHandler.getConsentData()) | ||
| }; | ||
| getOaData(`${OA_URL}?${utils.formatQS(params)}`, callback); | ||
| } | ||
|
|
||
| function getConsentQueryParams(gdprConsent, usPrivacy) { | ||
| const hasGdpr = (gdprConsent && typeof gdprConsent.gdprApplies === 'boolean' && gdprConsent.gdprApplies) ? 1 : 0; | ||
|
|
||
| let consentParams = { | ||
| gdpr: hasGdpr | ||
| }; | ||
|
|
||
| if (hasGdpr) { | ||
| consentParams.gdpr_consent = gdprConsent && gdprConsent.consentString | ||
| } | ||
|
|
||
| if (usPrivacy) { | ||
| consentParams.us_privacy = usPrivacy; | ||
| } | ||
|
|
||
| return consentParams; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| function getOaData(url, callback) { | ||
| const responseHandlers = { | ||
| success: response => { | ||
| let responseObj = {}; | ||
| if (response) { | ||
| try { | ||
| responseObj = JSON.parse(response); | ||
| } catch (error) { | ||
| utils.logError(error); | ||
| } | ||
| } | ||
| callback(responseObj.oa_ids && responseObj.oa_ids.length !== undefined ? responseObj : undefined); | ||
|
||
| }, | ||
| error: errorResponse => { | ||
| utils.logError(`openAudience: ID fetch encountered an error`, errorResponse); | ||
| callback(); | ||
| } | ||
| }; | ||
|
|
||
| ajax(url, responseHandlers, undefined, {method: 'GET', withCredentials: true}); | ||
| } | ||
|
|
||
| submodule('userId', openAudienceSubmodule); | ||
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.
our key will be
oa