Skip to content
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

Microad Bid Adapter: Added Support for Audience IDs #8662

Merged
merged 13 commits into from
Jul 25, 2022
Merged
26 changes: 23 additions & 3 deletions modules/microadBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ const BANNER_CODE = 1;
const NATIVE_CODE = 2;
const VIDEO_CODE = 4;

const AUDIENCE_IDS = [
{type: 6, bidKey: 'userId.imuid'},
{type: 8, bidKey: 'userId.id5id.uid'},
{type: 9, bidKey: 'userId.tdid'},
{type: 10, bidKey: 'userId.novatiq.snowflake'},
{type: 11, bidKey: 'userId.parrableId.eid'},
{type: 12, bidKey: 'userId.dacId.id'},
{type: 13, bidKey: 'userId.idl_env'},
{type: 14, bidKey: 'userId.criteoId'},
{type: 15, bidKey: 'userId.pubcid'}
]

function createCBT() {
const randomValue = Math.floor(Math.random() * Math.pow(10, 18)).toString(16);
const date = new Date().getTime().toString(16);
Expand Down Expand Up @@ -83,9 +95,17 @@ export const spec = {
}
}

const idlEnv = deepAccess(bid, 'userId.idl_env')
if (!isEmpty(idlEnv) && isStr(idlEnv)) {
params['idl_env'] = idlEnv
const aidsParams = []
AUDIENCE_IDS.forEach((audienceId) => {
const bidAudienceId = deepAccess(bid, audienceId.bidKey);
if (!isEmpty(bidAudienceId) && isStr(bidAudienceId)) {
aidsParams.push({ type: audienceId.type, id: bidAudienceId });
// Set Ramp ID
if (audienceId.type === 13) params['idl_env'] = bidAudienceId;
}
})
if (aidsParams.length > 0) {
params['aids'] = JSON.stringify(aidsParams)
}

requests.push({
Expand Down
71 changes: 53 additions & 18 deletions test/spec/modules/microadBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,35 +266,70 @@ describe('microadBidAdapter', () => {
});
});

it('should add Liveramp identity link if it is available in request parameters', () => {
const bidRequestWithLiveramp = Object.assign({}, bidRequestTemplate, {
userId: {idl_env: 'idl-env-sample'}
it('should not add Liveramp identity link and Audience ID if it is not available in request parameters', () => {
const bidRequestWithOutLiveramp = Object.assign({}, bidRequestTemplate, {
userId: {}
});
const requests = spec.buildRequests([bidRequestWithLiveramp], bidderRequest)
const requests = spec.buildRequests([bidRequestWithOutLiveramp], bidderRequest)
requests.forEach(request => {
expect(request.data).to.deep.equal(
Object.assign({}, expectedResultTemplate, {
cbt: request.data.cbt,
idl_env: 'idl-env-sample'
cbt: request.data.cbt
})
);
})
});

it('should not add Liveramp identity link if it is not available in request parameters', () => {
const bidRequestWithLiveramp = Object.assign({}, bidRequestTemplate, {
userId: {}
});
const requests = spec.buildRequests([bidRequestWithLiveramp], bidderRequest)
const expectedResult = Object.assign({}, expectedResultTemplate)
requests.forEach(request => {
expect(request.data).to.deep.equal(
Object.assign({}, expectedResultTemplate, {
cbt: request.data.cbt
Object.entries({
'IM-UID': {
userId: {imuid: 'imuid-sample'},
expected: {aids: JSON.stringify([{type: 6, id: 'imuid-sample'}])}
},
'ID5 ID': {
userId: {id5id: {uid: 'id5id-sample'}},
expected: {aids: JSON.stringify([{type: 8, id: 'id5id-sample'}])}
},
'Unified ID': {
userId: {tdid: 'unified-sample'},
expected: {aids: JSON.stringify([{type: 9, id: 'unified-sample'}])}
},
'Novatiq Snowflake ID': {
userId: {novatiq: {snowflake: 'novatiq-sample'}},
expected: {aids: JSON.stringify([{type: 10, id: 'novatiq-sample'}])}
},
'Parrable ID': {
userId: {parrableId: {eid: 'parrable-sample'}},
expected: {aids: JSON.stringify([{type: 11, id: 'parrable-sample'}])}
},
'AudienceOne User ID': {
userId: {dacId: {id: 'audience-one-sample'}},
expected: {aids: JSON.stringify([{type: 12, id: 'audience-one-sample'}])}
},
'Ramp ID and Liveramp identity': {
userId: {idl_env: 'idl-env-sample'},
expected: {idl_env: 'idl-env-sample', aids: JSON.stringify([{type: 13, id: 'idl-env-sample'}])}
},
'Criteo ID': {
userId: {criteoId: 'criteo-id-sample'},
expected: {aids: JSON.stringify([{type: 14, id: 'criteo-id-sample'}])}
},
'Shared ID': {
userId: {pubcid: 'shared-id-sample'},
expected: {aids: JSON.stringify([{type: 15, id: 'shared-id-sample'}])}
}
}).forEach(([test, arg]) => {
it(`should add ${test} if it is available in request parameters`, () => {
const bidRequestWithUserId = { ...bidRequestTemplate, userId: arg.userId }
const requests = spec.buildRequests([bidRequestWithUserId], bidderRequest)
requests.forEach((request) => {
expect(request.data).to.deep.equal({
...expectedResultTemplate,
cbt: request.data.cbt,
...arg.expected
})
);
})
})
});
})
});

describe('interpretResponse', () => {
Expand Down