Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Alkimi-Exchange/Prebid.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kalidas-alkimi committed Apr 19, 2024
2 parents bfeb356 + c4b879a commit eb0f842
Show file tree
Hide file tree
Showing 23 changed files with 1,055 additions and 32 deletions.
2 changes: 1 addition & 1 deletion modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
const queryParamsAndValues = [];
queryParamsAndValues.push('tzo=' + new Date().getTimezoneOffset())
queryParamsAndValues.push('format=json')
queryParamsAndValues.push('format=prebid')
const gdprApplies = deepAccess(bidderRequest, 'gdprConsent.gdprApplies');
const consentString = deepAccess(bidderRequest, 'gdprConsent.consentString');
if (gdprApplies !== undefined) {
Expand Down
9 changes: 9 additions & 0 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ function checkNativeSendId(bidRequest) {
*/
function buildCdbRequest(context, bidRequests, bidderRequest) {
let networkId;
let pubid;
let schain;
let userIdAsEids;
let regs = Object.assign({}, {
Expand All @@ -490,6 +491,7 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
userIdAsEids = bidRequest.userIdAsEids;
}
networkId = bidRequest.params.networkId || networkId;
pubid = bidRequest.params.pubid || pubid;
schain = bidRequest.schain || schain;
const slot = {
slotid: bidRequest.bidId,
Expand All @@ -513,6 +515,10 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
if (bidRequest.nativeOrtbRequest?.assets) {
slot.ext = Object.assign({}, slot.ext, { assets: bidRequest.nativeOrtbRequest.assets });
}
if (bidRequest.params.uid) {
slot.ext = Object.assign({}, slot.ext, { bidder: { uid: bidRequest.params.uid } });
}

if (bidRequest.params.publisherSubId) {
slot.publishersubid = bidRequest.params.publisherSubId;
}
Expand Down Expand Up @@ -581,6 +587,9 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
if (networkId) {
request.publisher.networkid = networkId;
}
if (pubid) {
request.publisher.id = pubid;
}

request.source = {
tid: bidderRequest.ortb2?.source?.tid
Expand Down
21 changes: 21 additions & 0 deletions modules/discoveryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const COOKIE_RETENTION_TIME = 365 * 24 * 60 * 60 * 1000; // 1 year
const COOKY_SYNC_IFRAME_URL = 'https://asset.popin.cc/js/cookieSync.html';
export const THIRD_PARTY_COOKIE_ORIGIN = 'https://asset.popin.cc';

const UTM_KEY = '_ss_pp_utm';
let UTMValue = {};

const NATIVERET = {
id: 'id',
bidfloor: 0,
Expand Down Expand Up @@ -409,6 +412,20 @@ function getItems(validBidRequests, bidderRequest) {
return items;
}

export const buildUTMTagData = (url) => {
if (!storage.cookiesAreEnabled()) return;
const urlParams = utils.parseUrl(url).search;
const UTMParams = {};
Object.keys(urlParams).forEach(key => {
if (/^utm_/.test(key)) {
UTMParams[key] = urlParams[key];
}
});
UTMValue = JSON.parse(storage.getCookie(UTM_KEY) || '{}');
Object.assign(UTMValue, UTMParams);
storage.setCookie(UTM_KEY, JSON.stringify(UTMValue), getCurrentTimeToUTCString());
}

/**
* get rtb qequest params
*
Expand Down Expand Up @@ -443,6 +460,10 @@ function getParam(validBidRequests, bidderRequest) {
const desc = getPageDescription();
const keywords = getPageKeywords();

try {
buildUTMTagData(page);
} catch (error) { }

if (items && items.length) {
let c = {
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
Expand Down
4 changes: 2 additions & 2 deletions modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ function _addBidResponse(serverBid, bidRequest, bidResponses, RendererConst, bid
bidResponse.meta.demandSource = serverBid.ext.bidder.grid.demandSource;
}

if (serverBid.ext && serverBid.ext.dsa && serverBid.ext.dsa.adrender) {
bidResponse.meta.adrender = serverBid.ext.dsa.adrender;
if (serverBid.ext && serverBid.ext.dsa) {
bidResponse.meta.dsa = serverBid.ext.dsa;
}

if (serverBid.content_type === 'video') {
Expand Down
3 changes: 2 additions & 1 deletion modules/limelightDigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ function buildPlacement(bidRequest) {
custom2: bidRequest.params.custom2,
custom3: bidRequest.params.custom3,
custom4: bidRequest.params.custom4,
custom5: bidRequest.params.custom5
custom5: bidRequest.params.custom5,
page: bidRequest.refererInfo.page
}
}
}
190 changes: 190 additions & 0 deletions modules/loyalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { logMessage, logError } from '../src/utils.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';

import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';

const BIDDER_CODE = 'loyal';
const AD_URL = 'https://us-east-1.loyal.app/pbjs';

function isBidResponseValid(bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId || !bid.ttl || !bid.currency) {
return false;
}

switch (bid.mediaType) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad);
case VIDEO:
return Boolean(bid.vastUrl || bid.vastXml);
case NATIVE:
return Boolean(bid.native && bid.native.impressionTrackers && bid.native.impressionTrackers.length);
default:
return false;
}
}

function getPlacementReqData(bid) {
const { params, bidId, mediaTypes } = bid;
const schain = bid.schain || {};
const { placementId, endpointId } = params;
const bidfloor = getBidFloor(bid);

const placement = {
bidId,
schain,
bidfloor,
eids: []
};

if (placementId) {
placement.placementId = placementId;
placement.type = 'publisher';
} else if (endpointId) {
placement.endpointId = endpointId;
placement.type = 'network';
}

if (mediaTypes && mediaTypes[BANNER]) {
placement.adFormat = BANNER;
placement.sizes = mediaTypes[BANNER].sizes;
} else if (mediaTypes && mediaTypes[VIDEO]) {
placement.adFormat = VIDEO;
placement.playerSize = mediaTypes[VIDEO].playerSize;
placement.minduration = mediaTypes[VIDEO].minduration;
placement.maxduration = mediaTypes[VIDEO].maxduration;
placement.mimes = mediaTypes[VIDEO].mimes;
placement.protocols = mediaTypes[VIDEO].protocols;
placement.startdelay = mediaTypes[VIDEO].startdelay;
placement.placement = mediaTypes[VIDEO].placement;
placement.skip = mediaTypes[VIDEO].skip;
placement.skipafter = mediaTypes[VIDEO].skipafter;
placement.minbitrate = mediaTypes[VIDEO].minbitrate;
placement.maxbitrate = mediaTypes[VIDEO].maxbitrate;
placement.delivery = mediaTypes[VIDEO].delivery;
placement.playbackmethod = mediaTypes[VIDEO].playbackmethod;
placement.api = mediaTypes[VIDEO].api;
placement.linearity = mediaTypes[VIDEO].linearity;
} else if (mediaTypes && mediaTypes[NATIVE]) {
placement.native = mediaTypes[NATIVE];
placement.adFormat = NATIVE;
}

return placement;
}

function getBidFloor(bid) {
try {
const bidFloor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*',
});
return bidFloor.floor;
} catch (err) {
logError(err);
return 0;
}
}

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

isBidRequestValid: (bid = {}) => {
const { params, bidId, mediaTypes } = bid;
let valid = Boolean(bidId && params && (params.placementId || params.endpointId));

if (mediaTypes && mediaTypes[BANNER]) {
valid = valid && Boolean(mediaTypes[BANNER] && mediaTypes[BANNER].sizes);
} else if (mediaTypes && mediaTypes[VIDEO]) {
valid = valid && Boolean(mediaTypes[VIDEO] && mediaTypes[VIDEO].playerSize);
} else if (mediaTypes && mediaTypes[NATIVE]) {
valid = valid && Boolean(mediaTypes[NATIVE]);
} else {
valid = false;
}
return valid;
},

buildRequests: (validBidRequests = [], bidderRequest = {}) => {
// convert Native ORTB definition to old-style prebid native definition
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);

let deviceWidth = 0;
let deviceHeight = 0;

let winLocation;
try {
const winTop = window.top;
deviceWidth = winTop.screen.width;
deviceHeight = winTop.screen.height;
winLocation = winTop.location;
} catch (e) {
logMessage(e);
winLocation = window.location;
}

const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.page;
let refferLocation;
try {
refferLocation = refferUrl && new URL(refferUrl);
} catch (e) {
logMessage(e);
}
// TODO: does the fallback make sense here?
let location = refferLocation || winLocation;
const language = (navigator && navigator.language) ? navigator.language.split('-')[0] : '';
const host = location.host;
const page = location.pathname;
const secure = location.protocol === 'https:' ? 1 : 0;
const placements = [];
const request = {
deviceWidth,
deviceHeight,
language,
secure,
host,
page,
placements,
coppa: config.getConfig('coppa') === true ? 1 : 0,
ccpa: bidderRequest.uspConsent || undefined,
tmax: bidderRequest.timeout
};

if (bidderRequest.gdprConsent?.consentString) {
request.gdpr = {
consentString: bidderRequest.gdprConsent.consentString
};
}

const len = validBidRequests.length;
for (let i = 0; i < len; i++) {
const bid = validBidRequests[i];
placements.push(getPlacementReqData(bid));
}

return {
method: 'POST',
url: AD_URL,
data: request
};
},

interpretResponse: (serverResponse) => {
let response = [];
for (let i = 0; i < serverResponse.body.length; i++) {
let resItem = serverResponse.body[i];
if (isBidResponseValid(resItem)) {
const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : [];
resItem.meta = { ...resItem.meta, advertiserDomains };

response.push(resItem);
}
}
return response;
},
};

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

```
Module Name: Loyal Bidder Adapter
Module Type: Loyal Bidder Adapter
Maintainer: hello@loyal.app
```

# Description

Connects to Loyal exchange for bids.
Loyal bid adapter supports Banner, Video (instream and outstream) and Native.

# Test Parameters
```
var adUnits = [
// Will return static test banner
{
code: 'adunit1',
mediaTypes: {
banner: {
sizes: [ [300, 250], [320, 50] ],
}
},
bids: [
{
bidder: 'loyal',
params: {
placementId: 'testBanner',
}
}
]
},
{
code: 'addunit2',
mediaTypes: {
video: {
playerSize: [ [640, 480] ],
context: 'instream',
minduration: 5,
maxduration: 60,
}
},
bids: [
{
bidder: 'loyal',
params: {
placementId: 'testVideo',
}
}
]
},
{
code: 'addunit3',
mediaTypes: {
native: {
title: {
required: true
},
body: {
required: true
},
icon: {
required: true,
size: [64, 64]
}
}
},
bids: [
{
bidder: 'loyal',
params: {
placementId: 'testNative',
}
}
]
}
];
```
Loading

0 comments on commit eb0f842

Please sign in to comment.