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

JW Player RTD Module - Limit scope to adUnits supporting instream video #6227

Merged
3 commits merged into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
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
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