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

Showheroes update #4

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
86 changes: 30 additions & 56 deletions modules/showheroes-bsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const converter = ortbConverter({
netRevenue: true,
ttl: TTL,
currency: 'EUR',
mediaType: VIDEO,
},
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
Expand Down Expand Up @@ -55,6 +56,24 @@ const converter = ortbConverter({
(req?.device?.sua) && delete req.device['sua'];
return req;
},

bidResponse(buildBidResponse, bid, context) {
const bidResponse = buildBidResponse(bid, context);

if (context.imp?.ext?.mediaType === 'outstream') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks suspicious, maybe you wanted to write:

if (bidResponse.mediaType === VIDEO && bidRequest.mediaTypes.video.context === 'outstream') {

const renderConfig = {
rendererUrl: bid.ext?.rendererConfig?.rendererUrl,
renderFunc: bid.ext?.rendererConfig?.renderFunc,
renderOptions: bid.ext?.rendererConfig?.renderOptions,
};
if (renderConfig.renderFunc && renderConfig.rendererUrl) {
bidResponse.renderer = createRenderer(bidResponse, renderConfig);
}
}
bidResponse.callbacks = bid.ext.callbacks;
bidResponse.extra = bid.ext?.extra;
return bidResponse;
},
})

const GVLID = 111;
Expand All @@ -79,7 +98,12 @@ export const spec = {
};
},
interpretResponse: (response, request) => {
return createBids(response.body, request.data);
if (!response.body) {
return [];
}

const bids = converter.fromORTB({response: response.body, request: request.data}).bids;
return bids;
},
getUserSyncs: (syncOptions, serverResponses) => {
const syncs = [];
Expand Down Expand Up @@ -121,68 +145,18 @@ export const spec = {
},
};

function createBids(bidRes, bidReq) {
if (!bidRes || !bidRes.seatbid) {
return [];
}
const bids = [];

bidRes.seatbid.forEach((seatbid) => {
if (!seatbid.bid?.length) {
return;
}
seatbid.bid.forEach((bid) => {
const imp = bidReq.imp.find((imp) => imp.id === bid.impid);
const bidUnit = {
cpm: bid.price,
requestId: bid.impid,
adUnitCode: imp?.ext?.adUnitCode,
currency: bidRes.cur,
mediaType: VIDEO,
ttl: bid.exp || TTL,
netRevenue: true,
extra: bid.extra,
width: bid.w,
height: bid.h,
creativeId: bid.crid,
callbacks: bid?.ext?.callbacks,
meta: {
advertiserDomains: bid.adomain || [],
},
};
if (bid.adm) {
bidUnit.vastXml = bid.adm;
bidUnit.adResponse = {
content: bid.adm,
};
}
if (bid.nurl) {
bidUnit.vastUrl = bid.nurl;
}
if (imp?.ext?.mediaType === 'outstream') {
const renderConfig = {
rendererUrl: bid.ext?.rendererConfig?.rendererUrl,
renderFunc: bid.ext?.rendererConfig?.renderFunc,
renderOptions: bid.ext?.rendererConfig?.renderOptions,
};
if (renderConfig.renderFunc && renderConfig.rendererUrl) {
bidUnit.renderer = createRenderer(bidUnit, renderConfig);
}
};
bids.push(bidUnit);
});
});

return bids;
}

function outstreamRender(response, renderConfig) {
response.renderer.push(() => {
const func = deepAccess(window, renderConfig.renderFunc);
if (!isFn(func)) {
return;
}
const renderPayload = { ...response, ...renderConfig.renderOptions };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of object is response?
If I'm not wrong is something out of our direct control, coming from Prebid.js.
I'm wondering if it is ok to mix response and renderOptions, this might lead to some unwanted properties override.

Moreover it's not clear the contract between the renderer function and the argument it can receive.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left like that on purpose. To be free to change/modify from the backend side whatever we want.
I didn't know what else to do. Right now we are serving appnexus renderer and we want to change that with showheroes renderer. So, to be able to control from the backend side without opening another PR in the pbjs repo.

I know it's not ideal, I know it's ugly and error-prone. But, until we don't have our renderer in place, I really don't see the other way. Then we can open a PR in pbjs and cleanup the mess that is left behind.

Another option is to hardcode appnexus renderer inside pbjs, and then 2nd PR to replace it with ours. Code would be a lot cleaner. Let me know what you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just looking at the ANOutstreamVideo.renderAd arguments and how other bidders are using it (simplest one).

Maybe it's better to explicitly return the object passed to the renderer directly from the server response

function outstreamRender(response, renderConfig) {
  response.renderer.push(() => {
    const func = deepAccess(window, renderConfig.renderFunc);
    if (!isFn(func)) {
      return;
    }
    func(renderConfig.renderOptions);
  });
}

This means that adserver must be changed with:

if media_type == settings.PREBID_FORMAT_OUTSTREAM:
    openrtb_bid.ext["rendererConfig"] = {
        "rendererUrl": RENDERER_URL,
        "renderFunc": "ANOutstreamVideo.renderAd",
        "renderOptions": {
            "showBigPlayButton": False,
            "showProgressBar": "bar",
            "skippable": False,
            "targetId": adunit_code,
            "adResponse": {
                "content": winning_xml
            }
        },
    }

if (renderPayload.vastXml) {
renderPayload.adResponse = {
content: renderPayload.vastXml,
};
}
func(renderPayload);
});
}
Expand Down
14 changes: 4 additions & 10 deletions test/spec/modules/showheroes-bsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ describe('shBidAdapter', () => {
});

describe('interpretResponse', function () {
it('handles nobid responses', function () {
expect(spec.interpretResponse({ body: {} }, { data: { meta: {} } }).length).to.equal(0)
expect(spec.interpretResponse({ body: [] }, { data: { meta: {} } }).length).to.equal(0)
})

const vastXml = '<?xml version="1.0" encoding="utf-8"?><VAST version="3.0"><Error><![CDATA[https://static.showheroes.com/shim.gif]]></Error></VAST>'

const callback_won = 'https://test.com/track/?ver=15&session_id=01ecd03ce381505ccdeb88e555b05001&category=request_session&type=event&request_session_id=01ecd03ce381505ccdeb88e555b05001&label=prebid_won&reason=ok'
Expand All @@ -139,12 +134,12 @@ describe('shBidAdapter', () => {
adm: vastXml,
impid: '38b373e1e31c18',
crid: 'c_38b373e1e31c18',
extra: 'test',
adomain: adomain,
ext: {
callbacks: {
won: [callback_won],
},
extra: 'test',
},
}],
seat: 'showheroes',
Expand All @@ -158,10 +153,12 @@ describe('shBidAdapter', () => {
{
cpm: 1,
creativeId: 'c_38b373e1e31c18',
adUnitCode: 'adunit-code-1',
creative_id: 'c_38b373e1e31c18',
currency: 'EUR',
width: 640,
height: 480,
playerHeight: 480,
playerWidth: 640,
mediaType: 'video',
netRevenue: true,
requestId: '38b373e1e31c18',
Expand All @@ -170,9 +167,6 @@ describe('shBidAdapter', () => {
advertiserDomains: adomain
},
vastXml: vastXml,
adResponse: {
content: vastXml,
},
callbacks: {
won: [callback_won],
},
Expand Down