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

HypeLab Bid Adapter: support floors and bugfixes #11165

Merged
merged 1 commit into from
Mar 11, 2024
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
36 changes: 31 additions & 5 deletions modules/hypelabBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { generateUUID } from '../src/utils.js';
import { generateUUID, isFn, isPlainObject } from '../src/utils.js';
import { ajax } from '../src/ajax.js';

export const BIDDER_CODE = 'hypelab';
Expand All @@ -12,7 +12,7 @@ export const REPORTING_ROUTE = '';

const PREBID_VERSION = '$prebid.version$';
const PROVIDER_NAME = 'prebid';
const PROVIDER_VERSION = '0.0.1';
const PROVIDER_VERSION = '0.0.2';

const url = (route) => ENDPOINT_URL + route;

Expand All @@ -38,18 +38,24 @@ function buildRequests(validBidRequests, bidderRequest) {

const uuid = uids[0] ? uids[0] : generateTemporaryUUID();

const floor = getBidFloor(request, request.sizes || []);

const dpr = typeof window != 'undefined' ? window.devicePixelRatio : 1;

const payload = {
property_slug: request.params.property_slug,
placement_slug: request.params.placement_slug,
provider_version: PROVIDER_VERSION,
provider_name: PROVIDER_NAME,
referrer:
location:
bidderRequest.refererInfo?.page || typeof window != 'undefined'
? window.location.href
: '',
sdk_version: PREBID_VERSION,
sizes: request.sizes,
wids: [],
floor,
dpr,
uuid,
bidRequestsCount: request.bidRequestsCount,
bidderRequestsCount: request.bidderRequestsCount,
Expand Down Expand Up @@ -79,6 +85,26 @@ function generateTemporaryUUID() {
return 'tmp_' + generateUUID();
}

function getBidFloor(bid, sizes) {
if (!isFn(bid.getFloor)) {
return bid.params.bidFloor ? bid.params.bidFloor : null;
}

let floor;

let floorInfo = bid.getFloor({
currency: 'USD',
mediaType: 'banner',
size: sizes.length === 1 ? sizes[0] : '*'
});

if (isPlainObject(floorInfo) && floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) {
floor = parseFloat(floorInfo.floor);
}

return floor;
}

function interpretResponse(serverResponse, bidRequest) {
const { data } = serverResponse.body;

Expand All @@ -94,12 +120,12 @@ function interpretResponse(serverResponse, bidRequest) {
creativeId: data.creative_set_slug,
currency: data.currency,
netRevenue: true,
referrer: bidRequest.data.referrer,
referrer: bidRequest.data.location,
ttl: data.ttl,
ad: data.html,
mediaType: serverResponse.body.data.media_type,
meta: {
advertiserDomains: data.advertiserDomains || [],
advertiserDomains: data.advertiser_domains || [],
},
};

Expand Down
6 changes: 5 additions & 1 deletion test/spec/modules/hypelabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const mockBidRequest = {
placement_slug: 'test_placement',
provider_version: '0.0.1',
provider_name: 'prebid',
referrer: 'https://example.com',
location: 'https://example.com',
sdk_version: '7.51.0-pre',
sizes: [[728, 90]],
wids: [],
Expand Down Expand Up @@ -160,6 +160,9 @@ describe('hypelabBidAdapter', function () {
expect(data.bidRequestsCount).to.be.a('number');
expect(data.bidderRequestsCount).to.be.a('number');
expect(data.bidderWinsCount).to.be.a('number');
expect(data.dpr).to.be.a('number');
expect(data.location).to.be.a('string');
expect(data.floor).to.equal(null);
});

describe('should set uuid to the first id in userIdAsEids', () => {
Expand Down Expand Up @@ -211,6 +214,7 @@ describe('hypelabBidAdapter', function () {
expect(data.ad).to.be.a('string');
expect(data.mediaType).to.be.a('string');
expect(data.meta.advertiserDomains).to.be.an('array');
expect(data.meta.advertiserDomains[0]).to.be.a('string');
});

describe('should return a blank array if cpm is not set', () => {
Expand Down