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

Sparteo Bid Adapter: initial release #10582

Merged
merged 5 commits into from
Oct 27, 2023
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
126 changes: 126 additions & 0 deletions modules/sparteoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { deepAccess, deepSetValue, logError, parseSizesInput, triggerPixel } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import {ortbConverter} from '../libraries/ortbConverter/converter.js'

const BIDDER_CODE = 'sparteo';
const GVLID = 1028;
const TTL = 60;
const HTTP_METHOD = 'POST';
const REQUEST_URL = 'https://bid.sparteo.com/auction';

const converter = ortbConverter({
context: {
// `netRevenue` and `ttl` are required properties of bid responses - provide a default for them
netRevenue: true, // or false if your adapter should set bidResponse.netRevenue = false
ttl: TTL // default bidResponse.ttl (when not specified in ORTB response.seatbid[].bid[].exp)
},
request(buildRequest, imps, bidderRequest, context) {
const request = buildRequest(imps, bidderRequest, context);

if (bidderRequest.bids[0].params.networkId) {
deepSetValue(request, 'site.publisher.ext.params.networkId', bidderRequest.bids[0].params.networkId);
}

if (bidderRequest.bids[0].params.publisherId) {
deepSetValue(request, 'site.publisher.ext.params.publisherId', bidderRequest.bids[0].params.publisherId);
}

return request;
},
bidResponse(buildBidResponse, bid, context) {
context.mediaType = deepAccess(bid, 'ext.prebid.type');

return buildBidResponse(bid, context)
}
});

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER, VIDEO],

/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
let bannerParams = deepAccess(bid, 'mediaTypes.banner');
let videoParams = deepAccess(bid, 'mediaTypes.video');

if (!bid.params) {
logError('The bid params are missing');
return false;
}

if (!bid.params.networkId && !bid.params.publisherId) {
logError('The networkId or publisherId is required');
return false;
}

if (!bannerParams && !videoParams) {
logError('The placement must be of banner or video type');
return false;
}

/**
* BANNER checks
*/

if (bannerParams) {
let sizes = bannerParams.sizes;

if (!sizes || parseSizesInput(sizes).length == 0) {
logError('mediaTypes.banner.sizes must be set for banner placement at the right format.');
return false;
}
}

/**
* VIDEO checks
*/

if (videoParams) {
if (parseSizesInput(videoParams.playerSize).length == 0) {
logError('mediaTypes.video.playerSize must be set for video placement at the right format.');
return false;
}
}

return true;
},

buildRequests: function(bidRequests, bidderRequest) {
const payload = converter.toORTB({bidRequests, bidderRequest})

return {
method: HTTP_METHOD,
url: bidRequests[0].params.endpoint ? bidRequests[0].params.endpoint : REQUEST_URL,
data: payload
};
},

interpretResponse: function(serverResponse, requests) {
const bids = converter.fromORTB({response: serverResponse.body, request: requests.data}).bids;

return bids;
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {},

onTimeout: function(timeoutData) {},

onBidWon: function(bid) {
if (bid && bid.nurl && bid.nurl.length > 0) {
bid.nurl.forEach(function(winUrl) {
triggerPixel(winUrl, null);
});
}
},

onSetTargeting: function(bid) {}
};

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

```
Module Name: Sparteo Bidder Adapter
Module Type: Bidder Adapter
Maintainer: prebid@sparteo.com
```

# Description

Module that connects to Sparteo's demand sources

# Test Parameters
```
var adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [
[1, 1]
]
}
},
bids: [
{
bidder: 'sparteo',
params: {
networkId: '1234567a-eb1b-1fae-1d23-e1fbaef234cf'
}
}
]
}
];
```
Loading