Skip to content

Commit

Permalink
JW Player RTD Module - Limit scope to adUnits supporting instream vid…
Browse files Browse the repository at this point in the history
…eo (#6227)

* checks if media type is video and jwtargeting is present

* adds early return

* adds tests for jwtargeting with banner or outtream

Co-authored-by: karimJWP <karimJWP@github.com>
  • Loading branch information
karimMourra and karimJWP authored Jan 26, 2021
1 parent dfed405 commit 40d335a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
21 changes: 15 additions & 6 deletions modules/jwplayerRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,32 +146,41 @@ function enrichBidRequest(bidReqConfig, onDone) {
export function enrichAdUnits(adUnits) {
const fpdFallback = config.getConfig('fpd.context.data.jwTargeting');
adUnits.forEach(adUnit => {
const jwTargeting = extractPublisherParams(adUnit, fpdFallback);
if (!jwTargeting || !Object.keys(jwTargeting).length) {
return;
}

const onVatResponse = function (vat) {
if (!vat) {
return;
}
const targeting = formatTargetingResponse(vat);
addTargetingToBids(adUnit.bids, targeting);
};

const jwTargeting = extractPublisherParams(adUnit, fpdFallback);
loadVat(jwTargeting, onVatResponse);
});
}

function supportsInstreamVideo(mediaTypes) {
const video = mediaTypes && mediaTypes.video;
return video && video.context === 'instream';
}

export function extractPublisherParams(adUnit, fallback) {
let adUnitTargeting;
try {
adUnitTargeting = adUnit.fpd.context.data.jwTargeting;
} catch (e) {}
return Object.assign({}, fallback, adUnitTargeting);
}

function loadVat(params, onCompletion) {
if (!params || !Object.keys(params).length) {
if (!adUnitTargeting && !supportsInstreamVideo(adUnit.mediaTypes)) {
return;
}

return Object.assign({}, fallback, adUnitTargeting);
}

function loadVat(params, onCompletion) {
const { playerID, mediaID } = params;
if (pendingRequests[mediaID] !== undefined) {
loadVatForPendingRequest(playerID, mediaID, onCompletion);
Expand Down
50 changes: 37 additions & 13 deletions test/spec/modules/jwplayerRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,19 +413,43 @@ describe('jwplayerRtdProvider', function() {
});

describe(' Extract Publisher Params', function () {
it('should default to config', function () {
const config = { mediaID: 'test' };
const config = { mediaID: 'test' };

const adUnit1 = { fpd: { context: {} } };
const targeting1 = extractPublisherParams(adUnit1, config);
expect(targeting1).to.deep.equal(config);
it('should exclude adUnits that do not support instream video and do not specify jwTargeting', function () {
const oustreamAdUnit = { mediaTypes: { video: { context: 'outstream' } } };
const oustreamTargeting = extractPublisherParams(oustreamAdUnit, config);
expect(oustreamTargeting).to.be.undefined;

const adUnit2 = { fpd: { context: { data: { jwTargeting: {} } } } };
const targeting2 = extractPublisherParams(adUnit2, config);
expect(targeting2).to.deep.equal(config);
const bannerAdUnit = { mediaTypes: { banner: {} } };
const bannerTargeting = extractPublisherParams(bannerAdUnit, config);
expect(bannerTargeting).to.be.undefined;

const targeting3 = extractPublisherParams(null, config);
expect(targeting3).to.deep.equal(config);
const targeting = extractPublisherParams({}, config);
expect(targeting).to.be.undefined;
});

it('should include ad unit when media type is video and is instream', function () {
const adUnit = { mediaTypes: { video: { context: 'instream' } } };
const targeting = extractPublisherParams(adUnit, config);
expect(targeting).to.deep.equal(config);
});

it('should include banner ad units that specify jwTargeting', function() {
const adUnit = { mediaTypes: { banner: {} }, fpd: { context: { data: { jwTargeting: {} } } } };
const targeting = extractPublisherParams(adUnit, config);
expect(targeting).to.deep.equal(config);
});

it('should include outstream ad units that specify jwTargeting', function() {
const adUnit = { mediaTypes: { video: { context: 'outstream' } }, fpd: { context: { data: { jwTargeting: {} } } } };
const targeting = extractPublisherParams(adUnit, config);
expect(targeting).to.deep.equal(config);
});

it('should fallback to config when empty jwTargeting is defined in ad unit', function () {
const adUnit = { fpd: { context: { data: { jwTargeting: {} } } } };
const targeting = extractPublisherParams(adUnit, config);
expect(targeting).to.deep.equal(config);
});

it('should prioritize adUnit properties ', function () {
Expand All @@ -450,9 +474,9 @@ describe('jwplayerRtdProvider', function() {
expect(targeting).to.have.property('playerID', expectedPlayerID);
});

it('should return empty object when Publisher Params are absent', function () {
const targeting = extractPublisherParams(null, null);
expect(targeting).to.deep.equal({});
it('should return undefined when Publisher Params are absent', function () {
const targeting = extractPublisherParams({}, null);
expect(targeting).to.be.undefined;
})
});

Expand Down

0 comments on commit 40d335a

Please sign in to comment.