Skip to content

Commit

Permalink
Merge branch 'prebid:master' into biddoBidAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
llays committed Apr 4, 2022
2 parents b2eb0e6 + f66e347 commit b9b33a5
Show file tree
Hide file tree
Showing 50 changed files with 3,270 additions and 1,989 deletions.
24 changes: 18 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ function makeDevpackPkg() {

function makeWebpackPkg() {
var cloned = _.cloneDeep(webpackConfig);
delete cloned.devtool;
if (!argv.sourceMaps) {
delete cloned.devtool;
}

var externalModules = helpers.getArgModules();

Expand All @@ -144,10 +146,19 @@ function makeWebpackPkg() {
return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid })))
.pipe(gulp.dest('build/dist'));
}

function addBanner() {
const sm = argv.sourceMaps;

return gulp.src(['build/dist/prebid-core.js'])
.pipe(gulpif(sm, sourcemaps.init({loadMaps: true})))
.pipe(header(banner, {prebid}))
.pipe(gulpif(sm, sourcemaps.write('.')))
.pipe(gulp.dest('build/dist'))
}

function getModulesListToAddInBanner(modules) {
return (modules.length > 0) ? modules.join(', ') : 'All available modules in current version.';
}
Expand All @@ -172,6 +183,7 @@ function nodeBundle(modules) {
function bundle(dev, moduleArr) {
var modules = moduleArr || helpers.getArgModules();
var allModules = helpers.getModuleNames(modules);
const sm = dev || argv.sourceMaps;

if (modules.length === 0) {
modules = allModules.filter(module => explicitModules.indexOf(module) === -1);
Expand Down Expand Up @@ -203,13 +215,13 @@ function bundle(dev, moduleArr) {
)
// Need to uodate the "Modules: ..." section in comment with the current modules list
.pipe(replace(/(Modules: )(.*?)(\*\/)/, ('$1' + getModulesListToAddInBanner(helpers.getArgModules()) + ' $3')))
.pipe(gulpif(dev, sourcemaps.init({ loadMaps: true })))
.pipe(gulpif(sm, sourcemaps.init({ loadMaps: true })))
.pipe(concat(outputFileName))
.pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', {
global: prebid.globalVarName
}
)))
.pipe(gulpif(dev, sourcemaps.write('.')));
.pipe(gulpif(sm, sourcemaps.write('.')));
}

// Run the unit tests.
Expand Down Expand Up @@ -398,7 +410,7 @@ gulp.task(clean);
gulp.task(escapePostbidConfig);

gulp.task('build-bundle-dev', gulp.series(makeDevpackPkg, gulpBundle.bind(null, true)));
gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg, gulpBundle.bind(null, false)));
gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg, addBanner, gulpBundle.bind(null, false)));

// public tasks (dependencies are needed for each task since they can be ran on their own)
gulp.task('test-only', test);
Expand All @@ -417,7 +429,7 @@ gulp.task('serve-fast', gulp.series(clean, gulp.parallel('build-bundle-dev', wat
gulp.task('serve-and-test', gulp.series(clean, gulp.parallel('build-bundle-dev', watchFast, testTaskMaker({watch: true}))));
gulp.task('serve-fake', gulp.series(clean, gulp.parallel('build-bundle-dev', watch), injectFakeServerEndpointDev, test, startFakeServer));

gulp.task('default', gulp.series(clean, makeWebpackPkg));
gulp.task('default', gulp.series(clean, 'build-bundle-prod'));

gulp.task('e2e-test', gulp.series(clean, setupE2e, gulp.parallel('build-bundle-prod', watch), injectFakeServerEndpoint, test));
// other tasks
Expand Down
82 changes: 80 additions & 2 deletions modules/adhashBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,79 @@ import {includes} from '../src/polyfill.js';
import {BANNER} from '../src/mediaTypes.js';

const VERSION = '1.0';
const BAD_WORD_STEP = 0.1;
const BAD_WORD_MIN = 0.2;

/**
* Function that checks the page where the ads are being served for brand safety.
* If unsafe words are found the scoring of that page increases.
* If it becomes greater than the maximum allowed score false is returned.
* The rules may vary based on the website language or the publisher.
* The AdHash bidder will not bid on unsafe pages (according to 4A's).
* @param badWords list of scoring rules to chech against
* @param maxScore maximum allowed score for that bidding
* @returns boolean flag is the page safe
*/
function brandSafety(badWords, maxScore) {
/**
* Performs the ROT13 encoding on the string argument and returns the resulting string.
* The Adhash bidder uses ROT13 so that the response is not blocked by:
* - ad blocking software
* - parental control software
* - corporate firewalls
* due to the bad words contained in the response.
* @param value The input string.
* @returns string Returns the ROT13 version of the given string.
*/
const rot13 = value => {
const input = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const output = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm';
const index = x => input.indexOf(x);
const translate = x => index(x) > -1 ? output[index(x)] : x;
return value.split('').map(translate).join('');
};

/**
* Calculates the scoring for each bad word with dimishing returns
* @param {integer} points points that this word costs
* @param {integer} occurances number of occurances
* @returns {float} final score
*/
const scoreCalculator = (points, occurances) => {
let positive = true;
if (points < 0) {
points *= -1;
positive = false;
}
let result = 0;
for (let i = 0; i < occurances; i++) {
result += Math.max(points - i * BAD_WORD_STEP, BAD_WORD_MIN);
}
return positive ? result : -result;
};

// Default parameters if the bidder is unable to send some of them
badWords = badWords || [];
maxScore = parseInt(maxScore) || 10;

try {
let score = 0;
const content = window.top.document.body.innerText.toLowerCase();
const words = content.trim().split(/\s+/).length;
for (const [word, rule, points] of badWords) {
if (rule === 'full' && new RegExp('\\b' + rot13(word) + '\\b', 'i').test(content)) {
const occurances = content.match(new RegExp('\\b' + rot13(word) + '\\b', 'g')).length;
score += scoreCalculator(points, occurances);
} else if (rule === 'partial' && content.indexOf(rot13(word.toLowerCase())) > -1) {
const occurances = content.match(new RegExp(rot13(word), 'g')).length;
score += scoreCalculator(points, occurances);
}
}
return score < maxScore * words / 500;
} catch (e) {
return true;
}
}

export const spec = {
code: 'adhash',
Expand Down Expand Up @@ -59,7 +132,8 @@ export const spec = {
blockedCreatives: [],
currentTimestamp: new Date().getTime(),
recentAds: [],
GDPR: gdprConsent
GDPRApplies: gdprConsent ? gdprConsent.gdprApplies : null,
GDPR: gdprConsent ? gdprConsent.consentString : null
},
options: {
withCredentials: false,
Expand All @@ -73,7 +147,11 @@ export const spec = {
interpretResponse: (serverResponse, request) => {
const responseBody = serverResponse ? serverResponse.body : {};

if (!responseBody.creatives || responseBody.creatives.length === 0) {
if (
!responseBody.creatives ||
responseBody.creatives.length === 0 ||
!brandSafety(responseBody.badWords, responseBody.maxScore)
) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion modules/admanBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {config} from '../src/config.js';

const BIDDER_CODE = 'adman';
const AD_URL = 'https://pub.admanmedia.com/?c=o&m=multi';
const URL_SYNC = 'https://pub.admanmedia.com';
const URL_SYNC = 'https://sync.admanmedia.com';

function isBidResponseValid(bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId ||
Expand Down
81 changes: 81 additions & 0 deletions modules/admaruBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

const ADMARU_ENDPOINT = 'https://p1.admaru.net/AdCall';
const BIDDER_CODE = 'admaru';

const DEFAULT_BID_TTL = 360;

function parseBid(rawBid, currency) {
const bid = {};

bid.cpm = rawBid.price;
bid.impid = rawBid.impid;
bid.requestId = rawBid.impid;
bid.netRevenue = true;
bid.dealId = '';
bid.creativeId = rawBid.crid;
bid.currency = currency;
bid.ad = rawBid.adm;
bid.width = rawBid.w;
bid.height = rawBid.h;
bid.mediaType = BANNER;
bid.ttl = DEFAULT_BID_TTL;

return bid;
}

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

isBidRequestValid: function (bid) {
return !!(bid && bid.params && bid.params.pub_id && bid.params.adspace_id);
},

buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bid => {
const payload = {
pub_id: bid.params.pub_id,
adspace_id: bid.params.adspace_id,
bidderRequestId: bid.bidderRequestId,
bidId: bid.bidId
};

return {
method: 'GET',
url: ADMARU_ENDPOINT,
data: payload,
}
})
},

interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
let bid = null;

if (!serverResponse.hasOwnProperty('body') || !serverResponse.body.hasOwnProperty('seatbid')) {
return bidResponses;
}

const serverBody = serverResponse.body;
const seatbid = serverBody.seatbid;

for (let i = 0; i < seatbid.length; i++) {
if (!seatbid[i].hasOwnProperty('bid')) {
continue;
}

const innerBids = seatbid[i].bid;
for (let j = 0; j < innerBids.length; j++) {
bid = parseBid(innerBids[j], serverBody.cur);

bidResponses.push(bid);
}
}

return bidResponses;
}
}

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

```
Module Name: Admaru Bidder Adapter
Module Type: Bidder Adapter
Maintainer: support@admaru.com
```

# Description

Module that connects to Admaru demand sources

# Test Parameters
```
var adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [[300, 250]], // a display size
}
},
bids: [
{
bidder: "admaru",
params: {
pub_id: '1234', // string - required
adspace_id: '1234' // string - required
}
}
]
}
];
```
16 changes: 11 additions & 5 deletions modules/betweenBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const spec = {
mediaType: serverResponse.body[i].mediaType,
ttl: serverResponse.body[i].ttl,
creativeId: serverResponse.body[i].creativeid,
currency: serverResponse.body[i].currency || 'RUB',
currency: serverResponse.body[i].currency || 'USD',
netRevenue: serverResponse.body[i].netRevenue || true,
ad: serverResponse.body[i].ad,
meta: {
Expand Down Expand Up @@ -158,10 +158,16 @@ export const spec = {
// type: 'iframe',
// url: 'https://acdn.adnxs.com/dmp/async_usersync.html'
// });
syncs.push({
type: 'iframe',
url: 'https://ads.betweendigital.com/sspmatch-iframe'
});
syncs.push(
{
type: 'iframe',
url: 'https://ads.betweendigital.com/sspmatch-iframe'
},
{
type: 'image',
url: 'https://ads.betweendigital.com/sspmatch'
}
);
return syncs;
}
}
Expand Down
29 changes: 25 additions & 4 deletions modules/colossussspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,33 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: (validBidRequests, bidderRequest) => {
const winTop = getWindowTop();
const location = winTop.location;
let deviceWidth = 0;
let deviceHeight = 0;
let winLocation;

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

const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.referer;
let refferLocation;
try {
refferLocation = refferUrl && new URL(refferUrl);
} catch (e) {
logMessage(e);
}

const location = refferLocation || winLocation;
let placements = [];
let request = {
deviceWidth: winTop.screen.width,
deviceHeight: winTop.screen.height,
deviceWidth,
deviceHeight,
language: (navigator && navigator.language) ? navigator.language : '',
secure: location.protocol === 'https:' ? 1 : 0,
host: location.host,
Expand Down
Loading

0 comments on commit b9b33a5

Please sign in to comment.