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

JwPlayer RTD Module: Support cids #8349

Merged
merged 2 commits into from
May 3, 2022
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
36 changes: 27 additions & 9 deletions modules/jwplayerRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ export function enrichAdUnits(adUnits) {
if (!vat) {
return;
}
const contentId = getContentId(vat.mediaID);
const contentData = getContentData(vat.segments);
const mediaId = vat.mediaID;
const contentId = getContentId(mediaId);
const contentSegments = getContentSegments(vat.segments);
const contentData = getContentData(mediaId, contentSegments);
const targeting = formatTargetingResponse(vat);
enrichBids(adUnit.bids, targeting, contentId, contentData);
};
Expand Down Expand Up @@ -263,7 +265,7 @@ export function getContentId(mediaID) {
return 'jw_' + mediaID;
}

export function getContentData(segments) {
export function getContentSegments(segments) {
if (!segments || !segments.length) {
return;
}
Expand All @@ -276,13 +278,29 @@ export function getContentData(segments) {
return convertedSegments;
}, []);

return {
name: 'jwplayer',
ext: {
segtax: 502
},
segment: formattedSegments
return formattedSegments;
}

export function getContentData(mediaId, segments) {
if (!mediaId && !segments) {
return;
}

const contentData = {
name: 'jwplayer.com',
ext: {}
};

if (mediaId) {
contentData.ext.cids = [mediaId];
}

if (segments) {
contentData.segment = segments;
contentData.ext.segtax = 502;
}

return contentData;
}

export function addOrtbSiteContent(bid, contentId, contentData) {
Expand Down
8 changes: 5 additions & 3 deletions modules/jwplayerRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ Example:
content: {
id: 'jw_abc123',
data: [{
name: 'jwplayer',
name: 'jwplayer.com',
ext: {
segtax: 502
segtax: 502,
cids: ['abc123']
},
segment: [{
id: '123'
Expand All @@ -117,8 +118,9 @@ where:
- `content` is an object containing metadata for the media. It may contain the following information:
- `id` is a unique identifier for the specific media asset
- `data` is an array containing segment taxonomy objects that have the following parameters:
- `name` is the `jwplayer` string indicating the provider name
- `name` is the `jwplayer.com` string indicating the provider name
- `ext.segtax` whose `502` value is the unique identifier for JW Player's proprietary taxonomy
- `ext.cids` is an array containing the list of extended content ids as defined in [oRTB's community extensions](https://github.com/InteractiveAdvertisingBureau/openrtb/blob/master/extensions/community_extensions/extended-content-ids.md#example---content-id-and-seller-defined-context).
- `segment` is an array containing the segment taxonomy values as an object where:
- `id` is the string representation of the data segment value.

Expand Down
64 changes: 50 additions & 14 deletions test/spec/modules/jwplayerRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchTargetingForMediaId, getVatFromCache, extractPublisherParams,
formatTargetingResponse, getVatFromPlayer, enrichAdUnits, addTargetingToBid,
fetchTargetingInformation, jwplayerSubmodule, getContentId, getContentData } from 'modules/jwplayerRtdProvider.js';
fetchTargetingInformation, jwplayerSubmodule, getContentId, getContentSegments, getContentData } from 'modules/jwplayerRtdProvider.js';
import { server } from 'test/mocks/xhr.js';
import {addOrtbSiteContent} from '../../../modules/jwplayerRtdProvider';

Expand Down Expand Up @@ -498,26 +498,62 @@ describe('jwplayerRtdProvider', function() {
});
});

describe('Get Content Data', function () {
describe('Get Content Segments', function () {
it('returns undefined when segments are empty', function () {
let data = getContentData(null);
expect(data).to.be.undefined;
data = getContentData(undefined);
expect(data).to.be.undefined;
data = getContentData([]);
expect(data).to.be.undefined;
let contentSegments = getContentSegments(null);
expect(contentSegments).to.be.undefined;
contentSegments = getContentSegments(undefined);
expect(contentSegments).to.be.undefined;
contentSegments = getContentSegments([]);
expect(contentSegments).to.be.undefined;
});

it('returns proper format', function () {
const segment1 = 'segment1';
const segment2 = 'segment2';
const segment3 = 'segment3';
const data = getContentData([segment1, segment2, segment3]);
expect(data).to.have.property('name', 'jwplayer');
expect(data.ext).to.have.property('segtax', 502);
expect(data.segment[0]).to.deep.equal({ id: segment1, value: segment1 });
expect(data.segment[1]).to.deep.equal({ id: segment2, value: segment2 });
expect(data.segment[2]).to.deep.equal({ id: segment3, value: segment3 });
const contentSegments = getContentSegments([segment1, segment2, segment3]);
expect(contentSegments[0]).to.deep.equal({ id: segment1, value: segment1 });
expect(contentSegments[1]).to.deep.equal({ id: segment2, value: segment2 });
expect(contentSegments[2]).to.deep.equal({ id: segment3, value: segment3 });
});
});

describe('Get Content Data', function () {
it('should return proper format', function () {
const testMediaId = 'test_media_id';
const testSegments = [{ id: 1 }, { id: 2 }];
const contentData = getContentData(testMediaId, testSegments);
expect(contentData).to.have.property('name', 'jwplayer.com');
expect(contentData.ext).to.have.property('segtax', 502);
expect(contentData.ext).to.have.property('cids');
expect(contentData.ext.cids).to.have.length(1);
expect(contentData.ext.cids[0]).to.equal(testMediaId);
expect(contentData.segment).to.deep.equal(testSegments);
});

it('should only set segtax and segment when segments are provided', function () {
const testMediaId = 'test_media_id';
const contentData = getContentData(testMediaId);
expect(contentData).to.have.property('name', 'jwplayer.com');
expect(contentData.ext.segtax).to.be.undefined;
expect(contentData.ext).to.have.property('cids');
expect(contentData.ext.cids).to.have.length(1);
expect(contentData.ext.cids[0]).to.equal(testMediaId);
expect(contentData.segment).to.be.undefined;
});

it('should only set cids when a media id is provided', function () {
const testSegments = [{ id: 1 }, { id: 2 }];
const contentData = getContentData(null, testSegments);
expect(contentData).to.have.property('name', 'jwplayer.com');
expect(contentData.ext).to.have.property('segtax', 502);
expect(contentData.ext).to.not.have.property('cids');
expect(contentData.segment).to.deep.equal(testSegments);
});

it('should return undefined when no params are provided', function () {
expect(getContentData()).to.be.undefined;
});
});

Expand Down