Skip to content

Commit

Permalink
Merge remote-tracking branch 'prebid/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdsInteractive committed Oct 14, 2024
2 parents 9d02c19 + 4cc7d25 commit 94f925f
Show file tree
Hide file tree
Showing 11 changed files with 1,331 additions and 7 deletions.
105 changes: 102 additions & 3 deletions libraries/audUtils/bidderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import {
logError
} from '../../src/utils.js';

// Declare native assets
const NATIVE_ASSETS = [
{ id: 1, required: 1, title: { len: 100 } }, // Title
{ id: 2, required: 1, img: { type: 3, w: 300, h: 250 } }, // Main image
{ id: 3, required: 0, data: { type: 1, len: 140 } }, // Body
{ id: 4, required: 1, data: { type: 2 } }, // Sponsored by
{ id: 5, required: 1, icon: { w: 50, h: 50 } }, // Icon
{ id: 6, required: 1, data: { type: 12, len: 15 } } // Call to action
];
// Function to get Request
export const getBannerRequest = (bidRequests, bidderRequest, ENDPOINT) => {
let request = [];
Expand Down Expand Up @@ -34,6 +43,7 @@ export const getBannerRequest = (bidRequests, bidderRequest, ENDPOINT) => {
if (bidderRequest?.uspConsent) {
deepSetValue(req, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}
req.MediaType = getMediaType(bidReq);
request.push(req);
});
// Return the array of request
Expand All @@ -48,6 +58,15 @@ export const getBannerRequest = (bidRequests, bidderRequest, ENDPOINT) => {
}
// Function to get Response
export const getBannerResponse = (bidResponse, mediaType) => {
return formatResponse(bidResponse, mediaType);
}
// Function to get NATIVE Response
export const getNativeResponse = (bidResponse, bidRequest, mediaType) => {
const assets = JSON.parse(JSON.parse(bidRequest.data)[0].imp[0].native.request).assets;
return formatResponse(bidResponse, mediaType, assets);
}
// Function to format response
const formatResponse = (bidResponse, mediaType, assets) => {
let responseArray = [];
if (bidResponse) {
try {
Expand All @@ -61,14 +80,28 @@ export const getBannerResponse = (bidResponse, mediaType) => {
response.height = bidReq.h;
response.ad = bidReq.adm;
response.meta = {
advertiserDomains: bidReq.adomain
advertiserDomains: bidReq.adomain,
primaryCatId: bidReq.cat || [],
attr: bidReq.attr || []
};
response.creativeId = bidReq.crid;
response.netRevenue = false;
response.currency = 'USD';
response.ttl = 300;
response.dealId = bidReq.dealId;
response.mediaType = mediaType;
if (mediaType == 'native') {
let nativeResp = JSON.parse(bidReq.adm).native;
let nativeData = {
clickUrl: nativeResp.link.url,
impressionTrackers: nativeResp.imptrackers
};
nativeResp.assets.forEach(asst => {
let data = getNativeAssestData(asst, assets);
nativeData[data.key] = data.value;
});
response.native = nativeData;
}
responseArray.push(response);
});
}
Expand All @@ -78,13 +111,18 @@ export const getBannerResponse = (bidResponse, mediaType) => {
}
return responseArray;
}
// Function to get imp
// Function to get imp based on Media Type
const getImpDetails = (bidReq) => {
let imp = {};
if (bidReq) {
imp.id = bidReq.bidId;
imp.bidfloor = getFloorPrice(bidReq);
imp.banner = getBannerDetails(bidReq);
if (bidReq.mediaTypes.native) {
let assets = { assets: NATIVE_ASSETS };
imp.native = { request: JSON.stringify(assets) };
} else if (bidReq.mediaTypes.banner) {
imp.banner = getBannerDetails(bidReq);
}
}
return imp;
}
Expand Down Expand Up @@ -137,3 +175,64 @@ const getUserDetails = (bidReq) => {
}
return user;
}
// Function to get asset data for response
const getNativeAssestData = (params, assets) => {
let response = {};
if (params.title) {
response.key = 'title';
response.value = params.title.text;
}
if (params.data) {
response.key = getAssetData(params.id, assets);
response.value = params.data.value;
}
if (params.img) {
response.key = getAssetImageDataType(params.id, assets);
response.value = {
url: params.img.url,
height: params.img.h,
width: params.img.w
}
}
return response;
}
// Function to get asset data types based on id
const getAssetData = (paramId, asset) => {
let resp = '';
for (let i = 0; i < asset.length; i++) {
if (asset[i].id == paramId) {
switch (asset[i].data.type) {
case 1 : resp = 'sponsored';
break;
case 2 : resp = 'desc';
break;
case 12 : resp = 'cta';
break;
}
}
}
return resp;
}
// Function to get image type based on the id
const getAssetImageDataType = (paramId, asset) => {
let resp = '';
for (let i = 0; i < asset.length; i++) {
if (asset[i].id == paramId) {
switch (asset[i].img.type) {
case 1 : resp = 'icon';
break;
case 3 : resp = 'image';
break;
}
}
}
return resp;
}
// Function to get Media Type
const getMediaType = (bidReq) => {
if (bidReq.mediaTypes.native) {
return 'native';
} else if (bidReq.mediaTypes.banner) {
return 'banner';
}
}
37 changes: 37 additions & 0 deletions modules/excoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {getStorageManager} from '../src/storageManager.js';
import {
isBidRequestValid, createUserSyncGetter, createInterpretResponseFn, createBuildRequestsFn
} from '../libraries/vidazooUtils/bidderUtils.js';

const DEFAULT_SUB_DOMAIN = 'rtb';
const BIDDER_CODE = 'exco';
const BIDDER_VERSION = '1.0.0';
const GVLID = 444;
export const storage = getStorageManager({bidderCode: BIDDER_CODE});

export function createDomain(subDomain = DEFAULT_SUB_DOMAIN) {
return `https://${subDomain}.exco-pb.com`;
}

const buildRequests = createBuildRequestsFn(createDomain, null, storage, BIDDER_CODE, BIDDER_VERSION, false);

const interpretResponse = createInterpretResponseFn(BIDDER_CODE, false);

const getUserSyncs = createUserSyncGetter({
iframeSyncUrl: 'https://cs.exco-pb.com/api/sync/iframe', imageSyncUrl: 'https://cs.exco-pb.com/api/sync/image'
});

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

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

**Module Name:** Exco Bid Adapter

**Module Type:** Bidder Adapter

**Maintainer:** [email protected]

# Description

Module that connects to Exco's demand sources.

# Test Parameters
```js
var adUnits = [
{
code: 'test-ad',
sizes: [[300, 250]],
bids: [
{
bidder: 'exco',
params: {
cId: '562524b21b1c1f08117fc7f9',
pId: '59ac17c192832d0011283fe3',
bidFloor: 0.0001,
ext: {
param1: 'loremipsum',
param2: 'dolorsitamet'
}
}
}
]
}
];
```
42 changes: 41 additions & 1 deletion modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,41 @@ function _getFloor(mediaTypes, staticBidFloor, bid) {
return bidFloor;
}

/**
* Retrieves the device data from the ORTB2 object
* @param {Object} ortb2Data ORTB2 object
* @returns {Object} Device data
*/
function _getDeviceData(ortb2Data) {
const _device = deepAccess(ortb2Data, 'device') || {};

// set device data params from ortb2
const _deviceRequestParams = {
ip: _device.ip,
ipv6: _device.ipv6,
ua: _device.ua,
dnt: _device.dnt,
os: _device.os,
osv: _device.osv,
dt: _device.devicetype,
lang: _device.language,
make: _device.make,
model: _device.model,
ppi: _device.ppi,
pxratio: _device.pxratio,
foddid: _device?.ext?.fiftyonedegrees_deviceId,
};

// return device data params with only non-empty values
return Object.keys(_deviceRequestParams)
.reduce((r, key) => {
if (_deviceRequestParams[key] !== undefined) {
r[key] = _deviceRequestParams[key];
}
return r;
}, {});
}

/**
* loops through bannerSizes array to get greatest slot dimensions
* @param {number[][]} sizes
Expand Down Expand Up @@ -437,6 +472,11 @@ function buildRequests(validBidRequests, bidderRequest) {
if (schain && schain.nodes) {
data.schain = _serializeSupplyChainObj(schain);
}
Object.assign(
data,
_getBrowserParams(topWindowUrl, mosttopLocation),
_getDeviceData(bidderRequest?.ortb2),
);

bids.push({
id: bidId,
Expand All @@ -447,7 +487,7 @@ function buildRequests(validBidRequests, bidderRequest) {
sizes,
url: BID_ENDPOINT,
method: 'GET',
data: Object.assign(data, _getBrowserParams(topWindowUrl, mosttopLocation))
data
});
});
return bids;
Expand Down
41 changes: 41 additions & 0 deletions modules/tapnativeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
BANNER,
NATIVE
} from '../src/mediaTypes.js';
import {
registerBidder
} from '../src/adapters/bidderFactory.js';
import {
getBannerRequest,
getBannerResponse,
getNativeResponse,
} from '../libraries/audUtils/bidderUtils.js';

const ENDPOINT = 'https://rtb-east.tapnative.com/hb';
// Export const spec
export const spec = {
code: 'tapnative',
supportedMediaTypes: [BANNER, NATIVE],
// Determines whether or not the given bid request is valid
isBidRequestValid: function(bidParam) {
return !!(bidParam.params.placement_id);
},
// Make a server request from the list of BidRequests
buildRequests: function(bidRequests, serverRequest) {
// Get Requests based on media types
return getBannerRequest(bidRequests, serverRequest, ENDPOINT);
},
// Unpack the response from the server into a list of bids.
interpretResponse: function(serverResponse, serverRequest) {
let bidderResponse = {};
const mType = JSON.parse(serverRequest.data)[0].MediaType;
if (mType == BANNER) {
bidderResponse = getBannerResponse(serverResponse, BANNER);
} else if (mType == NATIVE) {
bidderResponse = getNativeResponse(serverResponse, serverRequest, NATIVE);
}
return bidderResponse;
}
}

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

```
Module Name: Tapnative Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

Tapnative currently supports the BANNER and NATIVE type ads through prebid js

Module that connects to tapnative's demand sources.

# Test Request
```
var adUnits = [
{
code: 'display-ad',
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
}
bids: [
{
bidder: 'tapnative',
params: {
placement_id: 111520, // Required parameter
width: 300, // Optional parameter
height: 250, // Optional parameter
bid_floor: 0.5 // Optional parameter
}
}
]
},
{
code: 'native-ad-container',
mediaTypes: {
native: {
title: { required: true, len: 100 },
image: { required: true, sizes: [300, 250] },
sponsored: { required: false },
clickUrl: { required: true },
desc: { required: true },
icon: { required: false, sizes: [50, 50] },
cta: { required: false }
}
},
bids: [
{
bidder: 'tapnative',
params: {
placement_id: 111519, // Required parameter
bid_floor: 1 // Optional parameter
}
}
]
}
];
```
Loading

0 comments on commit 94f925f

Please sign in to comment.