Skip to content

Commit

Permalink
33Across: Adding floors support (#5408)
Browse files Browse the repository at this point in the history
* check gdpr in buildRequest

* User sync based on whether gdpr applies or not

* check if consent data exists during user sync

* split user sync into further branches: 1) when gdpr does not apply 2) when consent data is unavailable

* contribute viewability to ttxRequest

* update tests

* remove window mock from tests

* use local variables

* introduce ServerRequestBuilder

* add withOptions() method to ServerRequestBuilder

* add semicolons

* sync up package-lock.json with upstream/master

* stub window.top in tests

* introduce getTopWindowSize() for test purpose

* reformat code

* add withSite() method to TtxRequestBuilder

add withSite() method to TtxRequestBuilder

* add isIframe() and _isViewabilityMeasurable()

* handle NON_MEASURABLE viewability in nested iframes

* consider page visibility, stub utils functions getWindowTop() and getWindowSelf()

* contribute viewability as 0 for inactive tab

* add prebidjs version to ttx request

* send caller as an array

* fix JSDoc in utils.js

* send viewability as non measurable when unable to locate target HTMLElement, add warning message

* introduce mapAdSlotPathToElementId()

* introduce getAdSlotHTMLElement(), add logging

* introduce mapAdSlotPathToElementId()

* update logging in ad unit path to element id mapping

* rephrase logging, fix tests

* update adapter documentation

* remove excessive logging

* improve logging

* revert change

* fix return of _mapAdUnitPathToElementId()

* improve logging of _mapAdUnitPathToElementId()

* do not use Array.find()

* return id once element is found

* return id once element is found

* let -> const

* Removing killswitch behavior for GDPR

* Updated comments to reflect current gdpr logic

* URI encode consent string

* Updated example site ID to help Prebid team e2e test our adapter

* send page url in ortb

* Removed redundant pageUrl default

* Restored package-log.json that mirrors prebid's repo

* Sending USP string during buildRequest

* Adding USP consent data to user sync

* add unit test for syncing without bidrequest

* Changed to uspConsent to make the connatation consistent

* Resetting adapter state in adapter after user sync rather than exposing it.

* removed console log

* Adding schain info

* remove setting empty format ext

* better tests invalid values

* removing validation of schain

* Fixed lint errors

* First cut for bidfloors support

* fixed where getFloors is read

* fixed merge conflicts

Co-authored-by: Gleb Glushtsov <gleb.glushtsov@33across.com>
Co-authored-by: Gleb Glushtsov <glebglushtsov@users.noreply.github.com>
Co-authored-by: Gleb Glushtsov <gleb.glushtsov@gmail.com>
Co-authored-by: Aparna Hegde <ahegde@pool-10-1-150-29-nyc.internal.33across.com>
Co-authored-by: Aparna Hegde <ahegde@admins-MacBook-Pro.local>
Co-authored-by: Aparna Hegde <ahegde@pool-10-1-150-137-nyc.internal.33across.com>
Co-authored-by: Aparna Hegde <ahegde@pool-10-1-150-96-nyc.internal.33across.com>
Co-authored-by: Aparna Hegde <ahegde@AHEGDE-MAC.local>
Co-authored-by: Aparna Hegde <ahegde@AHEGDE-MAC.fios-router.home>
  • Loading branch information
10 people authored Jun 23, 2020
1 parent d9d7c0c commit 18d1e10
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 3 deletions.
49 changes: 46 additions & 3 deletions modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as utils from '../src/utils.js';
const BIDDER_CODE = '33across';
const END_POINT = 'https://ssc.33across.com/api/v1/hb';
const SYNC_ENDPOINT = 'https://ssc-cms.33across.com/ps/?m=xch&rt=html&ru=deb';
const MEDIA_TYPE = 'banner';
const CURRENCY = 'USD';

const adapterState = {
uniqueSiteIds: []
Expand Down Expand Up @@ -67,11 +69,27 @@ function _getAdSlotHTMLElement(adUnitCode) {

// Infer the necessary data from valid bid for a minimal ttxRequest and create HTTP request
// NOTE: At this point, TTX only accepts request for a single impression
function _createServerRequest(bidRequest, gdprConsent = {}, uspConsent, pageUrl) {
function _createServerRequest({bidRequest, gdprConsent = {}, uspConsent, pageUrl}) {
const ttxRequest = {};
const params = bidRequest.params;
const element = _getAdSlotHTMLElement(bidRequest.adUnitCode);
const sizes = _transformSizes(bidRequest.sizes);

let format;

// We support size based bidfloors so obtain one if there's a rule associated
if (typeof bidRequest.getFloor === 'function') {
let getFloor = bidRequest.getFloor.bind(bidRequest);

format = sizes.map((size) => {
const formatExt = _getBidFloors(getFloor, size);

return Object.assign({}, size, formatExt);
});
} else {
format = sizes;
}

const minSize = _getMinSize(sizes);

const viewabilityAmount = _isViewabilityMeasurable(element)
Expand All @@ -86,7 +104,7 @@ function _createServerRequest(bidRequest, gdprConsent = {}, uspConsent, pageUrl)
ttxRequest.imp = [];
ttxRequest.imp[0] = {
banner: {
format: sizes
format
},
ext: {
ttx: {
Expand Down Expand Up @@ -179,6 +197,24 @@ function _createSync({ siteId = 'zzz000000000003zzz', gdprConsent = {}, uspConse
return sync;
}

function _getBidFloors(getFloor, size) {
const bidFloors = getFloor({
currency: CURRENCY,
mediaType: MEDIA_TYPE,
size: [ size.w, size.h ]
});

if (!isNaN(bidFloors.floor) && (bidFloors.currency === CURRENCY)) {
return {
ext: {
ttx: {
bidfloors: [ bidFloors.floor ]
}
}
}
}
}

function _getSize(size) {
return {
w: parseInt(size[0], 10),
Expand Down Expand Up @@ -320,7 +356,14 @@ function buildRequests(bidRequests, bidderRequest) {

adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(utils.uniques);

return bidRequests.map(req => _createServerRequest(req, gdprConsent, uspConsent, pageUrl));
return bidRequests.map(bidRequest => _createServerRequest(
{
bidRequest,
gdprConsent,
uspConsent,
pageUrl
})
);
}

// NOTE: At this point, the response from 33exchange will only ever contain one bid i.e. the highest bid
Expand Down
67 changes: 67 additions & 0 deletions test/spec/modules/33acrossBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ describe('33acrossBidAdapter:', function () {
return this;
};

this.withFormatFloors = floors => {
const format = ttxRequest.imp[0].banner.format.map((fm, i) => {
return Object.assign(fm, {
ext: {
ttx: {
bidfloors: [ floors[i] ]
}
}
})
});

ttxRequest.imp[0].banner.format = format;

return this;
};

this.build = () => ttxRequest;
}

Expand Down Expand Up @@ -667,6 +683,57 @@ describe('33acrossBidAdapter:', function () {
expect(builtServerRequests).to.deep.equal([serverRequest]);
});
});

context('when price floor module is not enabled in bidRequest', function() {
it('does not set any bidfloors in ttxRequest', function() {
const ttxRequest = new TtxRequestBuilder()
.build();
const serverRequest = new ServerRequestBuilder()
.withData(ttxRequest)
.build();
const builtServerRequests = spec.buildRequests(bidRequests, {});

expect(builtServerRequests).to.deep.equal([serverRequest]);
});
});

context('when price floor module is enabled in bidRequest', function() {
it('does not set any bidfloors in ttxRequest if there is no floor', function() {
bidRequests[0].getFloor = () => ({});

const ttxRequest = new TtxRequestBuilder()
.build();
const serverRequest = new ServerRequestBuilder()
.withData(ttxRequest)
.build();
const builtServerRequests = spec.buildRequests(bidRequests, {});

expect(builtServerRequests).to.deep.equal([serverRequest]);
});

it('sets bidfloors in ttxRequest if there is a floor', function() {
bidRequests[0].getFloor = ({size, currency, mediaType}) => {
const floor = (size[0] === 300 && size[1] === 250) ? 1.0 : 0.10
return (
{
floor,
currency: 'USD'
}
);
};

const ttxRequest = new TtxRequestBuilder()
.withFormatFloors([ 1.0, 0.10 ])
.build();

const serverRequest = new ServerRequestBuilder()
.withData(ttxRequest)
.build();
const builtServerRequests = spec.buildRequests(bidRequests, {});

expect(builtServerRequests).to.deep.equal([serverRequest]);
});
});
});

describe('interpretResponse', function() {
Expand Down

0 comments on commit 18d1e10

Please sign in to comment.