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

adxcgBidAdapter prebid 3.0 requirements compatibility #4514

Merged
merged 2 commits into from
Dec 3, 2019
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
43 changes: 27 additions & 16 deletions modules/adxcgBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import includes from 'core-js/library/fn/array/includes'
* updated to pass aditional auction and impression level parameters. added pass for video targeting parameters
* updated to fix native support for image width/height and icon 2019.03.17
* updated support for userid - pubcid,ttid 2019.05.28
* updated to support prebid 3.0 -remove non https, move to banner.xx.sizes, remove utils.getTopWindowLocation,remove utils.getTopWindowUrl(),remove utils.getTopWindowReferrer()
*/

const BIDDER_CODE = 'adxcg'
Expand All @@ -20,7 +21,7 @@ const SOURCE = 'pbjs10'
const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration', 'startdelay', 'skippable', 'playback_method', 'frameworks']
const USER_PARAMS_AUCTION = ['forcedDspIds', 'forcedCampaignIds', 'forcedCreativeIds', 'gender', 'dnt', 'language']
const USER_PARAMS_BID = ['lineparam1', 'lineparam2', 'lineparam3']
const BIDADAPTERVERSION = 'r20180703PB10'
const BIDADAPTERVERSION = 'r20191128PB30'

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -71,8 +72,6 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
utils.logMessage(`buildRequests: ${JSON.stringify(validBidRequests)}`)

let location = utils.getTopWindowLocation()
let secure = location.protocol === 'https:'
let dt = new Date()
let ratio = window.devicePixelRatio || 1
let iobavailable = window && window.IntersectionObserver && window.IntersectionObserverEntry && window.IntersectionObserverEntry.prototype && 'intersectionRatio' in window.IntersectionObserverEntry.prototype
Expand All @@ -82,16 +81,11 @@ export const spec = {
bt = Math.min(window.PREBID_TIMEOUT, bt)
}

let requestUrl = url.parse(location.href)
requestUrl.search = null
requestUrl.hash = null

// add common parameters
let beaconParams = {
renderformat: 'javascript',
ver: BIDADAPTERVERSION,
url: encodeURIComponent(utils.getTopWindowUrl()),
secure: secure ? '1' : '0',
secure: '1',
source: SOURCE,
uw: window.screen.width,
uh: window.screen.height,
Expand All @@ -106,9 +100,10 @@ export const spec = {
rndid: Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000
}

if (utils.getTopWindowReferrer()) {
beaconParams.ref = encodeURIComponent(utils.getTopWindowReferrer())
}
const referrer = utils.deepAccess(bidderRequest, 'refererInfo.referer');
const page = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href');
beaconParams.ref = encodeURIComponent(referrer);
beaconParams.url = encodeURIComponent(page);

if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) {
beaconParams.gdpr = bidderRequest.gdprConsent.gdprApplies ? '1' : '0'
Expand All @@ -131,7 +126,10 @@ export const spec = {
validBidRequests.forEach((bid, index) => {
adZoneIds.push(utils.getBidIdParameter('adzoneid', bid.params))
prebidBidIds.push(bid.bidId)
sizes.push(utils.parseSizesInput(bid.sizes).join('|'))

if (isBannerRequest(bid)) {
sizes.push(utils.parseSizesInput(bid.mediaTypes.banner.sizes).join('|'))
}

let bidfloor = utils.getBidIdParameter('bidfloor', bid.params) || 0
bidfloors.push(bidfloor)
Expand All @@ -144,6 +142,7 @@ export const spec = {
}
// copy video context params
beaconParams['video.context' + '.' + index] = utils.deepAccess(bid, 'mediaTypes.video.context')
sizes.push(utils.parseSizesInput(bid.mediaTypes.video.playerSize).join('|'))
}

// copy all custom parameters impression level parameters not supported above
Expand All @@ -168,9 +167,17 @@ export const spec = {
beaconParams.tdid = validBidRequests[0].userId.tdid;
}

if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.id5id'))) {
beaconParams.id5id = validBidRequests[0].userId.id5id;
}

if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.idl_env'))) {
beaconParams.idl_env = validBidRequests[0].userId.idl_env;
}

let adxcgRequestUrl = url.format({
protocol: secure ? 'https' : 'http',
hostname: secure ? 'hbps.adxcg.net' : 'hbp.adxcg.net',
protocol: 'https',
hostname: 'hbps.adxcg.net',
pathname: '/get/adi',
search: beaconParams
})
Expand Down Expand Up @@ -272,7 +279,7 @@ export const spec = {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: '//cdn.adxcg.net/pb-sync.html'
url: 'https://cdn.adxcg.net/pb-sync.html'
}]
}
}
Expand All @@ -282,4 +289,8 @@ function isVideoRequest (bid) {
return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video')
}

function isBannerRequest (bid) {
return bid.mediaType === 'banner' || !!utils.deepAccess(bid, 'mediaTypes.banner')
}

registerBidder(spec)
104 changes: 93 additions & 11 deletions test/spec/modules/adxcgBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ describe('AdxcgAdapter', function () {
'adzoneid': '1'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [640, 360], [1, 1]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [640, 360], [1, 1]]
}
},
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
Expand All @@ -27,11 +31,11 @@ describe('AdxcgAdapter', function () {
},
'mediaTypes': {
'video': {
'context': 'instream'
'context': 'instream',
'playerSize': [[640, 480]]
}
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [640, 360], [1, 1]],
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
Expand Down Expand Up @@ -70,7 +74,11 @@ describe('AdxcgAdapter', function () {
'adzoneid': '1'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [640, 360], [1, 1]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [640, 360], [1, 1]]
}
},
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
Expand All @@ -81,12 +89,12 @@ describe('AdxcgAdapter', function () {
expect(request).to.exist
expect(request.method).to.equal('GET')
let parsedRequestUrl = url.parse(request.url)
expect(parsedRequestUrl.hostname).to.equal('hbp.adxcg.net')
expect(parsedRequestUrl.hostname).to.equal('hbps.adxcg.net')
expect(parsedRequestUrl.pathname).to.equal('/get/adi')

let query = parsedRequestUrl.search
expect(query.renderformat).to.equal('javascript')
expect(query.ver).to.equal('r20180703PB10')
expect(query.ver).to.equal('r20191128PB30')
expect(query.source).to.equal('pbjs10')
expect(query.pbjs).to.equal('$prebid.version$')
expect(query.adzoneid).to.equal('1')
Expand All @@ -103,7 +111,11 @@ describe('AdxcgAdapter', function () {
'adzoneid': '1'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [640, 360], [1, 1]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [640, 360], [1, 1]]
}
},
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
Expand Down Expand Up @@ -140,7 +152,11 @@ describe('AdxcgAdapter', function () {
'adzoneid': '1'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [640, 360], [1, 1]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [640, 360], [1, 1]]
}
},
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
Expand All @@ -165,7 +181,11 @@ describe('AdxcgAdapter', function () {
'adzoneid': '1'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [640, 360], [1, 1]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [640, 360], [1, 1]]
}
},
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
Expand All @@ -183,14 +203,76 @@ describe('AdxcgAdapter', function () {
})
})

describe('userid id5id should be passed to querystring', function () {
let bid = [{
'bidder': 'adxcg',
'params': {
'adzoneid': '1'
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [640, 360], [1, 1]]
}
},
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
}]

let bidderRequests = {};

bid[0].userId = {'id5id': 'id5idsample'};

it('should send pubcid if available', function () {
let request = spec.buildRequests(bid, bidderRequests)
let parsedRequestUrl = url.parse(request.url)
let query = parsedRequestUrl.search
expect(query.id5id).to.equal('id5idsample');
})
})

describe('userid idl_env should be passed to querystring', function () {
let bid = [{
'bidder': 'adxcg',
'params': {
'adzoneid': '1'
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [640, 360], [1, 1]]
}
},
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
}]

let bidderRequests = {};

bid[0].userId = {'idl_env': 'idl_envsample'};

it('should send pubcid if available', function () {
let request = spec.buildRequests(bid, bidderRequests)
let parsedRequestUrl = url.parse(request.url)
let query = parsedRequestUrl.search
expect(query.idl_env).to.equal('idl_envsample');
})
})

describe('response handler', function () {
let BIDDER_REQUEST = {
'bidder': 'adxcg',
'params': {
'adzoneid': '1'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [640, 360], [1, 1]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250], [640, 360], [1, 1]]
}
},
'bidId': '84ab500420319d',
'bidderRequestId': '7101db09af0db2',
'auctionId': '1d1a030790a475',
Expand Down Expand Up @@ -394,7 +476,7 @@ describe('AdxcgAdapter', function () {

it('should return iframe sync option', function () {
expect(spec.getUserSyncs(syncoptionsIframe)[0].type).to.equal('iframe')
expect(spec.getUserSyncs(syncoptionsIframe)[0].url).to.equal('//cdn.adxcg.net/pb-sync.html')
expect(spec.getUserSyncs(syncoptionsIframe)[0].url).to.equal('https://cdn.adxcg.net/pb-sync.html')
})
})
})