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

PubMatic Adapter : Support For Video Params from AdUnit MediaTypes #6773

Merged
merged 89 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
7e5986c
Merge pull request #1 from prebid/master
pm-shashank-jain Nov 27, 2018
d1146d7
Merge pull request #2 from prebid/master
pm-shashank-jain Nov 29, 2018
609ec16
changes to support native in pubmaticbid adapter
pm-shashank-jain Dec 5, 2018
792b854
Removed port from endpoint
pm-shashank-jain Dec 5, 2018
b6740d0
Removed protocol from endpoint
pm-shashank-jain Dec 5, 2018
0569f41
Formatting
pm-shashank-jain Dec 5, 2018
fd6bf03
Fix request payload
pm-shashank-jain Dec 6, 2018
bd14420
Updated test case
pm-shashank-jain Dec 6, 2018
65e2f1e
Changed request and response as per ortb spec
pm-shashank-jain Dec 7, 2018
13c87de
Change in request and response
pm-shashank-jain Dec 10, 2018
d9f3562
Removed comments and extra code
pm-shashank-jain Dec 10, 2018
adbc774
Code Review comments
pm-shashank-jain Dec 11, 2018
21fe846
Code Review Comments and Test cases for request and response
pm-shashank-jain Dec 13, 2018
9faff35
Removed data type as all data asset types are handled
pm-shashank-jain Dec 14, 2018
78cd16d
Code Review Changes
pm-shashank-jain Dec 14, 2018
4a40e1e
Code Review Comments
pm-shashank-jain Dec 17, 2018
a218d43
Supporting both banner and native and sending 0x0 in case of native
pm-shashank-jain Dec 18, 2018
f65b3fb
Bug Fixes
pm-shashank-jain Dec 21, 2018
a717fbc
Bug response not processed by prebid
pm-shashank-jain Dec 21, 2018
af2503d
Change warning message
pm-shashank-jain Dec 21, 2018
21277c1
Fixed typo
pm-shashank-jain Dec 21, 2018
53ac4fe
Merge pull request #4 from prebid/master
pm-shashank-jain Dec 21, 2018
ac1919f
Merge branch 'master' of github.com:pm-shashank-jain/Prebid.js into n…
pm-shashank-jain Dec 21, 2018
1de1623
Do not send request in case of invalid native bid
pm-shashank-jain Dec 24, 2018
6b059b7
Do not send request in case of invalid native requests
pm-shashank-jain Dec 24, 2018
9c80c46
objects converted to strings in log for debug purposes
pm-shashank-jain Dec 24, 2018
e0f8763
Fixed logic to check for required parmas
pm-shashank-jain Dec 24, 2018
c4ee495
Fixed typo for stringify
pm-shashank-jain Dec 24, 2018
d4abb65
Merge pull request #3 from pm-shashank-jain/nativesupport
pm-shashank-jain Dec 26, 2018
f143cee
documentation for native
pm-shashank-jain Dec 26, 2018
06a6e34
Merge pull request #5 from pm-shashank-jain/nativesupport
pm-shashank-jain Dec 26, 2018
84a9c02
Review comments from Prebid
pm-shashank-jain Jan 8, 2019
e3d068e
Typo
pm-shashank-jain Jan 8, 2019
468c3ab
Typo
pm-shashank-jain Jan 8, 2019
11fce22
Updated pub id for native
pm-shashank-jain Jan 10, 2019
b23e2dd
Code Review
pm-shashank-jain Jan 15, 2019
6b8c31b
Merge pull request #6 from pm-shashank-jain/nativesupport
pm-shashank-jain Jan 15, 2019
2f73d99
Merge branch 'master' of github.com:pm-shashank-jain/Prebid.js
pm-shashank-jain Aug 21, 2019
27e56d6
Latest Code
pm-shashank-jain Aug 21, 2019
9c0772b
Merge pull request #8 from prebid/master
pm-shashank-jain Aug 30, 2019
909f526
Support for pubid
pm-shashank-jain Aug 30, 2019
7fe0f35
Merge branch 'master' of github.com:pm-shashank-jain/Prebid.js
pm-shashank-jain Aug 30, 2019
53a7ddf
Test Cases for PubCommonId in PubMatic adapter
pm-shashank-jain Sep 3, 2019
f168aea
Delete yarn.lock
pm-shashank-jain Sep 3, 2019
e9db7f3
Rename adaptermanager.js to adapterManager.js
pm-shashank-jain Sep 3, 2019
e753a97
Rename yieldNexusBidAdapter.js to yieldnexusBidAdapter.js
pm-shashank-jain Sep 3, 2019
68b2e65
Rename yieldNexusBidAdapter.md to yieldnexusBidAdapter.md
pm-shashank-jain Sep 3, 2019
483cddf
Rename yieldNexusBidAdapter_spec.js to yieldnexusBidAdapter_spec.yiel…
pm-shashank-jain Sep 3, 2019
149875b
Rename yieldnexusBidAdapter_spec.yieldnexusBidAdaptera to yieldnexusB…
pm-shashank-jain Sep 3, 2019
8d89338
took latest
pm-shashank-jain Dec 27, 2019
e5b4722
Merge branch 'prebid-master'
pm-shashank-jain Dec 27, 2019
7a0cace
Merge remote-tracking branch 'upstream/master'
pm-shashank-jain Jun 12, 2020
a1d5256
bluebillywig outstream player support in pubmatic adapter
pm-shashank-jain Jun 23, 2020
6e4fa37
Merge https://github.com/prebid/Prebid.js
pm-shashank-jain Jul 2, 2020
fb6056c
Merge branch 'master' of github.com:pm-shashank-jain/Prebid.js into o…
pm-shashank-jain Jul 2, 2020
5d5e4eb
Merge https://github.com/prebid/Prebid.js into outstream_renderer
pm-shashank-jain Jul 15, 2020
825242c
Merge https://github.com/prebid/Prebid.js into outstream_renderer
pm-shashank-jain Jul 17, 2020
4681528
Merge https://github.com/prebid/Prebid.js into outstream_renderer
pm-shashank-jain Jul 21, 2020
1ee6583
removed pubcommon id test cases
pm-shashank-jain Jul 21, 2020
260f7f7
Merge https://github.com/prebid/Prebid.js
pm-shashank-jain Jul 21, 2020
cc7c65c
BBW Renderer
pm-shashank-jain Jul 21, 2020
8a2e508
Merge branch 'master' of github.com:pm-shashank-jain/Prebid.js into o…
pm-shashank-jain Jul 21, 2020
3362acd
Merge https://github.com/prebid/Prebid.js
pm-shashank-jain Jul 30, 2020
e72f47f
Merge pull request #11 from pm-shashank-jain/outstream_renderer
pm-shashank-jain Jul 30, 2020
251398e
Merge branch 'master' of https://github.com/prebid/Prebid.js
pm-shashank-jain Aug 12, 2020
efdf7a1
Took latest prebid
pm-shashank-jain Dec 16, 2020
936f0fe
Merge branch 'master' of https://github.com/prebid/Prebid.js
pm-shashank-jain Dec 28, 2020
af471f8
Pubmatic should work with provided renderer
pm-shashank-jain Dec 28, 2020
7048c86
Merge pull request #12 from pm-shashank-jain/outstream_bug_fix
pm-shashank-jain Dec 28, 2020
b75de91
Merge branch 'master' of https://github.com/prebid/Prebid.js
pm-shashank-jain Jan 27, 2021
92ee235
Review Comments
pm-shashank-jain Jan 27, 2021
6e24164
latest pull
pm-shashank-jain Apr 30, 2021
1b4abe3
Merge branch 'master' of github.com:prebid/Prebid.js
pm-shashank-jain May 5, 2021
393d8c9
changes for mediatype
pm-shashank-jain May 6, 2021
7c37018
Merge branch 'master' of github.com:prebid/Prebid.js
pm-shashank-jain May 6, 2021
563f594
Changes for video feature
pm-shashank-jain May 10, 2021
1eafbd9
DCTR at impression level
pm-shashank-jain May 11, 2021
f0428fc
Fixed test cases for DCTR
pm-shashank-jain May 11, 2021
dfd5d1b
Merge pull request #13 from pm-shashank-jain/dctr
pm-shashank-jain May 11, 2021
c2986b2
Merge pull request #14 from pm-shashank-jain/feature/video
pm-shashank-jain May 11, 2021
941555d
Merge branch 'mediatype_dctr_video' into mediatypedctrvideoparams
pm-shashank-jain May 11, 2021
d244a09
Merge pull request #15 from pm-shashank-jain/mediatypedctrvideoparams
pm-shashank-jain May 11, 2021
8c4f717
took latest md file
pm-shashank-jain May 12, 2021
35f0b04
Merge branch 'mediatype_dctr_video' of github.com:pm-shashank-jain/Pr…
pm-shashank-jain May 12, 2021
ca9a6dc
fixed issue with 0 as BidType
pm-shashank-jain May 12, 2021
a5d8c79
Fix for banner
pm-shashank-jain May 14, 2021
0af10d6
removed commented code
pm-shashank-jain May 17, 2021
4dc5c3c
Code Review comments, added unit test cases for dctr, video request a…
pm-shashank-jain May 20, 2021
70dda9d
review comments: Changed skip from bool to number,warning for non str…
pm-shashank-jain May 25, 2021
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
128 changes: 60 additions & 68 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const VIDEO_CUSTOM_PARAMS = {
'linearity': DATA_TYPES.NUMBER,
'placement': DATA_TYPES.NUMBER,
'minbitrate': DATA_TYPES.NUMBER,
'maxbitrate': DATA_TYPES.NUMBER
'maxbitrate': DATA_TYPES.NUMBER,
'skip': DATA_TYPES.NUMBER
}

const NATIVE_ASSETS = {
Expand Down Expand Up @@ -162,6 +163,12 @@ const BB_RENDERER = {
}
};

const MEDIATYPE = [
BANNER,
VIDEO,
NATIVE
]

let publisherId = 0;
let isInvalidNativeRequest = false;
let NATIVE_ASSET_ID_TO_KEY_MAP = {};
Expand Down Expand Up @@ -526,7 +533,7 @@ function _createBannerRequest(bid) {
}

function _createVideoRequest(bid) {
var videoData = bid.params.video;
var videoData = utils.mergeDeep(utils.deepAccess(bid.mediaTypes, 'video'), bid.params.video);
patmmccann marked this conversation as resolved.
Show resolved Hide resolved
var videoObj;

if (videoData !== UNDEFINED) {
Expand All @@ -544,11 +551,6 @@ function _createVideoRequest(bid) {
videoObj.w = parseInt(bid.mediaTypes.video.playerSize[0], 10);
videoObj.h = parseInt(bid.mediaTypes.video.playerSize[1], 10);
}
if (bid.params.video.hasOwnProperty('skippable')) {
videoObj.ext = {
'video_skippable': bid.params.video.skippable ? 1 : 0
};
}
} else {
videoObj = UNDEFINED;
utils.logWarn(LOG_WARN_PREFIX + 'Error: Video config params missing for adunit: ' + bid.params.adUnit + ' with mediaType set as video. Ignoring video impression in the adunit.');
Expand Down Expand Up @@ -576,6 +578,28 @@ function _addPMPDealsInImpression(impObj, bid) {
}
}

function _addDealCustomTargetings(imp, bid) {
pm-shashank-jain marked this conversation as resolved.
Show resolved Hide resolved
var dctr = '';
var dctrLen;
if (bid.params.dctr) {
dctr = bid.params.dctr;
if (utils.isStr(dctr) && dctr.length > 0) {
var arr = dctr.split('|');
dctr = '';
arr.forEach(val => {
dctr += (val.length > 0) ? (val.trim() + '|') : '';
});
dctrLen = dctr.length;
if (dctr.substring(dctrLen, dctrLen - 1) === '|') {
dctr = dctr.substring(0, dctrLen - 1);
}
imp.ext['key_val'] = dctr.trim()
} else {
utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
}
}
}

function _createImpressionObject(bid, conf) {
var impObj = {};
var bannerObj;
Expand All @@ -597,7 +621,7 @@ function _createImpressionObject(bid, conf) {
};

_addPMPDealsInImpression(impObj, bid);

_addDealCustomTargetings(impObj, bid);
if (bid.hasOwnProperty('mediaTypes')) {
for (mediaTypes in bid.mediaTypes) {
switch (mediaTypes) {
Expand Down Expand Up @@ -715,22 +739,28 @@ function _handleEids(payload, validBidRequests) {
}
}

function _checkMediaType(adm, newBid) {
function _checkMediaType(bid, newBid) {
// Create a regex here to check the strings
var admStr = '';
var videoRegex = new RegExp(/VAST\s+version/);
if (adm.indexOf('span class="PubAPIAd"') >= 0) {
newBid.mediaType = BANNER;
} else if (videoRegex.test(adm)) {
newBid.mediaType = VIDEO;
if (bid.ext && bid.ext['BidType'] != undefined) {
newBid.mediaType = MEDIATYPE[bid.ext.BidType];
} else {
try {
admStr = JSON.parse(adm.replace(/\\/g, ''));
if (admStr && admStr.native) {
newBid.mediaType = NATIVE;
utils.logInfo(LOG_WARN_PREFIX + 'bid.ext.BidType does not exist, checking alternatively for mediaType')
var adm = bid.adm;
var admStr = '';
var videoRegex = new RegExp(/VAST\s+version/);
if (adm.indexOf('span class="PubAPIAd"') >= 0) {
pm-shashank-jain marked this conversation as resolved.
Show resolved Hide resolved
newBid.mediaType = BANNER;
} else if (videoRegex.test(adm)) {
newBid.mediaType = VIDEO;
} else {
try {
admStr = JSON.parse(adm.replace(/\\/g, ''));
if (admStr && admStr.native) {
newBid.mediaType = NATIVE;
}
} catch (e) {
utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + adm);
}
} catch (e) {
utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + adm);
}
}
}
Expand Down Expand Up @@ -820,38 +850,6 @@ function _blockedIabCategoriesValidation(payload, blockedIabCategories) {
}
}

function _handleDealCustomTargetings(payload, dctrArr, validBidRequests) {
var dctr = '';
var dctrLen;
// set dctr value in site.ext, if present in validBidRequests[0], else ignore
if (dctrArr.length > 0) {
if (validBidRequests[0].params.hasOwnProperty('dctr')) {
dctr = validBidRequests[0].params.dctr;
if (utils.isStr(dctr) && dctr.length > 0) {
var arr = dctr.split('|');
dctr = '';
arr.forEach(val => {
dctr += (val.length > 0) ? (val.trim() + '|') : '';
});
dctrLen = dctr.length;
if (dctr.substring(dctrLen, dctrLen - 1) === '|') {
dctr = dctr.substring(0, dctrLen - 1);
}
payload.site.ext = {
key_val: dctr.trim()
}
} else {
utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
}
if (dctrArr.length > 1) {
utils.logWarn(LOG_WARN_PREFIX + 'dctr value found in more than 1 adunits. Value from 1st adunit will be picked. Ignoring values from subsequent adunits');
}
} else {
utils.logWarn(LOG_WARN_PREFIX + 'dctr value not found in 1st adunit, ignoring values from subsequent adunits');
}
}
}

function _assignRenderer(newBid, request) {
let bidParams, context, adUnitCode;
if (request.bidderRequest && request.bidderRequest.bids) {
Expand Down Expand Up @@ -886,22 +884,17 @@ export const spec = {
return false;
}
// video ad validation
if (bid.params.hasOwnProperty('video')) {
if (!bid.params.video.hasOwnProperty('mimes') || !utils.isArray(bid.params.video.mimes) || bid.params.video.mimes.length === 0) {
if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) {
pm-shashank-jain marked this conversation as resolved.
Show resolved Hide resolved
if (!bid.mediaTypes.video.mimes || (bid.params.video && (!bid.params.video.hasOwnProperty('mimes') || !utils.isArray(bid.params.video.mimes) || bid.params.video.mimes.length === 0))) {
utils.logWarn(LOG_WARN_PREFIX + 'Error: For video ads, mimes is mandatory and must specify atlease 1 mime value. Call to OpenBid will not be sent for ad unit:' + JSON.stringify(bid));
return false;
}
if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) {
if (!bid.mediaTypes[VIDEO].hasOwnProperty('context')) {
utils.logError(`${LOG_WARN_PREFIX}: no context specified in bid. Rejecting bid: `, bid);
return false;
}
if (bid.mediaTypes[VIDEO].context === 'outstream' && !utils.isStr(bid.params.outstreamAU) && !bid.hasOwnProperty('renderer') && !bid.mediaTypes[VIDEO].hasOwnProperty('renderer')) {
utils.logError(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting bid: `, bid);
return false;
}
} else {
utils.logError(`${LOG_WARN_PREFIX}: mediaTypes or mediaTypes.video is not specified. Rejecting bid: `, bid);
if (!bid.mediaTypes[VIDEO].hasOwnProperty('context')) {
pm-shashank-jain marked this conversation as resolved.
Show resolved Hide resolved
utils.logError(`${LOG_WARN_PREFIX}: no context specified in bid. Rejecting bid: `, bid);
return false;
}
if (bid.mediaTypes[VIDEO].context === 'outstream' && !utils.isStr(bid.params.outstreamAU) && !bid.hasOwnProperty('renderer') && !bid.mediaTypes[VIDEO].hasOwnProperty('renderer')) {
utils.logError(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting bid: `, bid);
return false;
}
}
Expand Down Expand Up @@ -1026,7 +1019,6 @@ export const spec = {
utils.deepSetValue(payload, 'regs.coppa', 1);
}

_handleDealCustomTargetings(payload, dctrArr, validBidRequests);
_handleEids(payload, validBidRequests);
_blockedIabCategoriesValidation(payload, blockedIabCategories);

Expand Down Expand Up @@ -1100,7 +1092,7 @@ export const spec = {
if (parsedRequest.imp && parsedRequest.imp.length > 0) {
parsedRequest.imp.forEach(req => {
if (bid.impid === req.id) {
_checkMediaType(bid.adm, newBid);
_checkMediaType(bid, newBid);
switch (newBid.mediaType) {
case BANNER:
break;
Expand Down
Loading