Skip to content

Commit

Permalink
Merge pull request #15 from prebid/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
pro-nsk authored Aug 24, 2023
2 parents 1ca3501 + ef8188e commit 1f46320
Show file tree
Hide file tree
Showing 15 changed files with 681 additions and 129 deletions.
3 changes: 2 additions & 1 deletion modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export const spec = {
{code: 'adliveconnect'},
{code: 'didnadisplay'},
{code: 'qortex'},
{code: 'adpluto'}
{code: 'adpluto'},
{code: 'headbidder'}
],
supportedMediaTypes: [BANNER, VIDEO, NATIVE],

Expand Down
16 changes: 11 additions & 5 deletions modules/adqueryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const spec = {
* @return {Bid[]}
*/
interpretResponse: (response, request) => {
logInfo(request);
logInfo(response);

const res = response && response.body && response.body.data;
let bidResponses = [];

Expand Down Expand Up @@ -113,8 +116,12 @@ export const spec = {
*/
onBidWon: (bid) => {
logInfo('onBidWon', bid);

const bidString = JSON.stringify(bid);
const encodedBuf = window.btoa(bidString);
let copyOfBid = JSON.parse(bidString);
delete copyOfBid.ad;
const shortBidString = JSON.stringify(bid);
const encodedBuf = window.btoa(shortBidString);

let params = {
q: encodedBuf,
Expand Down Expand Up @@ -170,7 +177,6 @@ export const spec = {
url: syncUrl
}];
}

};

function buildRequest(validBidRequests, bidderRequest) {
Expand All @@ -188,9 +194,9 @@ function buildRequest(validBidRequests, bidderRequest) {

if (!userId) {
// onetime User ID
const randomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4)));
userId = randomValues.map(it => it.toString(36)).join().substring(20);

const ramdomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4)));
userId = ramdomValues.map(val => val.toString(36)).join('').substring(0, 20);
logInfo('generated onetime User ID: ', userId);
window.qid = userId;
}

Expand Down
10 changes: 2 additions & 8 deletions modules/adqueryIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,9 @@ export const adqueryIdSubmodule = {
let qid = window.qid;

if (!qid) {
const ramdomValues = window.crypto.getRandomValues(new Uint32Array(4));
qid = (ramdomValues[0].toString(36) +
ramdomValues[1].toString(36) +
ramdomValues[2].toString(36) +
ramdomValues[3].toString(36))
.substring(0, 20);
const ramdomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4)));
qid = ramdomValues.map(val => val.toString(36)).join('').substring(0, 20);

const randomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4)));
qid = randomValues.map(it => it.toString(36)).join().substring(20);
logInfo('adqueryIdSubmodule ID QID GENERTAED:', qid);
}
logInfo('adqueryIdSubmodule ID QID:', qid);
Expand Down
6 changes: 2 additions & 4 deletions modules/geolocationRtdProvider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {submodule} from '../src/hook.js';
import {isFn, logError, deepAccess, deepSetValue, logInfo, logWarn} from '../src/utils.js';
import {isFn, logError, deepAccess, deepSetValue, logInfo, logWarn, timestamp} from '../src/utils.js';
import { ACTIVITY_TRANSMIT_PRECISE_GEO } from '../src/activities/activities.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';
import { isActivityAllowed } from '../src/activities/rules.js';
Expand All @@ -18,7 +18,6 @@ function getGeolocationData(requestBidsObject, onDone, providerConfig, userConse
return complete()
};
const requestPermission = deepAccess(providerConfig, 'params.requestPermission') === true;
const waitForIt = providerConfig.waitForIt;
navigator.permissions.query({
name: 'geolocation',
}).then(permission => {
Expand All @@ -28,15 +27,14 @@ function getGeolocationData(requestBidsObject, onDone, providerConfig, userConse
complete();
});
});
if (!waitForIt) complete();
function complete() {
if (done) return;
done = true;
if (geolocation) {
deepSetValue(requestBidsObject, 'ortb2Fragments.global.device.geo', {
lat: geolocation.coords.latitude,
lon: geolocation.coords.longitude,
lastfix: geolocation.timestamp,
lastfix: Math.round((timestamp() - geolocation.timestamp) / 1000),
type: 1
});
logInfo('geolocation was successfully received ', requestBidsObject.ortb2Fragments.global.device.geo)
Expand Down
146 changes: 146 additions & 0 deletions modules/precisoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { logMessage } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';

const BIDDER_CODE = 'preciso';
const AD_URL = 'https://ssp-bidder.mndtrk.com/bid_request/openrtb';
const URL_SYNC = 'https://ck.2trk.info/rtb/user/usersync.aspx?id=preciso_srl';
const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE, VIDEO];
const GVLID = 874;

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,
gvlid: GVLID,

isBidRequestValid: (bid) => {
return Boolean(bid.bidId && bid.params && !isNaN(bid.params.publisherId) && bid.params.host == 'prebid');
},

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

let winTop = window;
let location;
// TODO: this odd try-catch block was copied in several adapters; it doesn't seem to be correct for cross-origin
try {
location = new URL(bidderRequest.refererInfo.page)
winTop = window.top;
} catch (e) {
location = winTop.location;
logMessage(e);
};
let placements = [];
let imp = [];
let site = {
'domain': location.domain || '',
'page': location || ''
}

let request = {
'id': '123456',
'imp': imp,
'site': site,
'deviceWidth': winTop.screen.width,
'deviceHeight': winTop.screen.height,
'language': (navigator && navigator.language) ? navigator.language : '',
'secure': 1,
'host': location.host,
'page': location.pathname,
'coppa': config.getConfig('coppa') === true ? 1 : 0,
'placements': placements
};
request.language.indexOf('-') != -1 && (request.language = request.language.split('-')[0])
if (bidderRequest) {
if (bidderRequest.uspConsent) {
request.ccpa = bidderRequest.uspConsent;
}
if (bidderRequest.gdprConsent) {
request.gdpr = bidderRequest.gdprConsent
}
if (bidderRequest.gppConsent) {
request.gpp = bidderRequest.gppConsent;
}
}

const len = validBidRequests.length;

for (let i = 0; i < len; i++) {
let bid = validBidRequests[i];
let traff = bid.params.traffic || BANNER
placements.push({
region: bid.params.region,
bidId: bid.bidId,
sizes: bid.mediaTypes && bid.mediaTypes[traff] && bid.mediaTypes[traff].sizes ? bid.mediaTypes[traff].sizes : [],
traffic: traff,
publisherId: bid.params.publisherId
});
imp.push({
id: bid.bidId,
sizes: bid.mediaTypes && bid.mediaTypes[traff] && bid.mediaTypes[traff].sizes ? bid.mediaTypes[traff].sizes : [],
traffic: traff,
publisherId: bid.params.publisherId
})
if (bid.schain) {
placements.schain = bid.schain;
}
}
return {
method: 'POST',
url: AD_URL,
data: request
};
},

interpretResponse: function (serverResponse) {
const response = serverResponse.body

const bids = []

response.seatbid.forEach(seat => {
seat.bid.forEach(bid => {
bids.push({
requestId: bid.impid,
cpm: bid.price,
width: bid.w,
height: bid.h,
creativeId: bid.crid,
ad: bid.adm,
currency: 'USD',
netRevenue: true,
ttl: 300,
meta: {
advertiserDomains: bid.adomain || [],
},
})
})
})

return bids
},

getUserSyncs: (syncOptions, serverResponses = [], gdprConsent = {}, uspConsent = '', gppConsent = '') => {
let syncs = [];
let { gdprApplies, consentString = '' } = gdprConsent;

if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: `${URL_SYNC}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&us_privacy=${uspConsent}&t=4`
});
} else {
syncs.push({
type: 'image',
url: `${URL_SYNC}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&us_privacy=${uspConsent}&t=2`
});
}

return syncs
}

};

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

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

# Description

Module that connects to preciso' demand sources

# Parameters

| Name | Scope | Description | Example |
| :------------ | :------- | :------------------------ | :------------------- |
| `region` | required (for prebid.js) | region | "prebid-eu" |
| `publisherId` | required (for prebid-server) | partner ID | "1901" |
| `traffic` | optional (for prebid.js) | Configures the mediaType that should be used. Values can be banner, native or video | "banner" |

# Test Parameters
```
var adUnits = [
// Will return static native ad. Assets are stored through user UI for each placement separetly
{
code: 'placementId_0',
mediaTypes: {
native: {}
},
bids: [
{
bidder: 'preciso',
params: {
host: 'prebid',
publisherId: '0',
region: 'prebid-eu',
traffic: 'native'
}
}
]
},
// Will return static test banner
{
code: 'placementId_0',
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
},
bids: [
{
bidder: 'preciso',
params: {
host: 'prebid',
publisherId: '0',
region: 'prebid-eu',
traffic: 'banner'
}
}
]
},
// Will return test vast xml. All video params are stored under placement in publishers UI
{
code: 'placementId_0',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'instream'
}
},
bids: [
{
bidder: 'preciso',
params: {
host: 'prebid',
publisherId: '0',
region: 'prebid-eu',
traffic: 'video'
}
}
]
}
];
```
13 changes: 13 additions & 0 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,16 @@ function bidResponseHandler(args) {
bid.bidResponse = parseBidResponse(args);
}

function bidRejectedHandler(args) {
// If bid is rejected due to floors value did not met
// make cpm as 0, status as bidRejected and forward the bid for logging
if (args.rejectionReason === CONSTANTS.REJECTION_REASON.FLOOR_NOT_MET) {
args.cpm = 0;
args.status = CONSTANTS.BID_STATUS.BID_REJECTED;
bidResponseHandler(args);
}
}

function bidderDoneHandler(args) {
cache.auctions[args.auctionId].bidderDonePendingCount--;
args.bids.forEach(bid => {
Expand Down Expand Up @@ -607,6 +617,9 @@ let pubmaticAdapter = Object.assign({}, baseAdapter, {
case CONSTANTS.EVENTS.BID_RESPONSE:
bidResponseHandler(args);
break;
case CONSTANTS.EVENTS.BID_REJECTED:
bidRejectedHandler(args)
break;
case CONSTANTS.EVENTS.BIDDER_DONE:
bidderDoneHandler(args);
break;
Expand Down
Loading

0 comments on commit 1f46320

Please sign in to comment.