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

ADSS-281 implement getUserSyncs and putting checks for empty ad serve… #2377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ function buildRequests (validBidRequests) {
function interpretResponse (serverResponse, bidRequest) {
const bidResponses = []
const serverResponseBody = serverResponse.body
const defaultResponse = {
ad: {
price: 0,
id: 0,
markup: ''
},
pag: {
pvid: 0
}
}
const {
ad: {
price: cpm,
Expand All @@ -158,7 +168,7 @@ function interpretResponse (serverResponse, bidRequest) {
pag: {
pvid
}
} = serverResponseBody
} = Object.assign(defaultResponse, serverResponseBody)
let isTestUnit = (bidRequest.data && bidRequest.data.pi === 3 && bidRequest.data.si === 9)
let [width, height] = utils.parseSizesInput(bidRequest.sizes)[0].split('x')

Expand All @@ -183,11 +193,35 @@ function interpretResponse (serverResponse, bidRequest) {
return bidResponses
}

/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*/
function getUserSyncs (syncOptions, serverResponses) {
const responses = serverResponses.map((response) => {
return (response.body && response.body.pxs && response.body.pxs.scr) || []
})
const userSyncs = responses.reduce(function (usersyncs, response) {
return usersyncs.concat(response)
}, [])
const syncs = userSyncs.map((sync) => {
return {
type: sync.t === 'f' ? 'iframe' : 'image',
url: sync.u
}
})
return syncs;
}

export const spec = {
code: BIDDER_CODE,
aliases: ALIAS_BIDDER_CODE,
isBidRequestValid,
buildRequests,
interpretResponse
interpretResponse,
getUserSyncs
}
registerBidder(spec)
22 changes: 22 additions & 0 deletions test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,26 @@ describe('gumgumAdapter', () => {
expect(result.length).to.equal(0);
});
})
describe('getUserSyncs', () => {
const syncOptions = {
'iframeEnabled': 'true'
}
const response = {
'pxs': {
'scr': [
{
't': 'i',
'u': 'https://c.gumgum.com/images/pixel.gif'
},
{
't': 'f',
'u': 'https://www.nytimes.com/'
}
]
}
}
let result = spec.getUserSyncs(syncOptions, [{ body: response }]);
expect(result[0].type).to.equal('image')
expect(result[1].type).to.equal('iframe')
})
});