Skip to content

Commit

Permalink
Merge branch 'prebid:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
fatihkaya84 authored Oct 8, 2024
2 parents f38f08a + 7ac768f commit 8ae9b54
Show file tree
Hide file tree
Showing 19 changed files with 1,071 additions and 18 deletions.
7 changes: 7 additions & 0 deletions libraries/ortbConverter/processors/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export const DEFAULT_PROCESSORS = {
if (bid.ext?.dsa) {
bidResponse.meta.dsa = bid.ext.dsa;
}
if (bid.cat) {
bidResponse.meta.primaryCatId = bid.cat[0];
bidResponse.meta.secondaryCatIds = bid.cat.slice(1);
}
if (bid.attr) {
bidResponse.meta.attr = bid.attr;
}
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions libraries/vastTrackers/vastTrackers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ import {activityParams} from '../../src/activities/activityParams.js';

const vastTrackers = [];

addBidResponse.before(function (next, adUnitcode, bidResponse, reject) {
export function reset() {
vastTrackers.length = 0;
}

export function addTrackersToResponse(next, adUnitcode, bidResponse, reject) {
if (FEATURES.VIDEO && bidResponse.mediaType === VIDEO) {
const vastTrackers = getVastTrackers(bidResponse);
if (vastTrackers) {
bidResponse.vastXml = insertVastTrackers(vastTrackers, bidResponse.vastXml);
const impTrackers = vastTrackers.get('impressions');
if (impTrackers) {
bidResponse.vastImpUrl = [].concat(impTrackers).concat(bidResponse.vastImpUrl).filter(t => t);
bidResponse.vastImpUrl = [].concat([...impTrackers]).concat(bidResponse.vastImpUrl).filter(t => t);
}
}
}
next(adUnitcode, bidResponse, reject);
});
}
addBidResponse.before(addTrackersToResponse);

export function registerVastTrackers(moduleType, moduleName, trackerFn) {
if (typeof trackerFn === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion libraries/vidazooUtils/bidderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export function createBuildRequestsFn(createRequestDomain, createUniqueRequestDa

return function buildRequests(validBidRequests, bidderRequest) {
const topWindowUrl = bidderRequest.refererInfo.page || bidderRequest.refererInfo.topmostLocation;
const bidderTimeout = config.getConfig('bidderTimeout');
const bidderTimeout = bidderRequest.timeout || config.getConfig('bidderTimeout');

const singleRequestMode = allowSingleRequest && config.getConfig(`${bidderCode}.singleRequest`);

Expand Down
40 changes: 40 additions & 0 deletions modules/bidResponseFilter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { auctionManager } from '../../src/auctionManager.js';
import { config } from '../../src/config.js';
import { getHook } from '../../src/hook.js';

export const MODULE_NAME = 'bidResponseFilter';
export const BID_CATEGORY_REJECTION_REASON = 'Category is not allowed';
export const BID_ADV_DOMAINS_REJECTION_REASON = 'Adv domain is not allowed';
export const BID_ATTR_REJECTION_REASON = 'Attr is not allowed';

function init() {
getHook('addBidResponse').before(addBidResponseHook);
};

export function addBidResponseHook(next, adUnitCode, bid, reject, index = auctionManager.index) {
const {bcat = [], badv = []} = index.getOrtb2(bid) || {};
const battr = index.getBidRequest(bid)?.ortb2Imp[bid.mediaType]?.battr || index.getAdUnit(bid)?.ortb2Imp[bid.mediaType]?.battr || [];
const moduleConfig = config.getConfig(MODULE_NAME);

const catConfig = {enforce: true, blockUnknown: true, ...(moduleConfig?.cat || {})};
const advConfig = {enforce: true, blockUnknown: true, ...(moduleConfig?.adv || {})};
const attrConfig = {enforce: true, blockUnknown: true, ...(moduleConfig?.attr || {})};

const { primaryCatId, secondaryCatIds = [], advertiserDomains = [], attr: metaAttr } = bid.meta || {};

// checking if bid fulfills ortb2 fields rules
if ((catConfig.enforce && bcat.some(category => [primaryCatId, ...secondaryCatIds].includes(category))) ||
(catConfig.blockUnknown && !primaryCatId)) {
reject(BID_CATEGORY_REJECTION_REASON);
} else if ((advConfig.enforce && badv.some(domain => advertiserDomains.includes(domain))) ||
(advConfig.blockUnknown && !advertiserDomains.length)) {
reject(BID_ADV_DOMAINS_REJECTION_REASON);
} else if ((attrConfig.enforce && battr.includes(metaAttr)) ||
(attrConfig.blockUnknown && !metaAttr)) {
reject(BID_ATTR_REJECTION_REASON);
} else {
return next(adUnitCode, bid, reject);
}
}

init();
2 changes: 1 addition & 1 deletion modules/smartytechBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```
Module Name: SmartyTech Bid Adapter
Module Type: Bidder Adapter
Maintainer: info@adpartner.pro
Maintainer: info@fusify.io
```

# Description
Expand Down
19 changes: 19 additions & 0 deletions modules/smootBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { isBidRequestValid, buildRequests, interpretResponse, getUserSyncs } from '../libraries/teqblazeUtils/bidderUtils.js';

const BIDDER_CODE = 'smoot';
const AD_URL = 'https://endpoint1.smoot.ai/pbjs';
const SYNC_URL = 'https://usync.smxconv.com';

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

isBidRequestValid: isBidRequestValid(['placementId']),
buildRequests: buildRequests(AD_URL),
interpretResponse,
getUserSyncs: getUserSyncs(SYNC_URL)
};

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

```
Module Name: Smoot Bidder Adapter
Module Type: Smoot Bidder Adapter
Maintainer: it.ops@smoot.ai
```

# Description

Connects to Smoot exchange for bids.
Smoot 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: 'smoot',
params: {
placementId: 'testBanner',
}
}
]
},
{
code: 'addunit2',
mediaTypes: {
video: {
playerSize: [ [640, 480] ],
context: 'instream',
minduration: 5,
maxduration: 60,
}
},
bids: [
{
bidder: 'smoot',
params: {
placementId: 'testVideo',
}
}
]
},
{
code: 'addunit3',
mediaTypes: {
native: {
title: {
required: true
},
body: {
required: true
},
icon: {
required: true,
size: [64, 64]
}
}
},
bids: [
{
bidder: 'smoot',
params: {
placementId: 'testNative',
}
}
]
}
];
```
3 changes: 3 additions & 0 deletions src/auctionIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export function AuctionIndex(getAuctions) {
.flatMap(ber => ber.bids)
.find(br => br && br.bidId === requestId);
}
},
getOrtb2(bid) {
return this.getBidderRequest(bid)?.ortb2 || this.getAuction(bid)?.getFPD()?.global?.ortb2
}
});
}
19 changes: 19 additions & 0 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ function validateSizes(sizes, targLength) {
return cleanSizes;
}

export function setBattrForAdUnit(adUnit, mediaType) {
const ortb2Imp = adUnit.ortb2Imp || {};
const mediaTypes = adUnit.mediaTypes || {};

if (ortb2Imp[mediaType]?.battr && mediaTypes[mediaType]?.battr && (ortb2Imp[mediaType]?.battr !== mediaTypes[mediaType]?.battr)) {
logWarn(`Ad unit ${adUnit.code} specifies conflicting ortb2Imp.${mediaType}.battr and mediaTypes.${mediaType}.battr, the latter will be ignored`, adUnit);
}

const battr = ortb2Imp[mediaType]?.battr || mediaTypes[mediaType]?.battr;

if (battr != null) {
deepSetValue(adUnit, `ortb2Imp.${mediaType}.battr`, battr);
deepSetValue(adUnit, `mediaTypes.${mediaType}.battr`, battr);
}
}

function validateBannerMediaType(adUnit) {
const validatedAdUnit = deepClone(adUnit);
const banner = validatedAdUnit.mediaTypes.banner;
Expand All @@ -112,6 +128,7 @@ function validateBannerMediaType(adUnit) {
logError('Detected a mediaTypes.banner object without a proper sizes field. Please ensure the sizes are listed like: [[300, 250], ...]. Removing invalid mediaTypes.banner object from request.');
delete validatedAdUnit.mediaTypes.banner
}
setBattrForAdUnit(validatedAdUnit, 'banner');
return validatedAdUnit;
}

Expand All @@ -135,6 +152,7 @@ function validateVideoMediaType(adUnit) {
}
}
validateOrtbVideoFields(validatedAdUnit);
setBattrForAdUnit(validatedAdUnit, 'video');
return validatedAdUnit;
}

Expand Down Expand Up @@ -184,6 +202,7 @@ function validateNativeMediaType(adUnit) {
logError('Please use an array of sizes for native.icon.sizes field. Removing invalid mediaTypes.native.icon.sizes property from request.');
delete validatedAdUnit.mediaTypes.native.icon.sizes;
}
setBattrForAdUnit(validatedAdUnit, 'native');
return validatedAdUnit;
}

Expand Down
43 changes: 33 additions & 10 deletions test/spec/libraries/vastTrackers_spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import {addImpUrlToTrackers, getVastTrackers, insertVastTrackers, registerVastTrackers} from 'libraries/vastTrackers/vastTrackers.js';
import {
addImpUrlToTrackers,
addTrackersToResponse,
getVastTrackers,
insertVastTrackers,
registerVastTrackers,
reset
} from 'libraries/vastTrackers/vastTrackers.js';
import {MODULE_TYPE_ANALYTICS} from '../../../src/activities/modules.js';

describe('vast trackers', () => {
beforeEach(() => {
registerVastTrackers(MODULE_TYPE_ANALYTICS, 'test', function(bidResponse) {
return [
{'event': 'impressions', 'url': `https://vasttracking.mydomain.com/vast?cpm=${bidResponse.cpm}`}
];
});
})
afterEach(() => {
reset();
});

it('insert into tracker list', function() {
let trackers = getVastTrackers({'cpm': 1.0});
if (!trackers || !trackers.get('impressions')) {
registerVastTrackers(MODULE_TYPE_ANALYTICS, 'test', function(bidResponse) {
return [
{'event': 'impressions', 'url': `https://vasttracking.mydomain.com/vast?cpm=${bidResponse.cpm}`}
];
});
}
trackers = getVastTrackers({'cpm': 1.0});
const trackers = getVastTrackers({'cpm': 1.0});
expect(trackers).to.be.a('map');
expect(trackers.get('impressions')).to.exists;
expect(trackers.get('impressions').has('https://vasttracking.mydomain.com/vast?cpm=1')).to.be.true;
Expand All @@ -30,4 +40,17 @@ describe('vast trackers', () => {
expect(trackers.get('impressions')).to.exists;
expect(trackers.get('impressions').has('imptracker.com')).to.be.true;
});

if (FEATURES.VIDEO) {
it('should add trackers to bid response', () => {
const bidResponse = {
mediaType: 'video',
cpm: 1
}
addTrackersToResponse(sinon.stub(), 'au', bidResponse);
expect(bidResponse.vastImpUrl).to.eql([
'https://vasttracking.mydomain.com/vast?cpm=1'
])
});
}
})
1 change: 1 addition & 0 deletions test/spec/modules/ads_interactiveBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ describe('AdsInteractiveBidAdapter', function () {
expect(data).to.have.all.keys(
'deviceWidth',
'deviceHeight',
'device',
'language',
'secure',
'host',
Expand Down
Loading

0 comments on commit 8ae9b54

Please sign in to comment.