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

Admatic Bid Adapter: pixad alias and bid floor features activated #9204

Merged
merged 23 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d49b56a
Admatic Bidder Adaptor
fatihkaya84 Oct 19, 2022
e582645
Update admaticBidAdapter.md
fatihkaya84 Oct 19, 2022
4c4c06a
Update admaticBidAdapter.md
fatihkaya84 Oct 28, 2022
7a23b05
remove floor parameter
fatihkaya84 Oct 31, 2022
7a845b7
Update admaticBidAdapter.js
fatihkaya84 Oct 31, 2022
7a2e0e2
Admatic Bid Adapter: alias and bid floor features activated
fatihkaya84 Nov 4, 2022
de7ac85
Admatic adapter: host param control changed
fatihkaya84 Nov 4, 2022
661c54f
Alias name changed.
fatihkaya84 Nov 4, 2022
42675a0
Revert "Admatic adapter: host param control changed"
fatihkaya84 Nov 4, 2022
6ec8f45
added alias feature and host param
fatihkaya84 Nov 4, 2022
63e1fc6
Revert "added alias feature and host param"
fatihkaya84 Nov 5, 2022
6da6565
Revert "Alias name changed."
fatihkaya84 Nov 5, 2022
549f349
Revert "Admatic Bid Adapter: alias and bid floor features activated"
fatihkaya84 Nov 5, 2022
0b8718e
Revert "Update admaticBidAdapter.js"
fatihkaya84 Nov 5, 2022
e7f6902
Revert "remove floor parameter"
fatihkaya84 Nov 5, 2022
3c797b1
Admatic adapter: host param control && Add new Bidder
fatihkaya84 Nov 5, 2022
f44bbeb
Revert "Admatic adapter: host param control && Add new Bidder"
fatihkaya84 Nov 5, 2022
fb6e36e
Merge branch 'prebid:master' into master
fatihkaya84 Nov 5, 2022
68f2596
commit new features
fatihkaya84 Nov 5, 2022
7fd1f26
Update admaticBidAdapter.js
fatihkaya84 Nov 6, 2022
e883ef6
updated for coverage
fatihkaya84 Nov 12, 2022
6961cae
sync updated
fatihkaya84 Nov 14, 2022
a3b299f
Update adloader.js
fatihkaya84 Nov 14, 2022
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
167 changes: 108 additions & 59 deletions modules/admaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,117 +1,162 @@
import { getValue, logError, deepAccess, getBidIdParameter, isArray } from '../src/utils.js';
import { loadExternalScript } from '../src/adloader.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';

const ENDPOINT_URL = 'https://layer.serve.admatic.com.tr/pb';
const SYNC_URL = 'https://cdn.serve.admatic.com.tr/showad/sync.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
const SYNC_URL = 'https://cdn.serve.admatic.com.tr/showad/sync.html';
const BIDDER_CODE = 'admatic';

export const spec = {
code: 'admatic',
supportedMediaTypes: ['video', 'banner'],
/**
* 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.
code: BIDDER_CODE,
aliases: [
{code: 'pixad'}
],
supportedMediaTypes: [BANNER, VIDEO],
/** f
* @param {object} bid
* @return {boolean}
*/
isBidRequestValid: function(bid) {
isBidRequestValid: (bid) => {
let isValid = false;
if (typeof bid.params !== 'undefined') {
let isValidNetworkId = _validateId(getValue(bid.params, 'networkId'));
isValid = isValidNetworkId;// && isValidTypeId;
if (bid?.params) {
const isValidNetworkId = _validateId(getValue(bid.params, 'networkId'));
const isValidHost = _validateString(getValue(bid.params, 'host'));
isValid = isValidNetworkId && isValidHost;
}

if (!isValid) {
logError('AdMatic networkId parameters are required. Bid aborted.');
logError(`${bid.bidder} networkId and host parameters are required. Bid aborted.`);
}
return isValid;
},

/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} an array of bids
* @return ServerRequest Info describing the request to the server.
* @param {BidRequest[]} validBidRequests
* @return {ServerRequest}
*/
buildRequests: function(validBidRequests, bidderRequest) {
buildRequests: (validBidRequests, bidderRequest) => {
const bids = validBidRequests.map(buildRequestObject);
const networkId = getValue(validBidRequests[0].params, 'networkId');
const host = getValue(validBidRequests[0].params, 'host');
const currency = getValue(validBidRequests[0].params, 'currency') || 'TRY';

setTimeout(() => {
loadExternalScript(SYNC_URL, BIDDER_CODE);
}, bidderRequest.timeout);
const bidderName = validBidRequests[0].bidder;

const payload = {
'user': {
'ua': navigator.userAgent
user: {
ua: navigator.userAgent
},
'blacklist': [],
'site': {
'page': location.href,
'ref': location.origin,
'publisher': {
'name': location.hostname,
'publisherId': networkId
blacklist: [],
site: {
page: location.href,
ref: location.origin,
publisher: {
name: location.hostname,
publisherId: networkId
}
},
imp: bids,
ext: {
'cur': currency,
'type': 'admatic'
cur: currency,
bidder: bidderName
}
};

const payloadString = JSON.stringify(payload);
return {
method: 'POST',
url: ENDPOINT_URL,
data: payloadString,
options: {
contentType: 'application/json'
}
};
if (payload) {
return { method: 'POST', url: `https://${host}/pb?bidder=${bidderName}`, data: payload, options: { contentType: 'application/json' } };
}
},

getUserSyncs: function (syncOptions, responses) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: SYNC_URL
}];
}
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
* @param {*} response
* @param {ServerRequest} request
* @return {Bid[]}
*/
interpretResponse: (response, request) => {
const body = response.body || response;
const bidResponses = [];
if (body.data.length > 0) {
body.data.forEach(function (bid) {
if (body && body?.data && isArray(body.data)) {
body.data.forEach(bid => {
const resbid = {
requestId: bid.id,
cpm: bid.price,
width: bid.width,
height: bid.height,
currency: body.cur,
currency: body.cur || 'TRY',
netRevenue: true,
ad: bid.party_tag,
creativeId: bid.creative_id,
meta: {
advertiserDomains: bid && bid.adomain ? bid.adomain : []
},
ttl: 360,
bidder: 'admatic',
timeToRespond: 1,
requestTimestamp: 1
bidder: bid.bidder
};

bidResponses.push(resbid);
});
};
}
return bidResponses;
}
};

function enrichSlotWithFloors(slot, bidRequest) {
try {
const slotFloors = {};

if (bidRequest.getFloor) {
if (bidRequest.mediaTypes?.banner) {
slotFloors.banner = {};
const bannerSizes = parseSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes'))
bannerSizes.forEach(bannerSize => slotFloors.banner[parseSize(bannerSize).toString()] = bidRequest.getFloor({ size: bannerSize, mediaType: BANNER }));
}

if (bidRequest.mediaTypes?.video) {
slotFloors.video = {};
const videoSizes = parseSizes(deepAccess(bidRequest, 'mediaTypes.video.playerSize'))
videoSizes.forEach(videoSize => slotFloors.video[parseSize(videoSize).toString()] = bidRequest.getFloor({ size: videoSize, mediaType: VIDEO }));
}

if (Object.keys(slotFloors).length > 0) {
if (!slot) {
slot = {}
}
Object.assign(slot, {
floors: slotFloors
});
}
}
} catch (e) {
logError('Could not parse floors from Prebid: ' + e);
}
}

function parseSizes(sizes, parser = s => s) {
if (sizes == undefined) {
return [];
}
if (Array.isArray(sizes[0])) { // is there several sizes ? (ie. [[728,90],[200,300]])
return sizes.map(size => parser(size));
}
return [parser(sizes)]; // or a single one ? (ie. [728,90])
}

function parseSize(size) {
return size[0] + 'x' + size[1];
}

function buildRequestObject(bid) {
const reqObj = {};
reqObj.size = getSizes(bid);
reqObj.id = getBidIdParameter('bidId', bid);
reqObj.floor = getValue(bid.params, 'floor') || 0.01;

enrichSlotWithFloors(reqObj, bid);

return reqObj;
}

Expand Down Expand Up @@ -144,4 +189,8 @@ function _validateId(id) {
return (parseInt(id) > 0);
}

function _validateString(str) {
return (typeof str == 'string');
}

registerBidder(spec);
4 changes: 2 additions & 2 deletions modules/admaticBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Use `admatic` as bidder.
bidder: 'admatic',
params: {
networkId: 12345,
floor: 0.5
host: 'layer.serve.admatic.com.tr'
}
}]
},{
Expand All @@ -29,7 +29,7 @@ Use `admatic` as bidder.
bidder: 'admatic',
params: {
networkId: 12345,
floor: 0.5
host: 'layer.serve.admatic.com.tr'
}
}]
}];
Expand Down
1 change: 0 additions & 1 deletion src/adloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const _requestCache = new WeakMap();
const _approvedLoadExternalJSList = [
'debugging',
'adloox',
'admatic',
'criteo',
'outstream',
'adagio',
Expand Down
Loading