Skip to content

Commit

Permalink
Add support for additional content signals under the iab_content (pre…
Browse files Browse the repository at this point in the history
  • Loading branch information
nkloeber authored and JacobKlein26 committed Feb 8, 2023
1 parent 97f4221 commit f8ddf8f
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 8 deletions.
27 changes: 19 additions & 8 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,32 @@ function getContentObject(bid) {
}

/**
* Creates a string for iab_content object
* Creates a string for iab_content object by
* 1. flatten the iab content object
* 2. encoding the values
* 3. joining array of defined keys ('keyword', 'cat') into one value seperated with '|'
* 4. encoding the whole string
* @param {Object} iabContent
* @returns {String}
*/
function createIabContentString(iabContent) {
const arrKeys = ['keywords', 'cat']
const str = []
for (const key in iabContent) {
if (iabContent.hasOwnProperty(key)) {
const value = (arrKeys.indexOf(key) !== -1 && Array.isArray(iabContent[key]))
? iabContent[key].map(node => encodeURIComponent(node)).join('|') : encodeURIComponent(iabContent[key])
str.push(''.concat(key, ':', value))
const transformObjToParam = (obj = {}, extraKey = '') => {
for (const key in obj) {
if ((arrKeys.indexOf(key) !== -1 && Array.isArray(obj[key]))) {
// Array of defined keyword which have to be joined into one value from "key: [value1, value2, value3]" to "key:value1|value2|value3"
str.push(''.concat(key, ':', obj[key].map(node => encodeURIComponent(node)).join('|')))
} else if (typeof obj[key] !== 'object') {
str.push(''.concat(extraKey + key, ':', encodeURIComponent(obj[key])))
} else {
// Object has to be further flattened
transformObjToParam(obj[key], ''.concat(extraKey, key, '.'));
}
}
}
return encodeURIComponent(str.join(','))
return str.join(',');
};
return encodeURIComponent(transformObjToParam(iabContent))
}

/**
Expand Down
125 changes: 125 additions & 0 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,81 @@ const NATIVE_REQUEST = () => Object.assign(DEFAULT_REQUEST(), {
}
})

const IAB_REQUEST = () => Object.assign(DEFAULT_REQUEST(), {
params: {
adslotId: '1111',
supplyId: '2222',
iabContent: {
id: 'foo',
episode: '99',
title: 'bar',
series: 'baz',
season: 's01',
artist: 'foobar',
genre: 'barbaz',
isrc: 'CC-XXX-YY-NNNNN',
url: 'https://foo.test',
cat: ['cat1', 'cat2,ppp', 'cat3|||//'],
context: '2',
keywords: ['k1', 'k2', 'k3', 'k4'],
live: '0',
album: 'foo',
cattax: '3',
prodq: 2,
contentrating: 'foo',
userrating: 'bar',
qagmediarating: 2,
sourcerelationship: 1,
len: 12345,
language: 'en',
embeddable: 0,
producer: {
id: 'foo',
name: 'bar',
cattax: 532,
cat: [1, 'foo', true],
domain: 'producer.test'
},
data: {
id: 'foo',
name: 'bar',
segment: [{
name: 'foo',
value: 'bar',
ext: {
foo: {
bar: 'bar'
}
},
}, {
name: 'foo2',
value: 'bar2',
ext: {
test: {
nums: {
int: 123,
float: 123.123
},
bool: true,
string: 'foo2'
}
}
}],
},
network: {
id: 'foo',
name: 'bar',
domain: 'network.test'
},
channel: {
id: 'bar',
name: 'foo',
domain: 'channel.test'
}
}
}
})

const RESPONSE = {
advertiser: 'yieldlab',
curl: 'https://www.yieldlab.de',
Expand Down Expand Up @@ -251,6 +326,56 @@ describe('yieldlabBidAdapter', () => {
const request = spec.buildRequests([{...requestWithoutIabContent, ...siteConfig}])
expect(request.url).to.include('iab_content=id%3Aid_from_config')
})

it('flattens the iabContent, encodes the values, joins the keywords into one value, and than encodes the iab_content request param ', () => {
const expectedIabContentValue = encodeURIComponent(
'id:foo,' +
'episode:99,' +
'title:bar,' +
'series:baz,' +
'season:s01,' +
'artist:foobar,' +
'genre:barbaz,' +
'isrc:CC-XXX-YY-NNNNN,' +
'url:https%3A%2F%2Ffoo.test,' +
'cat:cat1|cat2%2Cppp|cat3%7C%7C%7C%2F%2F,' +
'context:2,' +
'keywords:k1|k2|k3|k4,' +
'live:0,' +
'album:foo,' +
'cattax:3,' +
'prodq:2,' +
'contentrating:foo,' +
'userrating:bar,' +
'qagmediarating:2,' +
'sourcerelationship:1,' +
'len:12345,' +
'language:en,' +
'embeddable:0,' +
'producer.id:foo,' +
'producer.name:bar,' +
'producer.cattax:532,' +
'cat:1|foo|true,' +
'producer.domain:producer.test,' +
'data.id:foo,data.name:bar,' +
'data.segment.0.name:foo,' +
'data.segment.0.value:bar,' +
'data.segment.0.ext.foo.bar:bar,' +
'data.segment.1.name:foo2,' +
'data.segment.1.value:bar2,' +
'data.segment.1.ext.test.nums.int:123,' +
'data.segment.1.ext.test.nums.float:123.123,' +
'data.segment.1.ext.test.bool:true,' +
'data.segment.1.ext.test.string:foo2,' +
'network.id:foo,network.name:bar,' +
'network.domain:network.test,' +
'channel.id:bar,' +
'channel.name:foo,' +
'channel.domain:channel.test'
)
const request = spec.buildRequests([IAB_REQUEST()], REQPARAMS)
expect(request.url).to.include('iab_content=' + expectedIabContentValue)
})
})

it('passes unencoded schain string to bid request when complete == 0', () => {
Expand Down

0 comments on commit f8ddf8f

Please sign in to comment.