Skip to content

Commit

Permalink
VIS.X Bid Adapter: check ad slot existence (prebid#7730)
Browse files Browse the repository at this point in the history
* VIS.X: add ad slot check

* VIS.X: update ad slot check helpers

Co-authored-by: Vladimir Fedoseev <[email protected]>
  • Loading branch information
2 people authored and Chris Pabst committed Jan 10, 2022
1 parent 41eb33d commit 955eb36
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 12 deletions.
21 changes: 19 additions & 2 deletions modules/visxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { triggerPixel, parseSizesInput, deepAccess, logError } from '../src/utils.js';
import { triggerPixel, parseSizesInput, deepAccess, logError, getGptSlotInfoForAdUnitCode } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
Expand Down Expand Up @@ -241,7 +241,7 @@ function makeVideo(videoParams = {}) {
}

function buildImpObject(bid) {
const { params: { uid }, bidId, mediaTypes, sizes } = bid;
const { params: { uid }, bidId, mediaTypes, sizes, adUnitCode } = bid;
const video = mediaTypes && _isVideoBid(bid) && _isValidVideoBid(bid) && makeVideo(mediaTypes.video);
const banner = makeBanner((mediaTypes && mediaTypes.banner) || (!video && { sizes }));
const impObject = {
Expand All @@ -253,6 +253,10 @@ function buildImpObject(bid) {
}
};

if (impObject.banner) {
impObject.ext.bidder.adslotExists = _isAdSlotExists(adUnitCode);
}

if (impObject.ext.bidder.uid && (impObject.banner || impObject.video)) {
return impObject;
}
Expand Down Expand Up @@ -355,4 +359,17 @@ function _isValidVideoBid(bid, logErrors = false) {
return result;
}

function _isAdSlotExists(adUnitCode) {
if (document.getElementById(adUnitCode)) {
return true;
}

const gptAdSlot = getGptSlotInfoForAdUnitCode(adUnitCode);
if (gptAdSlot && gptAdSlot.divId && document.getElementById(gptAdSlot.divId)) {
return true;
}

return false;
}

registerBidder(spec);
10 changes: 4 additions & 6 deletions modules/visxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```
Module Name: YOC VIS.X Bidder Adapter
Module Type: Bidder Adapter
Maintainer: service@yoc.com
Maintainer: supply.partners@yoc.com
```

# Description
Expand Down Expand Up @@ -47,16 +47,14 @@ var adUnits = [
}
]
},
// YOC In-stream adUnit
// In-stream video adUnit
{
code: 'instream-test-div',
mediaTypes: {
video: {
context: 'instream',
playerSize: [400, 300],
mimes: ['video/mp4'],
protocols: [3, 6]
},
playerSize: [400, 300]
}
},
bids: [
{
Expand Down
124 changes: 120 additions & 4 deletions test/spec/modules/visxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spec } from 'modules/visxBidAdapter.js';
import { config } from 'src/config.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import * as utils from 'src/utils.js';
import { makeSlot } from '../integration/faker/googletag.js';

describe('VisxAdapter', function () {
const adapter = newBidder(spec);
Expand Down Expand Up @@ -145,17 +146,17 @@ describe('VisxAdapter', function () {
const expectedFullImps = [{
'id': '30b31c1838de1e',
'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]},
'ext': {'bidder': {'uid': 903535}}
'ext': {'bidder': {'uid': 903535, 'adslotExists': false}}
},
{
'id': '3150ccb55da321',
'banner': {'format': [{'w': 728, 'h': 90}, {'w': 300, 'h': 250}]},
'ext': {'bidder': {'uid': 903535}}
'ext': {'bidder': {'uid': 903535, 'adslotExists': false}}
},
{
'id': '42dbe3a7168a6a',
'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]},
'ext': {'bidder': {'uid': 903536}}
'ext': {'bidder': {'uid': 903536, 'adslotExists': false}}
},
{
'id': '39a4e3a7168a6a',
Expand Down Expand Up @@ -452,7 +453,122 @@ describe('VisxAdapter', function () {
'imp': [{
'id': '39aff3a7169a6a',
'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]},
'ext': {'bidder': {'uid': 903538}}
'ext': {'bidder': {'uid': 903538, 'adslotExists': false}}
}],
'tmax': 3000,
'cur': ['EUR'],
'source': {
'ext': {
'wrapperType': 'Prebid_js',
'wrapperVersion': '$prebid.version$'
}
},
'site': {'page': referrer}
});
});
});

describe('buildRequests (check ad slot exists)', function () {
function parseRequest(url) {
const res = {};
(url.split('?')[1] || '').split('&').forEach((it) => {
const couple = it.split('=');
res[couple[0]] = decodeURIComponent(couple[1]);
});
return res;
}
const bidderRequest = {
timeout: 3000,
refererInfo: {
referer: 'https://example.com'
}
};
const referrer = bidderRequest.refererInfo.referer;
const bidRequests = [
{
'bidder': 'visx',
'params': {
'uid': 903535
},
'adUnitCode': 'visx-adunit-code-1',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
},
{
'bidder': 'visx',
'params': {
'uid': 903535
},
'adUnitCode': 'visx-adunit-code-2',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
}
];
let sandbox;
let documentStub;

before(function() {
sandbox = sinon.sandbox.create();
documentStub = sandbox.stub(document, 'getElementById');
documentStub.withArgs('visx-adunit-code-1').returns({
id: 'visx-adunit-code-1'
});
documentStub.withArgs('visx-adunit-element-2').returns({
id: 'visx-adunit-element-2'
});
});

after(function() {
sandbox.restore();
});

it('should find ad slot by ad unit code as element id', function () {
const request = spec.buildRequests([bidRequests[0]], bidderRequest);
const payload = parseRequest(request.url);
expect(payload).to.be.an('object');
expect(payload).to.have.property('auids', '903535');

const postData = request.data;
expect(postData).to.be.an('object');
expect(postData).to.deep.equal({
'id': '22edbae2733bf6',
'imp': [{
'id': '30b31c1838de1e',
'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]},
'ext': {'bidder': {'uid': 903535, 'adslotExists': true}}
}],
'tmax': 3000,
'cur': ['EUR'],
'source': {
'ext': {
'wrapperType': 'Prebid_js',
'wrapperVersion': '$prebid.version$'
}
},
'site': {'page': referrer}
});
});

it('should find ad slot by ad unit code as adUnitPath', function () {
makeSlot({code: 'visx-adunit-code-2', divId: 'visx-adunit-element-2'});

const request = spec.buildRequests([bidRequests[1]], bidderRequest);
const payload = parseRequest(request.url);
expect(payload).to.be.an('object');
expect(payload).to.have.property('auids', '903535');

const postData = request.data;
expect(postData).to.be.an('object');
expect(postData).to.deep.equal({
'id': '22edbae2733bf6',
'imp': [{
'id': '30b31c1838de1e',
'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]},
'ext': {'bidder': {'uid': 903535, 'adslotExists': true}}
}],
'tmax': 3000,
'cur': ['EUR'],
Expand Down

0 comments on commit 955eb36

Please sign in to comment.