diff --git a/modules/tapadRtdProvider.js b/modules/tapadRtdProvider.js index b25026a3766..b57fb3dd5a2 100644 --- a/modules/tapadRtdProvider.js +++ b/modules/tapadRtdProvider.js @@ -1,7 +1,7 @@ import { submodule } from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; import { MODULE_TYPE_RTD } from '../src/activities/modules.js'; -import { mergeDeep, safeJSONParse, timestamp } from '../src/utils.js'; +import { isArray, isPlainObject, mergeDeep, safeJSONParse, timestamp } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; export const SUBMODULE_NAME = 'tapad_rtd'; @@ -33,7 +33,6 @@ export const tapadRtdObj = { if (now > new Date(stale).getTime()) { // request data envelope and manipulate bids tapadRtdObj.requestDataEnvelope(config, userConsent); - done(); } tapadRtdObj.alterBids(reqBidsConfigObj, config); done() @@ -61,28 +60,37 @@ export const tapadRtdObj = { storage.setDataInLocalStorage(TAPAD_RTD_EXPIRATION_KEY, responseJson.expiresAt, null); } } - const queryString = tapadRtdObj.extractConsentQueryString(userConsent) + const queryString = tapadRtdObj.extractConsentQueryString(config, userConsent) const fullUrl = queryString == null ? `${TAPAD_RTD_URL}/acc/${config.accountId}/ids` : `${TAPAD_RTD_URL}/acc/${config.accountId}/ids${queryString}` ajax(fullUrl, storeDataEnvelopeResponse, null, { withCredentials: true, contentType: 'application/json' }) }, - extractConsentQueryString(userConsent) { + extractConsentQueryString(config, userConsent) { const queryObj = {}; - if (userConsent == null) { - return undefined; - } - if (userConsent.gdpr != null) { - const { gdprApplies, consentString } = userConsent.gdpr; - mergeDeep(queryObj, {gdpr: gdprApplies, gdpr_consent: consentString}) - } - if (userConsent.uspConsent != null) { - mergeDeep(queryObj, {us_privacy: userConsent.uspConsent}) + + if (userConsent != null) { + if (userConsent.gdpr != null) { + const { gdprApplies, consentString } = userConsent.gdpr; + mergeDeep(queryObj, {gdpr: gdprApplies, gdpr_consent: consentString}) + } + if (userConsent.uspConsent != null) { + mergeDeep(queryObj, {us_privacy: userConsent.uspConsent}) + } } - if (Object.keys(queryObj).length > 0) { - return Object.entries(queryObj).reduce((queryString, [key, val], i) => { - return `${queryString}${i === 0 ? '' : '&'}${key}=${val}` - }, '?') + const consentQueryString = Object.entries(queryObj).map(([key, val]) => `${key}=${val}`).join('&'); + + let idsString = ''; + if (config.ids != null && isPlainObject(config.ids)) { + idsString = Object.entries(config.ids).map(([idType, val]) => { + if (isArray(val)) { + return val.map((singleVal) => `id.${idType}=${singleVal}`).join('&') + } else { + return `id.${idType}=${val}` + } + }).join('&') } - return undefined; + + const combinedString = [consentQueryString, idsString].filter((string) => string !== '').join('&'); + return combinedString !== '' ? `?${combinedString}` : undefined; }, /** * @function diff --git a/modules/tapadRtdProvider.md b/modules/tapadRtdProvider.md index 02ca0a310d8..406fcd038e6 100644 --- a/modules/tapadRtdProvider.md +++ b/modules/tapadRtdProvider.md @@ -33,7 +33,8 @@ pbjs.setConfig({ waitForIt: true, params: { accountId: 123, - bidders: ['sovrn', 'pubmatic'] + bidders: ['sovrn', 'pubmatic'], + ids: { maid: ['424', '2982'], hem: 'my-hem' } } }] } @@ -41,10 +42,10 @@ pbjs.setConfig({ ``` ### Parameters -| Name | Type | Description | Default | -|:---------------|:--------------|:-----------------------------------------------------------------|:-------------------| -| name | String | Real time data module name | Always 'tapad_rtd' | -| waitForIt | Boolean | Should be `true` if there's an `auctionDelay` defined (optional) | `false` | -| accountId | String | Your account id issued by Tapad | | -| bidders | Array | List of bidders for which you would like data to be set | | -| params.timeout | Integer | timeout (ms) | 1000ms | +| Name | Type | Description | Default | +|:-----------------|:----------------------------------------|:-----------------------------------------------------------------|:-------------------| +| name | String | Real time data module name | Always 'tapad_rtd' | +| waitForIt | Boolean | Should be `true` if there's an `auctionDelay` defined (optional) | `false` | +| params.accountId | String | Your account id issued by Tapad | | +| params.bidders | Array | List of bidders for which you would like data to be set | | +| params.ids | Record or string> | Additional identifiers to send to Tapad RTID endpoint | | diff --git a/test/spec/modules/tapadRtdProvider_spec.js b/test/spec/modules/tapadRtdProvider_spec.js index 646685dc09e..2637e9f7321 100644 --- a/test/spec/modules/tapadRtdProvider_spec.js +++ b/test/spec/modules/tapadRtdProvider_spec.js @@ -275,14 +275,23 @@ describe('Tapad realtime module', () => { describe('extractConsentQueryString', () => { describe('when userConsent is empty', () => { it('returns undefined', () => { - expect(tapadRtdObj.extractConsentQueryString()).to.be.undefined + expect(tapadRtdObj.extractConsentQueryString({})).to.be.undefined }) }) describe('when userConsent exists', () => { - expect( - tapadRtdObj.extractConsentQueryString({ gdpr: { gdprApplies: 1, consentString: 'this-is-something' }, uspConsent: '1YYY' }) - ).to.equal('?gdpr=1&gdpr_consent=this-is-something&us_privacy=1YYY') + it('builds query string', () => { + expect( + tapadRtdObj.extractConsentQueryString({}, { gdpr: { gdprApplies: 1, consentString: 'this-is-something' }, uspConsent: '1YYY' }) + ).to.equal('?gdpr=1&gdpr_consent=this-is-something&us_privacy=1YYY') + }) + }) + + describe('when config.ids exists', () => { + it('builds query string', () => { + expect(tapadRtdObj.extractConsentQueryString({ ids: { maid: ['424', '2982'], hem: 'my-hem' } }, { gdpr: { gdprApplies: 1, consentString: 'this-is-something' }, uspConsent: '1YYY' })) + .to.equal('?gdpr=1&gdpr_consent=this-is-something&us_privacy=1YYY&id.maid=424&id.maid=2982&id.hem=my-hem') + }) }) }) })