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

YieldlabBidAdapter updated native asset mapping #9895

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 16 additions & 5 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,12 @@ export const spec = {

if (isNative(bidRequest, adType)) {
// there may be publishers still rely on it
const url = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}`;
bidResponse.adUrl = url;
bidResponse.adUrl = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}`;
bidResponse.mediaType = NATIVE;
const nativeImageAssetObj = find(matchedBid.native.assets, e => e.id === 2);
const nativeImageAssetObj = find(matchedBid.native.assets, asset => hasValidProperty(asset, 'img'));
const nativeImageAsset = nativeImageAssetObj ? nativeImageAssetObj.img : { url: '', w: 0, h: 0 };
const nativeTitleAsset = find(matchedBid.native.assets, e => e.id === 1);
const nativeBodyAsset = find(matchedBid.native.assets, e => e.id === 3);
const nativeTitleAsset = find(matchedBid.native.assets, asset => hasValidProperty(asset, 'title'));
const nativeBodyAsset = find(matchedBid.native.assets, asset => hasValidProperty(asset, 'data'));
bidResponse.native = {
title: nativeTitleAsset ? nativeTitleAsset.title.text : '',
body: nativeBodyAsset ? nativeBodyAsset.data.value : '',
Expand All @@ -201,6 +200,7 @@ export const spec = {
},
clickUrl: matchedBid.native.link.url,
impressionTrackers: matchedBid.native.imptrackers,
assets: matchedBid.native.assets,
};
}

Expand Down Expand Up @@ -505,4 +505,15 @@ function getBidFloor(bid, sizes) {
return undefined;
}

/**
* Checks if an object has a property with a given name and the property value is not null or undefined.
*
* @param {Object} obj - The object to check.
* @param {string} propName - The name of the property to check.
* @returns {boolean} Returns true if the object has a property with the given name and the property value is not null or undefined, otherwise false.
*/
function hasValidProperty(obj, propName) {
return obj.hasOwnProperty(propName) && obj[propName] != null;
}

registerBidder(spec);
6 changes: 6 additions & 0 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ describe('yieldlabBidAdapter', () => {
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);
const titleAsset = result[0].native.assets.find(asset => 'title' in asset);
const imageAsset = result[0].native.assets.find(asset => 'img' in asset);
const bodyAsset = result[0].native.assets.find(asset => 'data' in asset);
expect(titleAsset).to.exist.and.to.have.nested.property('id', 1)
expect(imageAsset).to.exist.and.to.have.nested.property('id', 2)
expect(bodyAsset).to.exist.and.to.have.nested.property('id', 3)
});

it('should add adUrl and default native assets when type is Native', () => {
Expand Down