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

YL-3989: Accept NATIVE yieldprobe response #2

Merged
merged 4 commits into from
Oct 21, 2021
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
35 changes: 33 additions & 2 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as utils from '../src/utils.js'
import { registerBidder } from '../src/adapters/bidderFactory.js'
import find from 'core-js-pure/features/array/find.js'
import { VIDEO, BANNER } from '../src/mediaTypes.js'
import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside this I will need to create another small PR in https://github.com/prebid/prebid.github.io/blob/1174621dbc456ba79a44d4d2de4055fcab547f33/dev-docs/bidders/yieldlab.md#L6

media_types: video, banner, native

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you already create the pull request? Can you add a link to the other pull request then?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. I thought to create two PRs in parallel against Prebid.js github. After we merge this PR to our repository I can create them together

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have a fork of the documentation repo as well and create pull requests in parallel in both forks. This would align best with our current workflow.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brushmate , I just create a PR: yieldlab/prebid.github.io#4

import { Renderer } from '../src/Renderer.js'

const ENDPOINT = 'https://ad.yieldlab.net'
Expand All @@ -14,7 +14,7 @@ const GVLID = 70
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [VIDEO, BANNER],
supportedMediaTypes: [VIDEO, BANNER, NATIVE],

isBidRequestValid: function (bid) {
if (bid && bid.params && bid.params.adslotId && bid.params.supplyId) {
Expand Down Expand Up @@ -142,6 +142,27 @@ export const spec = {
}
}

if (isNative(bidRequest, adType)) {
const url = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}`
alex-ylb marked this conversation as resolved.
Show resolved Hide resolved
bidResponse.adUrl = url
bidResponse.mediaType = NATIVE
const nativeImageAssetObj = matchedBid.native.assets.find(e => e.id === 2)
const nativeImageAsset = nativeImageAssetObj ? nativeImageAssetObj.img : {url: '', w: 0, h: 0};
const nativeTitleAsset = matchedBid.native.assets.find(e => e.id === 1)
const nativeBodyAsset = matchedBid.native.assets.find(e => e.id === 3)
bidResponse.native = {
title: nativeTitleAsset ? nativeTitleAsset.title.text : '',
body: nativeBodyAsset ? nativeBodyAsset.data.value : '',
image: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support image assets only? What about video assets?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Mareike we only support image assets.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thought, I did not spot in code where we return video native assets.

url: nativeImageAsset.url,
width: nativeImageAsset.w,
height: nativeImageAsset.h,
},
clickUrl: matchedBid.native.link.url,
impressionTrackers: matchedBid.native.imptrackers,
};
}

bidResponses.push(bidResponse)
}
})
Expand All @@ -159,6 +180,16 @@ function isVideo (format, adtype) {
return utils.deepAccess(format, 'mediaTypes.video') && adtype.toLowerCase() === 'video'
}

/**
* Is this a native format?
* @param {Object} format
* @param {String} adtype
* @returns {Boolean}
*/
function isNative(format, adtype) {
return utils.deepAccess(format, 'mediaTypes.native') && adtype.toLowerCase() === 'native'
}

/**
* Is this an outstream context?
* @param {Object} format
Expand Down
13 changes: 13 additions & 0 deletions modules/yieldlabBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ Module that connects to Yieldlab's demand sources
supplyId: "1381604"
}
}]
},
{
code: "native",
mediaTypes: {
native: { }
},
bids: [{
bidder: "yieldlab",
params: {
adslotId: "5220339",
supplyId: "1381604"
}
}]
}
];
```
81 changes: 81 additions & 0 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const VIDEO_REQUEST = Object.assign({}, REQUEST, {
}
})

const NATIVE_REQUEST = Object.assign({}, REQUEST, {
'mediaTypes': {
'native': { }
}
})

const RESPONSE = {
advertiser: 'yieldlab',
curl: 'https://www.yieldlab.de',
Expand All @@ -68,6 +74,42 @@ const RESPONSE = {
adtype: 'BANNER'
}

const NATIVE_RESPONSE = Object.assign({}, RESPONSE, {
'adtype': 'NATIVE',
'native': {
'link': {
'url': 'https://www.yieldlab.de'
},
'assets': [
{
'id': 1,
'title': {
'text': 'This is a great headline'
}
},
{
'id': 2,
'img': {
'url': 'https://localhost:8080/yl-logo100x100.jpg',
'w': 100,
'h': 100
}
},
{
'id': 3,
'data': {
'value': 'Native body value'
}
}
],
'imptrackers': [
'http://localhost:8080/ve?d=ODE9ZSY2MTI1MjAzNjMzMzYxPXN0JjA0NWUwZDk0NTY5Yi05M2FiLWUwZTQtOWFjNy1hYWY0MzFiZj1kaXQmMj12',
'http://localhost:8080/md/1111/9efa4e76-2030-4f04-bb9f-322541f8d611?mdata=false&pvid=false&ids=x:1',
'http://localhost:8080/imp?s=13216&d=2171514&a=12548955&ts=1633363025216&tid=fb134faa-7ca9-4e0e-ba39-b96549d0e540&l=0'
]
}
})

const VIDEO_RESPONSE = Object.assign({}, RESPONSE, {
'adtype': 'VIDEO'
})
Expand Down Expand Up @@ -238,6 +280,45 @@ describe('yieldlabBidAdapter', function () {
expect(result[0].vastUrl).to.include('&id=abc')
})

it('should add adUrl and native assets when type is Native', function () {
const result = spec.interpretResponse({body: [NATIVE_RESPONSE]}, {validBidRequests: [NATIVE_REQUEST], queryParams: REQPARAMS})

expect(result[0].requestId).to.equal('2d925f27f5079f')
expect(result[0].cpm).to.equal(0.01)
expect(result[0].mediaType).to.equal('native')
expect(result[0].adUrl).to.include('https://ad.yieldlab.net/d/1111/2222/?ts=')
expect(result[0].native.title).to.equal('This is a great headline')
expect(result[0].native.body).to.equal('Native body value')
expect(result[0].native.image.url).to.equal('https://localhost:8080/yl-logo100x100.jpg')
expect(result[0].native.image.width).to.equal(100)
expect(result[0].native.image.height).to.equal(100)
expect(result[0].native.clickUrl).to.equal('https://www.yieldlab.de')
expect(result[0].native.impressionTrackers.length).to.equal(3)
})

it('should add adUrl and default native assets when type is Native', function () {
const NATIVE_RESPONSE_2 = Object.assign({}, NATIVE_RESPONSE, {
'native': {
'link': {
'url': 'https://www.yieldlab.de'
},
'assets': [],
'imptrackers': []
}
})
const result = spec.interpretResponse({body: [NATIVE_RESPONSE_2]}, {validBidRequests: [NATIVE_REQUEST], queryParams: REQPARAMS})

expect(result[0].requestId).to.equal('2d925f27f5079f')
expect(result[0].cpm).to.equal(0.01)
expect(result[0].mediaType).to.equal('native')
expect(result[0].adUrl).to.include('https://ad.yieldlab.net/d/1111/2222/?ts=')
expect(result[0].native.title).to.equal('')
expect(result[0].native.body).to.equal('')
expect(result[0].native.image.url).to.equal('')
expect(result[0].native.image.width).to.equal(0)
expect(result[0].native.image.height).to.equal(0)
})

it('should append gdpr parameters to vastUrl', function () {
const result = spec.interpretResponse({body: [VIDEO_RESPONSE]}, {validBidRequests: [VIDEO_REQUEST], queryParams: REQPARAMS_GDPR})

Expand Down