Skip to content

Commit

Permalink
Alkimi Bid Adapter : add handling for user-sync URL and pass custom o…
Browse files Browse the repository at this point in the history
…bject with bid request (#11326)

* Alkimi bid adapter

* Alkimi bid adapter

* Alkimi bid adapter

* alkimi adapter

* onBidWon change

* sign utils

* auction ID as bid request ID

* unit test fixes

* change maintainer info

* Updated the ad unit params

* features support added

* transfer adUnitCode

* transfer adUnitCode: test

* AlkimiBidAdapter getFloor() using

* ALK-504
Multi size ad slot support

* ALK-504
Multi size ad slot support

* Support new OpenRTB parameters

* Support new oRTB2 parameters

* remove pos parameter

* Add gvl_id into Alkimi adapter

* Insert keywords into bid-request param

* Resolve AUCTION_PRICE macro on prebid-server for VAST ads

* Added support for full page auction

* Added custom user object

* userParams in request object

* Handling user-sync url, store user id and passing custom params

* Renamed the full_page_auction to fpa

* Updated the review comment

---------

Co-authored-by: Alexander <32703851+pro-nsk@users.noreply.github.com>
Co-authored-by: Alexander Bogdanov <akascheev@asteriosoft.com>
Co-authored-by: Alexander Bogdanov <abogdanov@asteriosoft.com>
Co-authored-by: motors <motors@live.ru>
Co-authored-by: mihanikw2g <92710748+mihanikw2g@users.noreply.github.com>
Co-authored-by: Nikulin Mikhail <mnikulin@asteriosoft.com>
Co-authored-by: mik <mihanikw2g@gmail.com>
  • Loading branch information
8 people authored Apr 25, 2024
1 parent fadc303 commit 51bcf81
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
56 changes: 48 additions & 8 deletions modules/alkimiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {deepAccess, deepClone, getDNT, generateUUID, replaceAuctionPrice} from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import {getStorageManager} from '../src/storageManager.js';
import {VIDEO, BANNER} from '../src/mediaTypes.js';
import {config} from '../src/config.js';

const BIDDER_CODE = 'alkimi';
const GVLID = 1169;
const USER_ID_KEY = 'alkimiUserID';
export const ENDPOINT = 'https://exchange.alkimi-onboarding.com/bid?prebid=true';
export const storage = getStorageManager({bidderCode: BIDDER_CODE});

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -43,11 +46,16 @@ export const spec = {
bidIds.push(bidRequest.bidId)
})

const ortb2 = bidderRequest.ortb2
const site = ortb2?.site

const id = getUserId()
const alkimiConfig = config.getConfig('alkimi')
const fullPageAuction = bidderRequest.ortb2?.source?.ext?.full_page_auction
const source = fullPageAuction != undefined ? { ext: { full_page_auction: fullPageAuction } } : undefined
const fpa = ortb2?.source?.ext?.fpa
const source = fpa != undefined ? { ext: { fpa } } : undefined
const walletID = alkimiConfig && alkimiConfig.walletID
const user = walletID != undefined ? { ext: { walletID: walletID } } : undefined
const userParams = alkimiConfig && alkimiConfig.userParams
const user = (walletID != undefined || userParams != undefined || id != undefined) ? { id, ext: { walletID, userParams } } : undefined

let payload = {
requestId: generateUUID(),
Expand All @@ -66,11 +74,14 @@ export const spec = {
source,
user,
site: {
keywords: bidderRequest.ortb2?.site?.keywords
keywords: site?.keywords,
sectioncat: site?.sectioncat,
pagecat: site?.pagecat,
cat: site?.cat
},
at: bidderRequest.ortb2?.at,
bcat: bidderRequest.ortb2?.bcat,
wseat: bidderRequest.ortb2?.wseat
at: ortb2?.at,
bcat: ortb2?.bcat,
wseat: ortb2?.wseat
}
}

Expand Down Expand Up @@ -111,7 +122,7 @@ export const spec = {
}

const {prebidResponse} = serverBody;
if (!prebidResponse || typeof prebidResponse !== 'object') {
if (!Array.isArray(prebidResponse)) {
return [];
}

Expand Down Expand Up @@ -141,6 +152,24 @@ export const spec = {
return true;
}
return false;
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
if (syncOptions.iframeEnabled && serverResponses.length > 0) {
const serverBody = serverResponses[0].body;
if (!serverBody || typeof serverBody !== 'object') return [];

const { iframeList } = serverBody;
if (!Array.isArray(iframeList)) return [];

const urls = [];
iframeList.forEach(url => {
urls.push({type: 'iframe', url});
})

return urls;
}
return [];
}
}

Expand Down Expand Up @@ -175,4 +204,15 @@ const getFormatType = bidRequest => {
return formats
}

const getUserId = () => {
if (storage.localStorageIsEnabled()) {
let userId = storage.getDataFromLocalStorage(USER_ID_KEY)
if (!userId) {
userId = generateUUID()
storage.setDataInLocalStorage(USER_ID_KEY, userId)
}
return userId
}
}

registerBidder(spec);
16 changes: 11 additions & 5 deletions test/spec/modules/alkimiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ describe('alkimiBidAdapter', function () {
})

it('should return false when required params are not passed', function () {
let bid = Object.assign({}, REQUEST)
let bid = JSON.parse(JSON.stringify(REQUEST))
delete bid.params.token
expect(spec.isBidRequestValid(bid)).to.equal(false)

bid = Object.assign({}, REQUEST)
bid = JSON.parse(JSON.stringify(REQUEST))
delete bid.params
expect(spec.isBidRequestValid(bid)).to.equal(false)
})
Expand All @@ -115,29 +115,35 @@ describe('alkimiBidAdapter', function () {
uspConsent: 'uspConsent',
ortb2: {
site: {
keywords: 'test1, test2'
keywords: 'test1, test2',
cat: ['IAB2'],
pagecat: ['IAB3'],
sectioncat: ['IAB4']
},
at: 2,
bcat: ['BSW1', 'BSW2'],
wseat: ['16', '165']
}
}
const bidderRequest = spec.buildRequests(bidRequests, requestData)

it('should return a properly formatted request with eids defined', function () {
const bidderRequest = spec.buildRequests(bidRequests, requestData)
expect(bidderRequest.data.eids).to.deep.equal(REQUEST.userIdAsEids)
})

it('should return a properly formatted request with gdpr defined', function () {
const bidderRequest = spec.buildRequests(bidRequests, requestData)
expect(bidderRequest.data.gdprConsent.consentRequired).to.equal(true)
expect(bidderRequest.data.gdprConsent.consentString).to.equal('test-consent')
})

it('should return a properly formatted request with uspConsent defined', function () {
const bidderRequest = spec.buildRequests(bidRequests, requestData)
expect(bidderRequest.data.uspConsent).to.equal('uspConsent')
})

it('sends bid request to ENDPOINT via POST', function () {
const bidderRequest = spec.buildRequests(bidRequests, requestData)
expect(bidderRequest.method).to.equal('POST')
expect(bidderRequest.data.requestId).to.not.equal(undefined)
expect(bidderRequest.data.referer).to.equal('http://test.com/path.html')
Expand All @@ -146,7 +152,7 @@ describe('alkimiBidAdapter', function () {
expect(bidderRequest.data.signRequest.randomUUID).to.equal(undefined)
expect(bidderRequest.data.bidIds).to.deep.contains('456')
expect(bidderRequest.data.signature).to.equal(undefined)
expect(bidderRequest.data.ortb2).to.deep.contains({ at: 2, wseat: ['16', '165'], bcat: ['BSW1', 'BSW2'], site: { keywords: 'test1, test2' }, })
expect(bidderRequest.data.ortb2).to.deep.contains({ at: 2, wseat: ['16', '165'], bcat: ['BSW1', 'BSW2'], site: { keywords: 'test1, test2', cat: ['IAB2'], pagecat: ['IAB3'], sectioncat: ['IAB4'] } })
expect(bidderRequest.options.customHeaders).to.deep.equal({ 'Rtb-Direct': true })
expect(bidderRequest.options.contentType).to.equal('application/json')
expect(bidderRequest.url).to.equal(ENDPOINT)
Expand Down

0 comments on commit 51bcf81

Please sign in to comment.