Skip to content

Commit

Permalink
Talkads Bid Adapter: add new bid adapter (prebid#7546)
Browse files Browse the repository at this point in the history
* Add files via upload

* Add files via upload

* Params update

* Params update

* Add test feature with fake test bid
  • Loading branch information
natexo-technical-team authored and Chris Pabst committed Jan 10, 2022
1 parent ade857f commit 7b16442
Show file tree
Hide file tree
Showing 3 changed files with 420 additions and 0 deletions.
129 changes: 129 additions & 0 deletions modules/talkadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { NATIVE, BANNER } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import {ajax} from '../src/ajax.js';

const CURRENCY = 'EUR';
const BIDDER_CODE = 'talkads';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [ NATIVE, BANNER ],
params: null,

/**
* Determines whether or not the given bid request is valid.
*
* @param poBid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: (poBid) => {
utils.logInfo('isBidRequestValid : ', poBid);
if (poBid.params === undefined) {
utils.logError('VALIDATION FAILED : the parameters must be defined');
return false;
}
if (poBid.params.tag_id === undefined) {
utils.logError('VALIDATION FAILED : the parameter "tag_id" must be defined');
return false;
}
if (poBid.params.bidder_url === undefined) {
utils.logError('VALIDATION FAILED : the parameter "bidder_url" must be defined');
return false;
}
this.params = poBid.params;
return !!(poBid.nativeParams || poBid.sizes);
}, // isBidRequestValid

/**
* Make a server request from the list of BidRequests.
*
* @param paValidBidRequests An array of bids
* @param poBidderRequest
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: (paValidBidRequests, poBidderRequest) => {
utils.logInfo('buildRequests : ', paValidBidRequests, poBidderRequest);
const laBids = paValidBidRequests.map((poBid, piId) => {
const loOne = { id: piId, ad_unit: poBid.adUnitCode, bid_id: poBid.bidId, type: '', size: [] };
if (poBid.nativeParams) {
loOne.type = 'native';
} else {
loOne.type = 'banner';
loOne.size = poBid.sizes;
}
return loOne;
});
const loServerRequest = {
cur: CURRENCY,
timeout: poBidderRequest.timeout,
auction_id: paValidBidRequests[0].auctionId,
transaction_id: paValidBidRequests[0].transactionId,
bids: laBids,
gdpr: { applies: false, consent: false },
};
if (poBidderRequest && poBidderRequest.gdprConsent) {
const loGdprConsent = poBidderRequest.gdprConsent;
if ((typeof loGdprConsent.gdprApplies === 'boolean') && loGdprConsent.gdprApplies) {
loServerRequest.gdpr.applies = true;
}
if ((typeof loGdprConsent.consentString === 'string') && loGdprConsent.consentString) {
loServerRequest.gdpr.consent = poBidderRequest.gdprConsent.consentString;
}
}
const lsUrl = this.params.bidder_url + '/' + this.params.tag_id;
return {
method: 'POST',
url: lsUrl,
data: JSON.stringify(loServerRequest),
};
}, // buildRequests

/**
* Unpack the response from the server into a list of bids.
*
* @param poServerResponse A successful response from the server.
* @param poPidRequest Request original server request
* @return An array of bids which were nested inside the server.
*/
interpretResponse: (poServerResponse, poPidRequest) => {
utils.logInfo('interpretResponse : ', poServerResponse);
if (!poServerResponse.body) {
return [];
}
let laResponse = [];
if (poServerResponse.body.status !== 'ok') {
utils.logInfo('Error : ', poServerResponse.body.error);
return laResponse;
}
poServerResponse.body.bids.forEach((poResponse) => {
laResponse[laResponse.length] = {
requestId: poResponse.requestId,
cpm: poResponse.cpm,
currency: poResponse.currency,
width: poResponse.width,
height: poResponse.height,
ad: poResponse.ad,
ttl: poResponse.ttl,
creativeId: poResponse.creativeId,
netRevenue: poResponse.netRevenue,
pbid: poServerResponse.body.pbid,
};
});
return laResponse;
}, // interpretResponse

/**
* Register bidder specific code, which will execute if a bid from this bidder won the auction.
*
* @param poBid The bid that won the auction
*/
onBidWon: (poBid) => {
utils.logInfo('onBidWon : ', poBid);
if (poBid.pbid) {
ajax(this.params.bidder_url + 'won/' + poBid.pbid);
}
}, // onBidWon
};

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

```
Module Name: TalkAds Adapter
Module Type: Bidder Adapter
Maintainer: technical_team@natexo.com
```

# Description

Module that connects to TalkAds bidder to fetch bids.
Both native and banner formats are supported but not at the same time.
The only currently supported currency is EUR.

This adapter requires setup and approval from the Natexo programmatic team.

# Configuration




# Test parameters

## Test banner Parameters

```
var adUnits = [
code: 'prebid_banner_test',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]],
}
},
bids: [{
bidder: 'talkads',
params: {
tag_id: 0,
bidder_url: 'https://d.natexo-programmatic.com/tad/tag/testbid',
},
}]
];
```

## Test native parameters

```
var adUnits = [
code: 'prebid_native_test',
mediaTypes: {
native: {}
},
bids: [{
bidder: 'talkads',
params: {
tag_id: 0,
bidder_url: 'https://d.natexo-programmatic.com/tad/tag/testbid',
},
}]
];
```
Loading

0 comments on commit 7b16442

Please sign in to comment.