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

IAS RTD Module: Custom key values #8214

Merged
merged 8 commits into from
Mar 31, 2022
43 changes: 42 additions & 1 deletion modules/iasRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ const FRAUD_FIELD_NAME = 'fr';
const SLOTS_OBJECT_FIELD_NAME = 'slots';
const CUSTOM_FIELD_NAME = 'custom';
const IAS_KW = 'ias-kw';
const IAS_KEY_MAPPINGS = {
adt: 'adt',
alc: 'alc',
dlm: 'dlm',
hat: 'hat',
off: 'off',
vio: 'vio',
drg: 'drg',
'ias-kw': 'ias-kw',
fr: 'fr',
vw: 'vw',
grm: 'grm',
pub: 'pub',
vw05: 'vw05',
vw10: 'vw10',
vw15: 'vw15',
vw30: 'vw30',
vw_vv: 'vw_vv',
grm_vv: 'grm_vv',
pub_vv: 'pub_vv',
id: 'id'
};

/**
* Module init
Expand All @@ -26,6 +48,14 @@ export function init(config, userConsent) {
utils.logError('missing pubId param for IAS provider');
return false;
}
if (params.hasOwnProperty('keyMappings')) {
const keyMappings = params.keyMappings;
for (let prop in keyMappings) {
if (IAS_KEY_MAPPINGS.hasOwnProperty(prop)) {
IAS_KEY_MAPPINGS[prop] = keyMappings[prop]
}
}
}
return true;
}

Expand Down Expand Up @@ -62,6 +92,16 @@ function stringifyScreenSize() {
return [(window.screen && window.screen.width) || -1, (window.screen && window.screen.height) || -1].join('.');
}

function renameKeyValues(source) {
let result = {};
for (let prop in IAS_KEY_MAPPINGS) {
if (source.hasOwnProperty(prop)) {
result[IAS_KEY_MAPPINGS[prop]] = source[prop];
}
}
return result;
}

function formatTargetingData(adUnit) {
let result = {};
if (iasTargeting[BRAND_SAFETY_OBJECT_FIELD_NAME]) {
Expand All @@ -76,7 +116,7 @@ function formatTargetingData(adUnit) {
if (iasTargeting[SLOTS_OBJECT_FIELD_NAME] && adUnit in iasTargeting[SLOTS_OBJECT_FIELD_NAME]) {
utils.mergeDeep(result, iasTargeting[SLOTS_OBJECT_FIELD_NAME][adUnit]);
}
return result;
return renameKeyValues(result);
}

function constructQueryString(anId, adUnits) {
Expand Down Expand Up @@ -147,6 +187,7 @@ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) {
undefined,
{ method: 'GET' }
);
callback()
}

/** @type {RtdSubmodule} */
Expand Down
86 changes: 56 additions & 30 deletions test/spec/modules/iasRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('iasRtdProvider is a RTD provider that', function () {
const value = iasSubModule.init(config);
expect(value).to.equal(false);
});
it('returns false missing pubId param', function () {
it('returns true with only the pubId param', function () {
const config = {
name: 'ias',
waitForIt: true,
Expand All @@ -40,6 +40,20 @@ describe('iasRtdProvider is a RTD provider that', function () {
const value = iasSubModule.init(config);
expect(value).to.equal(true);
});
it('returns true with the pubId and keyMappings params', function () {
const config = {
name: 'ias',
waitForIt: true,
params: {
pubId: '123456',
keyMappings: {
'id': 'ias_id'
}
}
};
const value = iasSubModule.init(config);
expect(value).to.equal(true);
});
});
describe('has a method `getBidRequestData` that', function () {
it('exists', function () {
Expand Down Expand Up @@ -75,42 +89,54 @@ describe('iasRtdProvider is a RTD provider that', function () {
it('exists', function () {
expect(iasSubModule.getTargetingData).to.be.a('function');
});
it('invoke method', function () {
const targeting = iasSubModule.getTargetingData(adUnitsCode, config);
expect(adUnitsCode).to.length(2);
expect(targeting).to.be.not.null;
expect(targeting).to.be.not.empty;
expect(targeting['one-div-id']).to.be.not.null;
const targetingKeys = Object.keys(targeting['one-div-id']);
expect(targetingKeys.length).to.equal(10);
expect(targetingKeys['adt']).to.be.not.null;
expect(targetingKeys['alc']).to.be.not.null;
expect(targetingKeys['dlm']).to.be.not.null;
expect(targetingKeys['drg']).to.be.not.null;
expect(targetingKeys['hat']).to.be.not.null;
expect(targetingKeys['off']).to.be.not.null;
expect(targetingKeys['vio']).to.be.not.null;
expect(targetingKeys['fr']).to.be.not.null;
expect(targetingKeys['ias-kw']).to.be.not.null;
expect(targetingKeys['id']).to.be.not.null;
expect(targeting['one-div-id']['adt']).to.be.eq('veryLow');
expect(targeting['one-div-id']['alc']).to.be.eq('veryLow');
expect(targeting['one-div-id']['dlm']).to.be.eq('veryLow');
expect(targeting['one-div-id']['drg']).to.be.eq('veryLow');
expect(targeting['one-div-id']['hat']).to.be.eq('veryLow');
expect(targeting['one-div-id']['off']).to.be.eq('veryLow');
expect(targeting['one-div-id']['vio']).to.be.eq('veryLow');
expect(targeting['one-div-id']['fr']).to.be.eq('false');
expect(targeting['one-div-id']['id']).to.be.eq('4813f7a2-1f22-11ec-9bfd-0a1107f94461');
});
describe('invoke method', function () {
it('returns a targeting object with the right shape', function () {
const targeting = iasSubModule.getTargetingData(adUnitsCode, config);
expect(adUnitsCode).to.length(2);
expect(targeting).to.be.not.null;
expect(targeting).to.be.not.empty;
expect(targeting['one-div-id']).to.be.not.null;
});
it('returns the right keys', function () {
const targeting = iasSubModule.getTargetingData(adUnitsCode, config);
const targetingKeys = Object.keys(targeting['one-div-id']);
expect(targetingKeys.length).to.equal(10);
expect(targetingKeys).to.include('adt', 'adt key missing from the targeting object');
expect(targetingKeys).to.include('alc', 'alc key missing from the targeting object');
expect(targetingKeys).to.include('dlm', 'dlm key missing from the targeting object');
expect(targetingKeys).to.include('drg', 'drg key missing from the targeting object');
expect(targetingKeys).to.include('hat', 'hat key missing from the targeting object');
expect(targetingKeys).to.include('off', 'off key missing from the targeting object');
expect(targetingKeys).to.include('vio', 'vio key missing from the targeting object');
expect(targetingKeys).to.include('fr', 'fr key missing from the targeting object');
expect(targetingKeys).to.include('ias-kw', 'ias-kw key missing from the targeting object');
expect(targetingKeys).to.not.include('id', 'id key present in the targeting object, should have been renamed to ias_id');
expect(targetingKeys).to.include('ias_id', 'ias_id key missing from the targeting object');
});
it('returns the right values', function () {
const targeting = iasSubModule.getTargetingData(adUnitsCode, config);
expect(targeting['one-div-id']['adt']).to.be.eq('veryLow');
expect(targeting['one-div-id']['alc']).to.be.eq('veryLow');
expect(targeting['one-div-id']['dlm']).to.be.eq('veryLow');
expect(targeting['one-div-id']['drg']).to.be.eq('veryLow');
expect(targeting['one-div-id']['hat']).to.be.eq('veryLow');
expect(targeting['one-div-id']['off']).to.be.eq('veryLow');
expect(targeting['one-div-id']['vio']).to.be.eq('veryLow');
expect(targeting['one-div-id']['fr']).to.be.eq('false');
expect(targeting['one-div-id']['ias_id']).to.be.eq('4813f7a2-1f22-11ec-9bfd-0a1107f94461');
});
})
});
});

const config = {
name: 'ias',
waitForIt: true,
params: {
pubId: 1234
pubId: 1234,
keyMappings: {
'id': 'ias_id'
}
}
};

Expand Down