Skip to content

Commit

Permalink
Add gdpr and targeting support for Yieldlab adapter (#2755)
Browse files Browse the repository at this point in the history
* Add targeting support

Support for optional key-value targeting. As the request to Yieldlab is joint, we expect the targeting params to be present for only one of the adUnits or to be the same for every adUnit.

* Add GDPR support

Support for the Prebid.js consent management module. Passing "consent" and "gdpr" (default: true) parameters if present.
  • Loading branch information
mirkorean authored and harpere committed Jun 22, 2018
1 parent 415926a commit e8f543b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
32 changes: 30 additions & 2 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,32 @@ export const spec = {
* @param validBidRequests
* @returns {{method: string, url: string}}
*/
buildRequests: function (validBidRequests) {
buildRequests: function (validBidRequests, bidderRequest) {
const adslotIds = []
const timestamp = Date.now()
const query = {
ts: timestamp,
json: true
}

utils._each(validBidRequests, function (bid) {
adslotIds.push(bid.params.adslotId)
if (bid.params.targeting) {
query.t = createQueryString(bid.params.targeting)
}
})

if (bidderRequest && bidderRequest.gdprConsent) {
query.consent = bidderRequest.gdprConsent.consentString
query.gdpr = (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true
}

const adslots = adslotIds.join(',')
const queryString = createQueryString(query)

return {
method: 'GET',
url: `${ENDPOINT}/yp/${adslots}?ts=${timestamp}&json=true`,
url: `${ENDPOINT}/yp/${adslots}?${queryString}`,
validBidRequests: validBidRequests
}
},
Expand Down Expand Up @@ -104,4 +117,19 @@ function parseSize (size) {
return size.split('x').map(Number)
}

/**
* Creates a querystring out of an object with key-values
* @param {Object} obj
* @returns {String}
*/
function createQueryString (obj) {
let str = []
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
}
}
return str.join('&')
}

registerBidder(spec)
6 changes: 5 additions & 1 deletion modules/yieldlabBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Module that connects to Yieldlab's demand sources
params: {
adslotId: "5220336",
supplyId: "1381604",
adSize: "728x90"
adSize: "728x90",
targeting: {
key1: "value1",
key2: "value2"
}
}
}]
}, {
Expand Down
22 changes: 21 additions & 1 deletion test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const REQUEST = {
'params': {
'adslotId': '1111',
'supplyId': '2222',
'adSize': '728x90'
'adSize': '728x90',
'targeting': {
'key1': 'value1',
'key2': 'value2'
}
},
'bidderRequestId': '143346cf0f1731',
'auctionId': '2e41f65424c87c',
Expand Down Expand Up @@ -62,6 +66,22 @@ describe('yieldlabBidAdapter', () => {
it('returns a list of valid requests', () => {
expect(request.validBidRequests).to.eql([REQUEST])
})

it('passes targeting to bid request', () => {
expect(request.url).to.include('t=key1%3Dvalue1%26key2%3Dvalue2')
})

const gdprRequest = spec.buildRequests(bidRequests, {
gdprConsent: {
consentString: 'BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA',
gdprApplies: true
}
})

it('passes gdpr flag and consent if present', () => {
expect(gdprRequest.url).to.include('consent=BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA')
expect(gdprRequest.url).to.include('gdpr=true')
})
})

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

0 comments on commit e8f543b

Please sign in to comment.