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

RoundhouseAds Bid Adapter: Add new bidder adapter with tests #12400

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ typings/

# MacOS system files
.DS_Store
Prebid.js/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this change and your change to the creative

2 changes: 1 addition & 1 deletion integrationExamples/gpt/x-domain/creative.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// creative will be rendered, e.g. GAM delivering a SafeFrame

// this code is autogenerated, also available in 'build/creative/creative.js'
<script>!function(){"use strict";const e="Prebid Event",n=(()=>{const e={frameBorder:0,scrolling:"no",marginHeight:0,marginWidth:0,topMargin:0,leftMargin:0,allowTransparency:"true"};return(n,t)=>{const r=n.createElement("iframe");return Object.entries(Object.assign({},t,e)).forEach((([e,n])=>r.setAttribute(e,n))),r}})();function t(e){return!!e.frames.__pb_locator__}window.pbRender=function(r){let o=r.parent;try{for(;o!==r.top&&!t(o);)o=o.parent;t(o)||(o=r.parent)}catch(e){}return function({adId:t,pubUrl:s,clickUrl:i}){const c=new URL(s,window.location).origin;function a(e,n,r){const s=new MessageChannel;s.port1.onmessage=u(r),o.postMessage(JSON.stringify(Object.assign({message:e,adId:t},n)),c,[s.port2])}function d(n){a(e,{event:"adRenderFailed",info:{reason:n?.reason||"exception",message:n?.message}}),n?.stack&&console.error(n)}function u(e){return function(){try{return e.apply(this,arguments)}catch(e){d(e)}}}a("Prebid Request",{options:{clickUrl:i}},(function(o){let s;try{s=JSON.parse(o.data)}catch(e){return}if("Prebid Response"===s.message&&s.adId===t){const t=n(r.document,{width:0,height:0,style:"display: none",srcdoc:`<script>${s.renderer}<\/script>`});t.onload=u((function(){const o=t.contentWindow;o.Promise.resolve(o.render(s,{sendMessage:a,mkFrame:n},r)).then((()=>a(e,{event:"adRenderSucceeded"})),d)})),r.document.body.appendChild(t)}}))}}(window)}();</script>
<script>(()=>{"use strict";const e="Prebid Event",n=(()=>{const e={frameBorder:0,scrolling:"no",marginHeight:0,marginWidth:0,topMargin:0,leftMargin:0,allowTransparency:"true"};return(n,t)=>{const r=n.createElement("iframe");return Object.entries(Object.assign({},t,e)).forEach((([e,n])=>r.setAttribute(e,n))),r}})();function t(e){return!!e.frames.__pb_locator__}window.pbRender=function(r){let o=r.parent;try{for(;o!==r.top&&!t(o);)o=o.parent;t(o)||(o=r.parent)}catch(e){}return function({adId:t,pubUrl:s,clickUrl:i}){const a=new URL(s,window.location).origin;function c(e,n,r){const s=new MessageChannel;s.port1.onmessage=l(r),o.postMessage(JSON.stringify(Object.assign({message:e,adId:t},n)),a,[s.port2])}function d(n){c(e,{event:"adRenderFailed",info:{reason:n?.reason||"exception",message:n?.message}}),n?.stack&&console.error(n)}function l(e){return function(){try{return e.apply(this,arguments)}catch(e){d(e)}}}c("Prebid Request",{options:{clickUrl:i}},(function(o){let s;try{s=JSON.parse(o.data)}catch(e){return}if("Prebid Response"===s.message&&s.adId===t){const t=n(r.document,{width:0,height:0,style:"display: none",srcdoc:`<script>${s.renderer}<\/script>`});t.onload=l((function(){const o=t.contentWindow;o.Promise.resolve(o.render(s,{sendMessage:c,mkFrame:n},r)).then((()=>c(e,{event:"adRenderSucceeded"})),d)})),r.document.body.appendChild(t)}}))}}(window)})();</script>

<script>
pbRender({
Expand Down
127 changes: 127 additions & 0 deletions modules/roundhouseadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';

/**
* RoundhouseAds adapter configurations
*/

const BIDDER_CODE = 'roundhouseads';
const BIDADAPTERVERSION = 'RHA-PREBID-2024.10.01';
const USER_SYNC_ENDPOINT = 'https://roundhouseads.com/sync';

const isLocalhost = typeof window !== 'undefined' && window.location.hostname === 'localhost';
const ENDPOINT_URL = isLocalhost
? 'http://localhost:3000/bid'
: 'https://Rhapbjsv3-env.eba-aqkfquti.us-east-1.elasticbeanstalk.com/bid';

/**
* Validates a bid request for required parameters.
* @param {Object} bid - The bid object from Prebid.
* @returns {boolean} - True if the bid has required parameters, false otherwise.
*/
function isBidRequestValid(bid) {
return !!(bid.params && bid.params.publisherId && typeof bid.params.publisherId === 'string');
}

/**
* Constructs the bid request to send to the endpoint.
* @param {Array} validBidRequests - Validated bid requests.
* @param {Object} bidderRequest - Prebid's bidder request.
* @returns {Array} - Array of request objects.
*/
function buildRequests(validBidRequests, bidderRequest) {
return validBidRequests.map(bid => {
const data = {
id: bid.bidId,
publisherId: bid.params.publisherId,
placementId: bid.params.placementId || '',
currency: bid.params.currency || 'USD',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please support the openrtb location

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not resolved

referer: bidderRequest.refererInfo?.page,
sizes: bid.mediaTypes?.banner?.sizes,
video: bid.mediaTypes?.video || null,
native: bid.mediaTypes?.native || null,
ext: {
ver: BIDADAPTERVERSION,
}
};

return {
method: 'POST',
url: ENDPOINT_URL,
data,
};
});
}

/**
* Interprets the server response for Prebid.
* @param {Object} serverResponse - Server response from the bidder.
* @param {Object} request - The original request.
* @returns {Array} - Array of bid responses.
*/
function interpretResponse(serverResponse, request) {
juliansalinas121 marked this conversation as resolved.
Show resolved Hide resolved
const bidResponses = [];
const response = serverResponse.body;

if (response && response.bids && Array.isArray(response.bids)) {
response.bids.forEach(bid => {
const bidResponse = {
requestId: bid.requestId,
cpm: bid.cpm || 0,
width: bid.width || 300,
height: bid.height || 250,
creativeId: bid.creativeId || 'defaultCreative',
currency: bid.currency || 'USD',
netRevenue: true,
ttl: bid.ttl || 360,
ad: bid.ad || '<div>Test Ad</div>',
mediaType: bid.mediaType || BANNER,
};

if (bid.mediaType === VIDEO) {
bidResponse.vastUrl = bid.vastUrl;
} else if (bid.mediaType === NATIVE) {
bidResponse.native = bid.native;
}

bidResponses.push(bidResponse);
});
}

return bidResponses;
}

/**
* Provides user sync URL based on available sync options.
* @param {Object} syncOptions - Sync options.
* @param {Array} serverResponses - Server responses.
* @param {Object} gdprConsent - GDPR consent data.
* @param {string} uspConsent - USP consent data.
* @returns {Array} - Array of user syncs.
*/
function getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
const gdprParams = gdprConsent
? `&gdpr=${gdprConsent.gdprApplies ? 1 : 0}&gdpr_consent=${encodeURIComponent(gdprConsent.consentString)}`
: '';
const uspParam = uspConsent ? `&us_privacy=${encodeURIComponent(uspConsent)}` : '';

if (syncOptions.iframeEnabled) {
syncs.push({ type: 'iframe', url: `${USER_SYNC_ENDPOINT}?${gdprParams}${uspParam}` });
} else if (syncOptions.pixelEnabled) {
syncs.push({ type: 'image', url: `${USER_SYNC_ENDPOINT}?${gdprParams}${uspParam}` });
}

return syncs;
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
isBidRequestValid,
buildRequests,
interpretResponse,
getUserSyncs,
};

registerBidder(spec);
153 changes: 153 additions & 0 deletions modules/roundhouseadsBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# RoundhouseAds Bidder Adapter

## Overview

- **Module Name**: RoundhouseAds Bidder Adapter
- **Module Type**: Bidder Adapter
- **Maintainer**: info@roundhouseads.com

# Description

Module that connects to RoundhouseAds' demand sources to fetch bids.

The RoundhouseAds bid adapter supports Banner, Video, and Native ad formats.

# Test Parameters

```js
var adUnits = [
// Banner adUnit with only required parameters
{
code: 'test-div-banner-minimal',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: 'roundhouseads',
params: {
publisherId: 'your-publisher-id'
}
}
]
},
// Banner adUnit with all optional parameters provided
{
code: 'test-div-banner-full',
mediaTypes: {
banner: {
sizes: [[728, 90]]
}
},
bids: [
{
bidder: 'roundhouseads',
params: {
publisherId: 'your-publisher-id',
placementId: 'your-placement-id',
bidfloor: 0.50,
banner: {
pos: 1
}
}
}
]
},
// Native adUnit with only required parameters
{
code: 'test-div-native-minimal',
mediaTypes: {
native: {
title: { required: true, len: 80 },
image: { required: true, sizes: [150, 150] },
sponsoredBy: { required: true }
}
},
bids: [
{
bidder: 'roundhouseads',
params: {
publisherId: 'your-publisher-id'
}
}
]
},
// Native adUnit with all optional parameters provided
{
code: 'test-div-native-full',
mediaTypes: {
native: {
title: { required: true, len: 80 },
body: { required: true, len: 200 },
image: { required: true, sizes: [300, 250] },
icon: { required: false, sizes: [50, 50] },
sponsoredBy: { required: true },
clickUrl: { required: true }
}
},
bids: [
{
bidder: 'roundhouseads',
params: {
publisherId: 'your-publisher-id',
placementId: 'your-placement-id',
native: {
language: 'en'
}
}
}
]
},
// Video adUnit with only required parameters
{
code: 'test-div-video-minimal',
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 480],
mimes: ['video/mp4'],
protocols: [2, 3, 5, 6]
}
},
bids: [
{
bidder: 'roundhouseads',
params: {
publisherId: 'your-publisher-id'
}
}
]
},
// Video adUnit with all optional parameters provided
{
code: 'test-div-video-full',
mediaTypes: {
video: {
minduration: 1,
maxduration: 60,
playerSize: [640, 480],
api: [1, 2],
mimes: ['video/mp4'],
protocols: [2, 3, 5, 6],
skip: 1,
skipmin: 5,
skipafter: 15
}
},
bids: [
{
bidder: 'roundhouseads',
params: {
publisherId: 'your-publisher-id',
placementId: 'your-placement-id',
bidfloor: 0.75,
video: {
language: 'en'
}
}
}
]
}
];
80 changes: 80 additions & 0 deletions test/spec/modules/roundhouseadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { expect } from 'chai';
import { spec } from 'modules/roundhouseadsBidAdapter.js';

describe('RoundhouseAdsAdapter', function () {
function makeBid() {
return {
bidder: 'roundhouseads',
params: {
placementId: 'testPlacement',
publisherId: '123456',
},
mediaTypes: {
banner: { sizes: [[300, 250], [728, 90]] },
},
adUnitCode: 'adunit-code',
bidId: 'bid123',
bidderRequestId: 'request123',
auctionId: 'auction123',
};
}

describe('isBidRequestValid', function () {
it('should return true when required params are found', function () {
const bid = makeBid();
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when publisherId is missing', function () {
const bid = makeBid();
delete bid.params.publisherId;
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequests', function () {
it('should build a request with correct data', function () {
const bidRequests = [makeBid()];
const bidderRequest = { refererInfo: { page: 'http://example.com' } };
const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request[0].url).to.equal('http://localhost:3000/bid');
expect(request[0].data.publisherId).to.equal('123456');
expect(request[0].data.placementId).to.equal('testPlacement');
});
});

describe('interpretResponse', function () {
it('should interpret the server response correctly', function () {
const serverResponse = {
body: {
bids: [
{
requestId: 'bid123',
cpm: 1.0,
width: 300,
height: 250,
creativeId: 'creative123',
currency: 'USD',
ttl: 360,
ad: '<div>Test Ad</div>',
},
],
},
};
const request = { data: { id: 'bid123' } };
const result = spec.interpretResponse(serverResponse, request);
expect(result[0].requestId).to.equal('bid123');
expect(result[0].cpm).to.equal(1.0);
expect(result[0].ad).to.equal('<div>Test Ad</div>');
});
});

describe('getUserSyncs', function () {
it('should return user sync iframe if iframeEnabled', function () {
const syncOptions = { iframeEnabled: true };
const result = spec.getUserSyncs(syncOptions);
expect(result[0].type).to.equal('iframe');
expect(result[0].url).to.contain('https://roundhouseads.com/sync');
});
});
});