Skip to content
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

oneTag Bid Adapter: bidRequest object adjustments #6105

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Changes from all 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
87 changes: 37 additions & 50 deletions modules/onetagBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Renderer } from '../src/Renderer.js';
import find from 'core-js-pure/features/array/find.js';
import { getStorageManager } from '../src/storageManager.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { createEidsArray } from './userId/eids.js';

const ENDPOINT = 'https://onetag-sys.com/prebid-request';
const USER_SYNC_ENDPOINT = 'https://onetag-sys.com/usync/';
Expand Down Expand Up @@ -63,8 +64,8 @@ function buildRequests(validBidRequests, bidderRequest) {
if (bidderRequest && bidderRequest.uspConsent) {
payload.usPrivacy = bidderRequest.uspConsent;
}
if (bidderRequest && bidderRequest.userId) {
payload.userId = bidderRequest.userId;
if (validBidRequests && validBidRequests.length !== 0 && validBidRequests[0].userId) {
payload.userId = createEidsArray(validBidRequests[0].userId);
}
try {
if (storage.hasLocalStorage()) {
Expand All @@ -88,47 +89,34 @@ function interpretResponse(serverResponse, bidderRequest) {
if (!body.bids || !Array.isArray(body.bids) || body.bids.length === 0) {
return bids;
}
body.bids.forEach(({
requestId,
cpm,
width,
height,
creativeId,
dealId,
currency,
mediaType,
ttl,
rendererUrl,
ad,
vastUrl,
videoCacheKey
}) => {
body.bids.forEach(bid => {
const responseBid = {
requestId,
cpm,
width,
height,
creativeId,
dealId: dealId == null ? dealId : '',
currency,
netRevenue: false,
requestId: bid.requestId,
cpm: bid.cpm,
width: bid.width,
height: bid.height,
creativeId: bid.creativeId,
dealId: bid.dealId == null ? bid.dealId : '',
currency: bid.currency,
netRevenue: bid.netRevenue || false,
mediaType: bid.mediaType,
meta: {
mediaType
mediaType: bid.mediaType
},
ttl: ttl || 300
ttl: bid.ttl || 300
};
if (mediaType === BANNER) {
responseBid.ad = ad;
} else if (mediaType === VIDEO) {
const {context, adUnitCode} = find(requestData.bids, (item) => item.bidId === requestId);
if (bid.mediaType === BANNER) {
responseBid.ad = bid.ad;
} else if (bid.mediaType === VIDEO) {
const {context, adUnitCode} = find(requestData.bids, (item) => item.bidId === bid.requestId);
if (context === INSTREAM) {
responseBid.vastUrl = vastUrl;
responseBid.videoCacheKey = videoCacheKey;
responseBid.vastUrl = bid.vastUrl;
responseBid.videoCacheKey = bid.videoCacheKey;
} else if (context === OUTSTREAM) {
responseBid.vastXml = ad;
responseBid.vastUrl = vastUrl;
if (rendererUrl) {
responseBid.renderer = createRenderer({requestId, rendererUrl, adUnitCode});
responseBid.vastXml = bid.ad;
responseBid.vastUrl = bid.vastUrl;
if (bid.rendererUrl) {
responseBid.renderer = createRenderer({ ...bid, adUnitCode });
}
}
}
Expand All @@ -146,25 +134,24 @@ function createRenderer(bid, rendererOptions = {}) {
loaded: false
});
try {
renderer.setRender(onetagRenderer);
renderer.setRender(({renderer, width, height, vastXml, adUnitCode}) => {
renderer.push(() => {
window.onetag.Player.init({
...bid,
width,
height,
vastXml,
nodeId: adUnitCode,
config: renderer.getConfig()
});
});
});
} catch (e) {

}
return renderer;
}

function onetagRenderer({renderer, width, height, vastXml, adUnitCode}) {
renderer.push(() => {
window.onetag.Player.init({
width,
height,
vastXml,
nodeId: adUnitCode,
config: renderer.getConfig()
});
});
}

function getFrameNesting() {
let topmostFrame = window;
let parent = window.parent;
Expand Down