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

Audiencelogy Bid Adapter : Initial Release #11853

Open
wants to merge 7 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
104 changes: 104 additions & 0 deletions libraries/audiencelogyUtils/bidderUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
deepAccess,
generateUUID,
isArray,
} from '../../src/utils.js';

// Function to get Request
export const getRequest = (bid, bidderRequest) => {
let request = {
id: generateUUID(),
imp: [{
id: bid.bidId,
bidfloor: getFloor(bid),
banner: getBanner(bid)
}],
placementId: bid.params.placement_id,
site: getSite(bidderRequest),
user: buildUser(bid)
};
// Get GPP Consent from bidderRequest
if (bidderRequest?.gppConsent?.gppString) {
request.gpp = bidderRequest.gppConsent.gppString;
request.gpp_sid = bidderRequest.gppConsent.applicableSections;
} else if (bidderRequest?.ortb2?.regs?.gpp) {
request.gpp = bidderRequest.ortb2.regs.gpp;
request.gpp_sid = bidderRequest.ortb2.regs.gpp_sid;
}
// Get coppa compliance from bidderRequest
if (bidderRequest?.ortb2?.regs?.coppa) {
request.coppa = 1;
}
// Get uspConsent from bidderRequest
if (bidderRequest && bidderRequest.uspConsent) {
request.us_privacy = bidderRequest.uspConsent;
}
return request;
}
// Function to get banner details
const getBanner = (bid) => {
if (deepAccess(bid, 'mediaTypes.banner')) {
// Fetch width and height from MediaTypes object, if not provided in bid params
if (deepAccess(bid, 'mediaTypes.banner.sizes') && !bid.params.height && !bid.params.width) {
let sizes = deepAccess(bid, 'mediaTypes.banner.sizes');
if (isArray(sizes) && sizes.length > 0) {
return {
h: sizes[0][1],
w: sizes[0][0]
};
}
} else {
return {
h: bid.params.height,
w: bid.params.width
};
}
}
}
// Function to get bid_floor
const getFloor = (bid) => {
if (bid.params && bid.params.bid_floor) {
return bid.params.bid_floor;
} else {
return 0;
}
}
// Function to get site details
const getSite = (bidderRequest) => {
let site = {};
if (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.page) {
site.name = bidderRequest.refererInfo.domain;
} else {
site.name = '';
}
return site;
}
// Function to format response
export const formatResponse = (bid) => {
let response = {};
response.requestId = bid && bid.impid ? bid.impid : undefined;
response.cpm = bid && bid.price ? bid.price : 0.0;
response.width = bid && bid.w ? bid.w : 0;
response.height = bid && bid.h ? bid.h : 0;
response.ad = bid && bid.adm ? bid.adm : '';
response.meta = {
advertiserDomains: bid && bid.adomain ? bid.adomain : []
};
response.creativeId = bid && bid.crid ? bid.crid : undefined;
response.netRevenue = false;
response.currency = bid && bid.cur ? bid.cur : 'USD';
response.ttl = 300;
response.dealId = bid && bid.dealId ? bid.dealId : undefined;
return response;
}
// Function to build the user object
const buildUser = (bid) => {
let user = {};
if (bid && bid.params) {
user.id = bid.params.user_id && typeof bid.params.user_id == 'string' ? bid.params.user_id : '';
user.buyeruid = localStorage.getItem('adx_profile_guid') ? localStorage.getItem('adx_profile_guid') : '';
user.keywords = bid.params.keywords && typeof bid.params.keywords == 'string' ? bid.params.keywords : '';
user.customdata = bid.params.customdata && typeof bid.params.customdata == 'string' ? bid.params.customdata : '';
}
return user;
}
70 changes: 70 additions & 0 deletions modules/audiencelogyBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
logError
} from '../src/utils.js';
import {
BANNER
} from '../src/mediaTypes.js';
import {
registerBidder
} from '../src/adapters/bidderFactory.js';
import {
getRequest,
formatResponse,
} from '../libraries/audiencelogyUtils/bidderUtils.js';

const BIDDER_CODE = 'audiencelogy';
const ENDPOINT_URL = 'https://rtb.audiencelogy.com/prebid';

// Export const spec
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: BANNER,
// Determines whether or not the given bid request is valid
isBidRequestValid: function (bid) {
return !!(bid.params.placement_id && bid.params.user_id && bid.params.nid);
},
// Make a server request from the list of BidRequests
buildRequests: function (bidRequests, bidderRequest) {
const requests = [];
let nid = 0;
// Loop for each bid request
bidRequests.forEach(bid => {
// Get the bid request object
const request = getRequest(bid, bidderRequest);
// Push the created bid request to the requests array
requests.push(request);
// Set nid value
nid = bid.params.nid;
});
// Return the array of bid requests
return {
method: 'POST',
url: `${ENDPOINT_URL}/${nid}`,
data: JSON.stringify(requests),
options: {
contentType: 'application/json',
}
};
},
// Unpack the response from the server into a list of bids.
interpretResponse: function (bidResponse, bidRequest) {
let resp = [];
if (bidResponse && bidResponse.body) {
try {
let bids = bidResponse.body.seatbid && bidResponse.body.seatbid[0] ? bidResponse.body.seatbid[0].bid : [];
if (bids) {
bids.forEach(bidObj => {
let newBid = formatResponse(bidObj);
newBid.mediaType = BANNER;
resp.push(newBid);
});
}
} catch (err) {
logError(err);
}
}
return resp;
}
}

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

```
Module Name: Audiencelogy Bidder Adapter
Module Type: Bidder Adapter
Maintainer: support@audiencelogy.com
```

# Description

Audiencelogy currently supports the BANNER type ads through prebid js

Module that connects to audiencelogy's demand sources.

# Banner Test Request
```
var adUnits = [
{
code: 'display-ad',
mediaTypes: {
banner: {
sizes: [[160, 600]],
}
}
bids: [
{
bidder: 'audiencelogy',
params: {
user_id: '1111111' // Required parameter
nid: 1, // Required parameter
placement_id: 584, // Required parameter
width: 160, // Optional parameter
height: 600, // Optional parameter
domain: '', // Optional parameter
bid_floor: 0.5 // Optional parameter
}
}
]
}
];
```
Loading
Loading