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 Bid Adapter: add new endpoint #8816

Merged
merged 37 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d0b644d
add ShowHeroes Adapter
vadim-mazzherin Apr 10, 2019
b6c0154
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Sep 23, 2019
bfcdb91
ShowHeroes adapter - expanded outstream support
vadim-mazzherin Sep 23, 2019
c2e4686
Revert "ShowHeroes adapter - expanded outstream support"
vadim-mazzherin Sep 23, 2019
6c57d09
ShowHeroes adapter - expanded outstream support
vadim-mazzherin Sep 23, 2019
f10b01f
Merge branch 'master' of https://github.com/prebid/Prebid.js
veranevera Oct 1, 2019
6b36284
ShowHeroes adapter - fixes (#4222)
veranevera Oct 1, 2019
2f7f6e6
Merge branch 'master' of https://github.com/prebid/Prebid.js
veranevera Oct 7, 2019
c701851
ShowHeroes adapter - banner and outstream fixes (#4222)
veranevera Oct 7, 2019
3ea3260
Merge branch 'master' of https://github.com/prebid/Prebid.js
veranevera Oct 8, 2019
02ce519
ShowHeroes adapter - description and outstream changes (#4222)
veranevera Oct 8, 2019
041268c
ShowHeroes adapter - increase test coverage and small fix
vadim-mazzherin Oct 10, 2019
fa9d95c
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Oct 10, 2019
84009c7
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Dec 2, 2019
e11820c
ShowHeroes Adapter - naming convention issue
vadim-mazzherin Dec 3, 2019
94b1a53
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Dec 3, 2019
5319b37
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Mar 24, 2020
45b3714
Mixed AdUnits declaration support
vadim-mazzherin Apr 7, 2020
2e06464
ITDEV-4723 PrebidJS adapter support with SupplyChain module object
h2p4x8 Apr 30, 2020
09c158f
ITDEV-4723 Fix tests
vadim-mazzherin Apr 30, 2020
f039423
ITDEV-4723 New entry point
vadim-mazzherin May 4, 2020
942a645
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin May 5, 2020
e31698d
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Jul 11, 2021
1315c9e
showheroes-bsBidAdapter: Add support for advertiserDomains
vadim-mazzherin Jul 12, 2021
ae0d73d
showheroes-bsBidAdapter: hotfix for outstream render
vadim-mazzherin Oct 20, 2021
2270649
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Oct 20, 2021
09da82a
showheroes-bsBidAdapter: update renderer url
vadim-mazzherin Oct 28, 2021
971a5b1
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Dec 22, 2021
d027543
showheroes-bsBidAdapter: use only the necessary fields from the gdprC…
vadim-mazzherin Dec 22, 2021
bb757a0
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Jun 29, 2022
42d4326
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Jul 1, 2022
a997f70
ShowHeroes adapter - added a new endpoint
vadim-mazzherin Jul 1, 2022
2d71389
ShowHeroes adapter - unit tests
vadim-mazzherin Jul 13, 2022
ded2bb2
Merge remote-tracking branch 'upstream/master'
vadim-mazzherin Jul 28, 2022
1f5d907
Update showheroes-bsBidAdapter.md
vadim-mazzherin Jul 29, 2022
9bd6cd1
Merge branch 'prebid:master' into master
vadim-mazzherin Aug 3, 2022
5aacc1f
kick off tests
ChrisHuie Aug 10, 2022
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
178 changes: 130 additions & 48 deletions modules/showheroes-bsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { deepAccess, getBidIdParameter, getWindowTop, logError } from '../src/utils.js';
import {
deepAccess,
getBidIdParameter,
getWindowTop,
triggerPixel,
logInfo,
logError
} from '../src/utils.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
Expand All @@ -7,6 +14,7 @@ import { loadExternalScript } from '../src/adloader.js';

const PROD_ENDPOINT = 'https://bs.showheroes.com/api/v1/bid';
const STAGE_ENDPOINT = 'https://bid-service.stage.showheroes.com/api/v1/bid';
const VIRALIZE_ENDPOINT = 'https://ads.viralize.tv/prebid-sh/';
const PROD_PUBLISHER_TAG = 'https://static.showheroes.com/publishertag.js';
const STAGE_PUBLISHER_TAG = 'https://pubtag.stage.showheroes.com/publishertag.js';
const PROD_VL = 'https://video-library.showheroes.com';
Expand All @@ -26,12 +34,13 @@ export const spec = {
aliases: ['showheroesBs'],
supportedMediaTypes: [VIDEO, BANNER],
isBidRequestValid: function(bid) {
return !!bid.params.playerId;
return !!bid.params.playerId || !!bid.params.unitId;
},
buildRequests: function(validBidRequests, bidderRequest) {
let adUnits = [];
const pageURL = validBidRequests[0].params.contentPageUrl || bidderRequest.refererInfo.page;
const pageURL = validBidRequests[0].params.contentPageUrl || bidderRequest.refererInfo.referer;
const isStage = !!validBidRequests[0].params.stage;
const isViralize = !!validBidRequests[0].params.unitId;
const isOutstream = deepAccess(validBidRequests[0], 'mediaTypes.video.context') === 'outstream';
const isCustomRender = deepAccess(validBidRequests[0], 'params.outstreamOptions.customRender');
const isNodeRender = deepAccess(validBidRequests[0], 'params.outstreamOptions.slot') || deepAccess(validBidRequests[0], 'params.outstreamOptions.iframe');
Expand All @@ -40,12 +49,19 @@ export const spec = {
const isBanner = !!validBidRequests[0].mediaTypes.banner || (isOutstream && !(isCustomRender || isNativeRender || isNodeRender));
const defaultSchain = validBidRequests[0].schain || {};

const consentData = bidderRequest.gdprConsent || {};
const gdprConsent = {
apiVersion: consentData.apiVersion || 2,
gdprApplies: consentData.gdprApplies || 0,
consentString: consentData.consentString || '',
}

validBidRequests.forEach((bid) => {
const videoSizes = getVideoSizes(bid);
const bannerSizes = getBannerSizes(bid);
const vpaidMode = getBidIdParameter('vpaidMode', bid.params);

const makeBids = (type, size) => {
const makeBids = (type, size, isViralize) => {
let context = '';
let streamType = 2;

Expand All @@ -61,53 +77,79 @@ export const spec = {
}
}

const consentData = bidderRequest.gdprConsent || {};

const gdprConsent = {
apiVersion: consentData.apiVersion || 2,
gdprApplies: consentData.gdprApplies || 0,
consentString: consentData.consentString || '',
}

return {
let rBid = {
type: streamType,
adUnitCode: bid.adUnitCode,
bidId: bid.bidId,
mediaType: type,
context: context,
playerId: getBidIdParameter('playerId', bid.params),
auctionId: bidderRequest.auctionId,
bidderCode: BIDDER_CODE,
gdprConsent: gdprConsent,
start: +new Date(),
timeout: 3000,
size: {
width: size[0],
height: size[1]
},
params: bid.params,
schain: bid.schain || defaultSchain,
schain: bid.schain || defaultSchain
};

if (isViralize) {
rBid.unitId = getBidIdParameter('unitId', bid.params);
rBid.sizes = size;
rBid.mediaTypes = {
[type]: {'context': context}
};
} else {
rBid.playerId = getBidIdParameter('playerId', bid.params);
rBid.mediaType = type;
rBid.size = {
width: size[0],
height: size[1]
};
rBid.gdprConsent = gdprConsent;
}

return rBid;
};

videoSizes.forEach((size) => {
adUnits.push(makeBids(VIDEO, size));
});
if (isViralize) {
if (videoSizes && videoSizes[0]) {
adUnits.push(makeBids(VIDEO, videoSizes, isViralize));
}
if (bannerSizes && bannerSizes[0]) {
adUnits.push(makeBids(BANNER, bannerSizes, isViralize));
}
} else {
videoSizes.forEach((size) => {
adUnits.push(makeBids(VIDEO, size));
});

bannerSizes.forEach((size) => {
adUnits.push(makeBids(BANNER, size));
});
bannerSizes.forEach((size) => {
adUnits.push(makeBids(BANNER, size));
});
}
});

return {
url: isStage ? STAGE_ENDPOINT : PROD_ENDPOINT,
method: 'POST',
options: {contentType: 'application/json', accept: 'application/json'},
data: {
let endpointUrl;
let data;

const QA = validBidRequests[0].params.qa || {};

if (isViralize) {
endpointUrl = VIRALIZE_ENDPOINT;
data = {
'bidRequests': adUnits,
'context': {
'gdprConsent': gdprConsent,
'schain': defaultSchain,
'pageURL': QA.pageURL || encodeURIComponent(pageURL)
}
}
} else {
endpointUrl = isStage ? STAGE_ENDPOINT : PROD_ENDPOINT;

data = {
'user': [],
'meta': {
'adapterVersion': 2,
'pageURL': encodeURIComponent(pageURL),
'pageURL': QA.pageURL || encodeURIComponent(pageURL),
'vastCacheEnabled': (!!config.getConfig('cache') && !isBanner && !outstreamOptions) || false,
'isDesktop': getWindowTop().document.documentElement.clientWidth > 700,
'xmlAndTag': !!(isOutstream && isCustomRender) || false,
Expand All @@ -116,6 +158,13 @@ export const spec = {
'requests': adUnits,
'debug': validBidRequests[0].params.debug || false,
}
}

return {
url: QA.endpoint || endpointUrl,
method: 'POST',
options: {contentType: 'application/json', accept: 'application/json'},
data: data
};
},
interpretResponse: function(response, request) {
Expand Down Expand Up @@ -149,33 +198,53 @@ export const spec = {
}
return syncs;
},

onBidWon(bid) {
if (bid.callbacks) {
triggerPixel(bid.callbacks.won);
}
logInfo(
`Showheroes adapter won the auction. Bid id: ${bid.bidId || bid.requestId}`
);
},
};

function createBids(bidRes, reqData) {
if (bidRes && (!Array.isArray(bidRes.bids) || bidRes.bids.length < 1)) {
if (!bidRes) {
return [];
}
const responseBids = bidRes.bids || bidRes.bidResponses;
if (!Array.isArray(responseBids) || responseBids.length < 1) {
return [];
}

const bids = [];
const bidMap = {};
(reqData.requests || []).forEach((bid) => {
(reqData.requests || reqData.bidRequests || []).forEach((bid) => {
bidMap[bid.bidId] = bid;
});

bidRes.bids.forEach(function (bid) {
const reqBid = bidMap[bid.bidId];
responseBids.forEach(function (bid) {
const requestId = bid.bidId || bid.requestId;
const reqBid = bidMap[requestId];
const currentBidParams = reqBid.params;
const isViralize = !!reqBid.params.unitId;
const size = {
width: bid.width || bid.size.width,
height: bid.height || bid.size.height
};

let bidUnit = {};
bidUnit.cpm = bid.cpm;
bidUnit.requestId = bid.bidId;
bidUnit.requestId = requestId;
bidUnit.adUnitCode = reqBid.adUnitCode;
bidUnit.currency = bid.currency;
bidUnit.mediaType = bid.mediaType || VIDEO;
bidUnit.ttl = TTL;
bidUnit.creativeId = 'c_' + bid.bidId;
bidUnit.creativeId = 'c_' + requestId;
bidUnit.netRevenue = true;
bidUnit.width = bid.size.width;
bidUnit.height = bid.size.height;
bidUnit.width = size.width;
bidUnit.height = size.height;
bidUnit.meta = {
advertiserDomains: bid.adomain || []
};
Expand All @@ -185,24 +254,26 @@ function createBids(bidRes, reqData) {
content: bid.vastXml,
};
}
if (bid.vastTag) {
bidUnit.vastUrl = bid.vastTag;
if (bid.vastTag || bid.vastUrl) {
bidUnit.vastUrl = bid.vastTag || bid.vastUrl;
}
if (bid.mediaType === BANNER) {
bidUnit.ad = getBannerHtml(bid, reqBid, reqData);
} else if (bid.context === 'outstream') {
const renderer = Renderer.install({
id: bid.bidId,
id: requestId,
url: 'https://static.showheroes.com/renderer.js',
adUnitCode: reqBid.adUnitCode,
config: {
playerId: reqBid.playerId,
width: bid.size.width,
height: bid.size.height,
width: size.width,
height: size.height,
vastUrl: bid.vastTag,
vastXml: bid.vastXml,
ad: bid.ad,
debug: reqData.debug,
isStage: !!reqData.meta.stage,
isStage: reqData.meta && !!reqData.meta.stage,
isViralize: isViralize,
customRender: getBidIdParameter('customRender', currentBidParams.outstreamOptions),
slot: getBidIdParameter('slot', currentBidParams.outstreamOptions),
iframe: getBidIdParameter('iframe', currentBidParams.outstreamOptions),
Expand All @@ -218,7 +289,12 @@ function createBids(bidRes, reqData) {
}

function outstreamRender(bid) {
const embedCode = createOutstreamEmbedCode(bid);
let embedCode;
if (bid.renderer.config.isViralize) {
embedCode = createOutstreamEmbedCodeV2(bid);
} else {
embedCode = createOutstreamEmbedCode(bid);
}
if (typeof bid.renderer.config.customRender === 'function') {
bid.renderer.config.customRender(bid, embedCode);
} else {
Expand Down Expand Up @@ -266,6 +342,12 @@ function createOutstreamEmbedCode(bid) {
return fragment;
}

function createOutstreamEmbedCodeV2(bid) {
const range = document.createRange();
range.selectNode(document.getElementsByTagName('body')[0]);
return range.createContextualFragment(getBidIdParameter('ad', bid.renderer.config));
}

function getBannerHtml (bid, reqBid, reqData) {
const isStage = !!reqData.meta.stage;
const urls = getEnvURLs(isStage);
Expand Down
49 changes: 49 additions & 0 deletions modules/showheroes-bsBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,52 @@ Module that connects to ShowHeroes demand source to fetch bids.
}
];
```

# Test Parameters (V2)
```
var adUnits = [
{
code: 'video',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'instream',
}
},
bids: [
{
bidder: "showheroes-bs",
params: {
unitId: 'AACBWAcof-611K4U',
vpaidMode: true // by default is 'false'
}
}
]
},
{
code: 'video',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'outstream',
}
},
bids: [
{
bidder: "showheroes-bs",
params: {
unitId: 'AACBTwsZVANd9NlB',

outstreamOptions: {
// Required for the outstream renderer to exact node, one of
iframe: 'iframe_id',
// or
slot: 'slot_id'
}
}
}
]
}
];
```

Loading