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

Blue Bid Adapter : initial release #12513

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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
106 changes: 106 additions & 0 deletions modules/blueBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { getStorageManager } from '../src/storageManager.js';
import { deepSetValue } from '../src/utils.js';

const BIDDER_CODE = 'blue';
const ENDPOINT_URL = 'https://bidder-us-east-1.getblue.io/engine/?src=prebid';
const GVLID = 620; // GVLID for your bidder
const COOKIE_NAME = 'ckid'; // Cookie name for identifying users
export const storage = getStorageManager({ bidderCode: BIDDER_CODE });

const converter = ortbConverter({
context: {
netRevenue: true, // Default netRevenue setting
ttl: 100, // Default time-to-live for bid responses
},
imp,
request,
});

function request(buildRequest, imps, bidderRequest, context) {
let request = buildRequest(imps, bidderRequest, context);
deepSetValue(request, 'site.publisher.id', context.publisherId);
// eslint-disable-next-line no-console
return request;
}

function imp(buildImp, bidRequest, context) {
let imp = buildImp(bidRequest, context);
imp.bidfloor = bidRequest.params.bidFloor;
imp.bidfloorcur = bidRequest.params.currency;
imp.tagid = bidRequest.params.placementId;
return imp;
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER], // Supported ad types

// Validate bid request
isBidRequestValid: function (bid) {
return (
!!bid.params.placementId &&
!!bid.params.publisherId &&
!!bid.params.bidFloor &&
!!bid.params.currency
);
},

// Build OpenRTB requests using `ortbConverter`
buildRequests: function (validBidRequests, bidderRequest) {
const context = {
publisherId: validBidRequests.find(
(bidRequest) => bidRequest.params?.publisherId
)?.params.publisherId,
};

const ortbRequest = converter.toORTB({
bidRequests: validBidRequests,
bidderRequest,
context,
});

// Add GVLID and cookie ID to the request
ortbRequest.ext = ortbRequest.ext || {};
deepSetValue(ortbRequest, 'ext.gvlid', GVLID);

// Include user cookie if available
const ckid = storage.getCookie(COOKIE_NAME) || null;
if (ckid) {
deepSetValue(ortbRequest, 'user.ext.buyerid', ckid);
}

return {
method: 'POST',
url: ENDPOINT_URL,
data: ortbRequest,
options: {
contentType: 'application/json',
},
};
},

// Interpret OpenRTB responses using `ortbConverter`
interpretResponse: function (serverResponse, request) {
const ortbResponse = serverResponse.body;

// Parse the OpenRTB response into Prebid bid responses
const prebidResponses = converter.fromORTB({
response: ortbResponse,
request: request.data,
}).bids;

// Example: Modify bid responses if needed
prebidResponses.forEach((bid) => {
bid.meta = bid.meta || {};
bid.meta.adapterVersion = '1.0.0';
});

return prebidResponses;
},
};

registerBidder(spec);
30 changes: 30 additions & 0 deletions modules/blueBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Overview

Module Name: Blue Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]

# Description

Module that connects to Blue's demand sources.

# Test Parameters
```
var adUnits = [
{
code: 'banner-ad-div',
sizes: [[300, 250], [728, 90]],
bids: [
{
bidder: 'blue',
params: {
publisherId: "xpto",
bidFloor: 0.5,
currency: "USD",
placementId: "xpto",
}
}
]
}
];
```
67 changes: 67 additions & 0 deletions test/spec/modules/blueBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { expect } from 'chai';
import { spec, storage } from 'modules/blueBidAdapter.js';

describe('blue Adapter', function () {
describe('isBidRequestValid', function () {
const validBid = {
bidder: 'blue',
params: {
bidFloor: 0.05,
currency: 'USD',
placementId: 13144370,
publisherId: 13144370,
},
};

const invalidBid = {
bidder: 'blue',
params: {
bidFloor: 0.05,
currency: 'USD',
},
};

it('should return true for valid bid', function () {
expect(spec.isBidRequestValid(validBid)).to.equal(true);
});

it('should return false for invalid bid', function () {
expect(spec.isBidRequestValid(invalidBid)).to.equal(false);
});
});

describe('buildRequests', function () {
const bidRequest = {
bidder: 'blue',
params: {
bidFloor: 0.05,
currency: 'USD',
placementId: 13144370,
publisherId: 13144370,
},
adUnitCode: 'div-gpt-ad-1460505748561-0',
sizes: [[300, 250]],
};

const bidderRequest = {
refererInfo: {
referer: 'https://example.com',
},
};

it('should include cookie ID if available', function () {
const cookieStub = sinon.stub(storage, 'getCookie').returns('test-cookie-id');
const request = spec.buildRequests([bidRequest], bidderRequest);
const payload = request.data;

expect(payload.user.ext.buyerid).to.equal('test-cookie-id');
cookieStub.restore();
});
});

describe('Additional Tests', function () {
it('should support banner media type', function () {
expect(spec.supportedMediaTypes).to.include('banner');
});
});
});
Loading