Skip to content

Commit

Permalink
add publisher ids functionality to Tapad RTD submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
moeroach94 committed Aug 17, 2023
1 parent 9cf41dd commit 07cbb9a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
44 changes: 26 additions & 18 deletions modules/tapadRtdProvider.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions modules/tapadRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ pbjs.setConfig({
waitForIt: true,
params: {
accountId: 123,
bidders: ['sovrn', 'pubmatic']
bidders: ['sovrn', 'pubmatic'],
ids: { maid: ['424', '2982'], hem: 'my-hem' }
}
}]
}
})
```

### 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<string> | 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<string> | List of bidders for which you would like data to be set | |
| params.ids | Record<string, Array<string> or string> | Additional identifiers to send to Tapad RTID endpoint | |
17 changes: 13 additions & 4 deletions test/spec/modules/tapadRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})
})

0 comments on commit 07cbb9a

Please sign in to comment.