Skip to content

Commit

Permalink
Nativo Bid Adapter: added bid size qs parameter to the request (#8523)
Browse files Browse the repository at this point in the history
* Initial nativoBidAdapter document creation (js, md and spec)

* Fulling working prebid using nativoBidAdapter. Support for GDPR and CCPA in user syncs.

* Added defult size settings based on the largest ad unit. Added response body validation. Added consent to request url qs params.

* Changed bidder endpoint url

* Changed double quotes to single quotes.

* Reverted package-json.lock to remove modifications from PR

* Added optional bidder param 'url' so the ad server can force- match an existing placement

* Lint fix. Added space after if.

* Added new QS param to send various adUnit data to adapter endpopint

* Updated unit test for new QS param

* Added qs param to keep track of ad unit refreshes

* Updated bidMap key default value

* Updated refresh increment logic

* Refactored spread operator for IE11 support

* Updated isBidRequestValid check

* Refactored Object.enties to use Object.keys to fix CircleCI testing errors

* Updated bid mapping key creation to prioritize ad unit code over placementId

* Added filtering by ad, advertiser and campaign.

* Merged master

* Added more robust bidDataMap with multiple key access

* Deduped filer values

* Rolled back package.json

* Duped upstream/master's package.lock file ... not sure how it got changed in the first place

* Small refactor of filterData length check. Removed comparison with 0 since a length value of 0 is already falsy.

* Added bid sizes to request

* Fixed function name in spec. Added unit tests.
  • Loading branch information
jsfledd authored Jun 21, 2022
1 parent 0727222 commit 59ffde0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 24 deletions.
26 changes: 19 additions & 7 deletions modules/nativoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SUPPORTED_AD_TYPES = [BANNER]
* Keep track of bid data by keys
* @returns {Object} - Map of bid data that can be referenced by multiple keys
*/
const BidDataMap = () => {
export const BidDataMap = () => {
const referenceMap = {}
const bids = []

Expand All @@ -25,7 +25,7 @@ const BidDataMap = () => {
* @param {String} key - The key to store the index reference
* @param {Integer} index - The index value of the bidData
*/
function adKeyReference(key, index) {
function addKeyReference(key, index) {
if (!referenceMap.hasOwnProperty(key)) {
referenceMap[key] = index
}
Expand All @@ -42,12 +42,12 @@ const BidDataMap = () => {

if (Array.isArray(keys)) {
keys.forEach((key) => {
adKeyReference(String(key), index)
addKeyReference(String(key), index)
})
return
}

adKeyReference(String(keys), index)
addKeyReference(String(keys), index)
}

/**
Expand Down Expand Up @@ -132,8 +132,9 @@ export const spec = {
*/
buildRequests: function (validBidRequests, bidderRequest) {
const placementIds = new Set()
let placementId, pageUrl
const bidDataMap = BidDataMap()
const placementSizes = { length: 0 }
let placementId, pageUrl
validBidRequests.forEach((request) => {
pageUrl = deepAccess(
request,
Expand All @@ -142,15 +143,21 @@ export const spec = {
)
placementId = deepAccess(request, 'params.placementId')

if (placementId) {
const bidDataKeys = [request.adUnitCode]

if (placementId && !placementIds.has(placementId)) {
placementIds.add(placementId)
bidDataKeys.push(placementId)

placementSizes[placementId] = request.sizes
placementSizes.length++
}

const bidData = {
bidId: request.bidId,
size: getLargestSize(request.sizes),
}
bidDataMap.addBidData(bidData, [placementId, request.adUnitCode])
bidDataMap.addBidData(bidData, bidDataKeys)
})
bidRequestMap[bidderRequest.bidderRequestId] = bidDataMap

Expand Down Expand Up @@ -199,6 +206,11 @@ export const spec = {
params.unshift({ key: 'ntv_ctf', value: Array.from(campaignsToFilter).join(',') })
}

// Placement Sizes
if (placementSizes.length) {
params.unshift({ key: 'ntv_pas', value: btoa(JSON.stringify(placementSizes)) })
}

// Add placement IDs
if (placementIds.size > 0) {
// Convert Set to Array (IE 11 Safe)
Expand Down
84 changes: 67 additions & 17 deletions test/spec/modules/nativoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
import { expect } from 'chai'
import { spec } from 'modules/nativoBidAdapter.js'
import { spec, BidDataMap } from 'modules/nativoBidAdapter.js'

describe('bidDataMap', function () {
it('Should fail gracefully if no key value pairs have been added and no key is sent', function () {
const bdm = new BidDataMap()
const bidData = bdm.getBidData()
expect(bidData).to.be.undefined
})

it('Should fail gracefully if no key value pairs have been added', function () {
const bdm = new BidDataMap()
const bidData = bdm.getBidData('testKey')
expect(bidData).to.be.undefined
})

it('Should add bid data to corresponding keys', function () {
const keys = ['key1', 'anotherKey', 6]
const bidData = { prop: 'value' }

const bdm = new BidDataMap()
bdm.addBidData(bidData, keys)
const bidDataKey0 = bdm.getBidData(keys[0])
const bidDataKey1 = bdm.getBidData(keys[1])
const bidDataKey2 = bdm.getBidData(keys[2])
expect(bidDataKey0).to.be.equal(bidData)
expect(bidDataKey1).to.be.equal(bidData)
expect(bidDataKey2).to.be.equal(bidData)
})
})

describe('nativoBidAdapterTests', function () {
describe('isBidRequestValid', function () {
Expand Down Expand Up @@ -48,23 +76,28 @@ describe('nativoBidAdapterTests', function () {
})

describe('buildRequests', function () {
let bidRequests = [
{
bidder: 'nativo',
params: {
placementId: '10433394',
},
adUnitCode: 'adunit-code',
sizes: [
[300, 250],
[300, 600],
],
bidId: '27b02036ccfa6e',
bidderRequestId: '1372cd8bd8d6a8',
auctionId: 'cfc467e4-2707-48da-becb-bcaab0b2c114',
transactionId: '3b36e7e0-0c3e-4006-a279-a741239154ff',
const bidRequest = {
bidder: 'nativo',
params: {
placementId: '10433394',
},
]
adUnitCode: 'adunit-code',
sizes: [
[300, 250],
[300, 600],
],
bidId: '27b02036ccfa6e',
bidderRequestId: '1372cd8bd8d6a8',
auctionId: 'cfc467e4-2707-48da-becb-bcaab0b2c114',
transactionId: '3b36e7e0-0c3e-4006-a279-a741239154ff',
}
const bidRequestString = JSON.stringify(bidRequest)
let bidRequests

beforeEach(function() {
// Clone bidRequest each time
bidRequests = [JSON.parse(bidRequestString)]
})

it('url should contain query string parameters', function () {
const request = spec.buildRequests(bidRequests, {
Expand All @@ -83,6 +116,23 @@ describe('nativoBidAdapterTests', function () {
expect(request.url).to.include('ntv_ppc')
expect(request.url).to.include('ntv_url')
expect(request.url).to.include('ntv_dbr')
expect(request.url).to.include('ntv_pas')
})

it('url should NOT contain placement specific query string parameters if placementId option is not provided', function () {
bidRequests[0].params = {}
const request = spec.buildRequests(bidRequests, {
bidderRequestId: 123456,
refererInfo: {
referer: 'https://www.test.com',
},
})

expect(request.url).to.exist
expect(request.url).to.be.a('string')

expect(request.url).to.not.include('ntv_pas')
expect(request.url).to.not.include('ntv_ptd')
})
})
})
Expand Down

0 comments on commit 59ffde0

Please sign in to comment.