Skip to content

Oculus 82 locate ad slot element by ad slot path #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { registerBidder } from '../src/adapters/bidderFactory';
import { config } from '../src/config';
import * as utils from '../src/utils';

const { registerBidder } = require('../src/adapters/bidderFactory');
const { config } = require('../src/config');

const BIDDER_CODE = '33across';
const END_POINT = 'https://ssc.33across.com/api/v1/hb';
const SYNC_ENDPOINT = 'https://de.tynt.com/deb/v2?m=xch&rt=html';
Expand Down Expand Up @@ -32,17 +31,41 @@ function _isViewabilityMeasurable(element) {
}

function _getViewability(element, topWin, { w, h } = {}) {
return utils.getWindowTop().document.visibilityState === 'visible'
return topWin.document.visibilityState === 'visible'
? _getPercentInView(element, topWin, { w, h })
: 0;
}

function _mapAdUnitPathToElementId(adUnitCode) {
let id = null;

if (utils.isGptPubadsDefined()) {
const isMatchingAdSlot = utils.isSlotMatchingAdUnitCode(adUnitCode);
const matchingAdSlot = window.googletag.pubads().getSlots().find(isMatchingAdSlot);

if (matchingAdSlot) {
id = matchingAdSlot.getSlotElementId();

utils.logInfo(`[33Across Adapter] Map ad unit path to HTML element id: '${adUnitCode}' -> '${id}'`);
}
}

utils.logWarn(`[33Across Adapter] Unable to locate element for ad unit code: '${adUnitCode}'`);

return null;
}

function _getAdSlotHTMLElement(adUnitCode) {
return document.getElementById(adUnitCode) ||
document.getElementById(_mapAdUnitPathToElementId(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) {
const ttxRequest = {};
const params = bidRequest.params;
const element = document.getElementById(bidRequest.adUnitCode);
const element = _getAdSlotHTMLElement(bidRequest.adUnitCode);
const sizes = _transformSizes(bidRequest.sizes);
const minSize = _getMinSize(sizes);

Expand All @@ -52,10 +75,6 @@ function _createServerRequest(bidRequest, gdprConsent) {

const contributeViewability = ViewabilityContributor(viewabilityAmount);

if (element === null) {
utils.logWarn(`Unable to locate element with id: '${bidRequest.adUnitCode}'`);
}

/*
* Infer data for the request payload
*/
Expand Down Expand Up @@ -264,13 +283,19 @@ function isBidRequestValid(bid) {
// - the server, at this point, also doesn't need the consent string to handle gdpr compliance. So passing
// value whether set or not, for the sake of future dev.
function buildRequests(bidRequests, bidderRequest) {
const gdprConsent = Object.assign({ consentString: undefined, gdprApplies: false }, bidderRequest && bidderRequest.gdprConsent);
// const gdprConsent = Object.assign({
// consentString: undefined,
// gdprApplies: false
// }, bidderRequest && bidderRequest.gdprConsent);
const gdprConsent = {
gdprApplies: false,
consentString: undefined, // see comment about this
...(bidderRequest && bidderRequest.gdprConsent)
};

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

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

// NOTE: At this point, the response from 33exchange will only ever contain one bid i.e. the highest bid
Expand Down
2 changes: 1 addition & 1 deletion modules/33acrossBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Connects to 33Across's exchange for bids.
```
var adUnits = [
{
code: '33across-hb-ad-123456-1',
code: '33across-hb-ad-123456-1', // ad slot HTML element ID
sizes: [
[300, 250],
[728, 90]
Expand Down
4 changes: 2 additions & 2 deletions test/spec/modules/33acrossBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ describe('33acrossBidAdapter:', function () {

utils.getWindowTop.restore();
utils.getWindowSelf.restore();
sandbox.stub(utils, 'getWindowTop').returns(win);
sandbox.stub(utils, 'getWindowSelf').returns({});
sandbox.stub(utils, 'getWindowTop').returns({});
sandbox.stub(utils, 'getWindowSelf').returns(win);

expect(spec.buildRequests(bidRequests)).to.deep.equal([ serverRequest ]);
});
Expand Down