Skip to content

Commit

Permalink
BLIINK Bid Adapter : Add new format, outstream, banner (#7529)
Browse files Browse the repository at this point in the history
* feat(adapter): Add bliink bid adapter

* feat(tests): Add tests unit file

* refactor: code optimisation and fix cookie sync

* fix(bliinkAdapter): get meta value

* update: Update documentation bliinkBidAdapter.md

* update: Fix sizes in buildBid function

* fix: step build

* Revert "fix: step build"

This reverts commit 9a746f5a175190ddd209f6f51bd71946a5575fe7.

* fix: step build

* fix: step build

* fix: step build

* fix: tests units

* fix: js doc

* fix: tests units

* fix: Fix build Circle CI

* fix: Fix build Circle CI

* fix: Fix build Circle CI

* fix: Fix build Circle CI

* fix: Fix build Circle CI

* fix: Fix build Circle CI

* fix: Fix build Circle CI

Co-authored-by: Jonathan <jonathan@bliink.io>
Co-authored-by: samuel.kerboeuf <samuel@bliink.io>
  • Loading branch information
3 people authored Oct 13, 2021
1 parent 60672a5 commit cf2395e
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 74 deletions.
90 changes: 58 additions & 32 deletions modules/bliinkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ export const META_KEYWORDS = 'keywords'
export const META_DESCRIPTION = 'description'

const VIDEO = 'video'
const NATIVE = 'native'
const BANNER = 'banner'

const supportedMediaTypes = [BANNER, VIDEO, NATIVE]
const supportedMediaTypes = [BANNER, VIDEO]
const aliasBidderCode = ['bk']

export function getMetaList(name) {
Expand Down Expand Up @@ -90,7 +89,11 @@ export const parseXML = (content) => {
if (typeof content !== 'string' || content.length === 0) return null

const parser = new DOMParser()
const xml = parser.parseFromString(content, 'text/xml')
let xml;

try {
xml = parser.parseFromString(content, 'text/xml')
} catch (e) {}

if (xml &&
xml.getElementsByTagName('VAST')[0] &&
Expand All @@ -104,19 +107,19 @@ export const parseXML = (content) => {
/**
* @param bidRequest
* @param bliinkCreative
* @return {{cpm, netRevenue: boolean, ad: string, requestId, width: number, currency: string, mediaType: string, vastXml, ttl: number, height: number}|null}
* @return {{cpm, netRevenue: boolean, requestId, width: (*|number), currency, ttl: number, creativeId, height: (*|number)} & {mediaType: string, vastXml}}
*/
export const buildBid = (bidRequest, bliinkCreative) => {
if (!bidRequest && !bliinkCreative) return null

const body = {
requestId: bidRequest.bidId,
currency: bliinkCreative.currency,
cpm: bliinkCreative.price,
creativeId: bliinkCreative.creativeId,
currency: 'EUR',
width: (bidRequest.sizes && bidRequest.sizes[0][0]) || 1,
height: (bidRequest.sizes && bidRequest.sizes[0][1]) || 1,
netRevenue: false,
width: 1,
height: 1,
ttl: 3600,
}

Expand All @@ -131,14 +134,20 @@ export const buildBid = (bidRequest, bliinkCreative) => {

delete bidRequest['bids']

return Object.assign(body, {
currency: bliinkCreative.currency,
width: 1,
height: 1,
mediaType: VIDEO,
ad: '<html lang="en"></html>',
vastXml: bliinkCreative.content,
})
switch (bliinkCreative.media_type) {
case VIDEO:
return Object.assign(body, {
mediaType: VIDEO,
vastXml: bliinkCreative.content,
})
case BANNER:
return Object.assign(body, {
mediaType: BANNER,
ad: (bliinkCreative && bliinkCreative.content && bliinkCreative.content.creative && bliinkCreative.content.creative.adm) || '',
})
default:
break;
}
}

/**
Expand Down Expand Up @@ -209,7 +218,7 @@ export const buildRequests = (_, bidderRequest) => {
* @return
*/
const interpretResponse = (serverResponse, request) => {
if ((serverResponse && serverResponse.mode === 'no-ad') && (!request.params)) {
if ((serverResponse && serverResponse.mode === 'no-ad')) {
return []
}

Expand All @@ -218,23 +227,40 @@ const interpretResponse = (serverResponse, request) => {

const xml = parseXML(body)

if (xml) {
const price = xml.getElementsByTagName('Price') && xml.getElementsByTagName('Price')[0]
const currency = xml.getElementsByTagName('Currency') && xml.getElementsByTagName('Currency')[0]
const creativeId = xml.getElementsByTagName('CreativeId') && xml.getElementsByTagName('CreativeId')[0]

const creative = {
content: body,
price: (price && price.textContent) || 0,
currency: (currency && currency.textContent) || 'EUR',
creativeId: creativeId || 0,
media_type: 'video',
}

return buildBid(serverBody.bids[0], creative);
let creative;

switch (serverBody.bids[0].params.placement) {
case xml && VIDEO:
const price = xml.getElementsByTagName('Price') && xml.getElementsByTagName('Price')[0]
const currency = xml.getElementsByTagName('Currency') && xml.getElementsByTagName('Currency')[0]
const creativeId = xml.getElementsByTagName('CreativeId') && xml.getElementsByTagName('CreativeId')[0]

creative = {
content: body,
price: (price && price.textContent) || 0,
currency: (currency && currency.textContent) || 'EUR',
creativeId: creativeId || 0,
media_type: 'video',
}

return buildBid(serverBody.bids[0], creative)
case BANNER:
if (body) {
creative = {
content: body,
price: body.price,
currency: body.currency,
creativeId: 0,
media_type: 'banner',
}

return buildBid(serverBody.bids[0], creative)
}

break
default:
break
}

return []
}

/**
Expand Down
35 changes: 29 additions & 6 deletions modules/bliinkBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const adUnits = [
bidder: 'bliink',
params: {
placement: 'banner',
tagId: '14f30eca-85d2-11e8-9eed-0242ac120007'
tagId: '41'
}
}
]
Expand All @@ -50,11 +50,34 @@ const adUnits = [
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 480],
mimes: ['video/mp4'],
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
playbackmethod: [2],
skip: 1
playerSize: [[640,480]],
}
},
bids: [
{
bidder: 'bliink',
params: {
tagId: '41',
placement: 'video',
}
}
]
}
]
```

## Sample outstream Video Ad Unit

```js
const adUnits = [
{
code: '/19968336/prebid_cache_video_adunit',
sizes: [[640,480]],
mediaType: 'video',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [[640,480]],
}
},
bids: [
Expand Down
Loading

0 comments on commit cf2395e

Please sign in to comment.