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] Deprecate playerID #11179

Merged
merged 2 commits into from
Mar 7, 2024
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
22 changes: 13 additions & 9 deletions modules/jwplayerRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,22 @@ export function extractPublisherParams(adUnit, fallback) {
}

function loadVat(params, onCompletion) {
const { playerID, mediaID } = params;
let { playerID, playerDivId, mediaID } = params;
if (!playerDivId) {
playerDivId = playerID;
}

if (pendingRequests[mediaID] !== undefined) {
loadVatForPendingRequest(playerID, mediaID, onCompletion);
loadVatForPendingRequest(playerDivId, mediaID, onCompletion);
return;
}

const vat = getVatFromCache(mediaID) || getVatFromPlayer(playerID, mediaID) || { mediaID };
const vat = getVatFromCache(mediaID) || getVatFromPlayer(playerDivId, mediaID) || { mediaID };
onCompletion(vat);
}

function loadVatForPendingRequest(playerID, mediaID, callback) {
const vat = getVatFromPlayer(playerID, mediaID);
function loadVatForPendingRequest(playerDivId, mediaID, callback) {
const vat = getVatFromPlayer(playerDivId, mediaID);
if (vat) {
callback(vat);
} else {
Expand All @@ -225,8 +229,8 @@ export function getVatFromCache(mediaID) {
};
}

export function getVatFromPlayer(playerID, mediaID) {
const player = getPlayer(playerID);
export function getVatFromPlayer(playerDivId, mediaID) {
const player = getPlayer(playerDivId);
if (!player) {
return null;
}
Expand Down Expand Up @@ -362,14 +366,14 @@ export function addTargetingToBid(bid, targeting) {
bid.rtd = Object.assign({}, rtd, jwRtd);
}

function getPlayer(playerID) {
function getPlayer(playerDivId) {
const jwplayer = window.jwplayer;
if (!jwplayer) {
logError(SUBMODULE_NAME + '.js was not found on page');
return;
}

const player = jwplayer(playerID);
const player = jwplayer(playerDivId);
if (!player || !player.getPlaylist) {
logError('player ID did not match any players');
return;
Expand Down
4 changes: 2 additions & 2 deletions modules/jwplayerRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const adUnit = {
data: {
jwTargeting: {
// Note: the following Ids are placeholders and should be replaced with your Ids.
playerID: 'abcd',
playerDivId: 'abcd',
mediaID: '1234'
}
}
Expand All @@ -51,7 +51,7 @@ pbjs.que.push(function() {
});
});
```
**Note**: The player ID is the ID of the HTML div element used when instantiating the player.
**Note**: The player Div ID is the ID of the HTML div element used when instantiating the player.
You can retrieve this ID by calling `player.id`, where player is the JW Player instance variable.

**Note**: You may also include `jwTargeting` information in the prebid config's `ortb2.site.ext.data`. Information provided in the adUnit will always supersede, and information in the config will be used as a fallback.
Expand Down
45 changes: 40 additions & 5 deletions test/spec/modules/jwplayerRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,41 @@ describe('jwplayerRtdProvider', function() {

fetchTargetingForMediaId(mediaIdWithSegment);

const bid = {};
const adUnit = {
ortb2Imp: {
ext: {
data: {
jwTargeting: {
mediaID: mediaIdWithSegment,
playerDivId: validPlayerID
}
}
}
},
bids: [
bid
]
};
const expectedContentId = 'jw_' + mediaIdWithSegment;
const expectedTargeting = {
segments: validSegments,
content: {
id: expectedContentId
}
};
jwplayerSubmodule.getBidRequestData({ adUnits: [adUnit] }, bidRequestSpy);
expect(bidRequestSpy.calledOnce).to.be.true;
expect(bid.rtd.jwplayer).to.have.deep.property('targeting', expectedTargeting);
server.respond();
expect(bidRequestSpy.calledOnce).to.be.true;
});

it('includes backwards support for playerID when playerDivId is not set', function () {
const bidRequestSpy = sinon.spy();

fetchTargetingForMediaId(mediaIdWithSegment);

const bid = {};
const adUnit = {
ortb2Imp: {
Expand Down Expand Up @@ -605,23 +640,23 @@ describe('jwplayerRtdProvider', function() {
it('should prioritize adUnit properties ', function () {
const expectedMediaID = 'test_media_id';
const expectedPlayerID = 'test_player_id';
const config = { playerID: 'bad_id', mediaID: 'bad_id' };
const config = { playerDivId: 'bad_id', mediaID: 'bad_id' };

const adUnit = { ortb2Imp: { ext: { data: { jwTargeting: { mediaID: expectedMediaID, playerID: expectedPlayerID } } } } };
const adUnit = { ortb2Imp: { ext: { data: { jwTargeting: { mediaID: expectedMediaID, playerDivId: expectedPlayerID } } } } };
const targeting = extractPublisherParams(adUnit, config);
expect(targeting).to.have.property('mediaID', expectedMediaID);
expect(targeting).to.have.property('playerID', expectedPlayerID);
expect(targeting).to.have.property('playerDivId', expectedPlayerID);
});

it('should use config properties as fallbacks', function () {
const expectedMediaID = 'test_media_id';
const expectedPlayerID = 'test_player_id';
const config = { playerID: expectedPlayerID, mediaID: 'bad_id' };
const config = { playerDivId: expectedPlayerID, mediaID: 'bad_id' };

const adUnit = { ortb2Imp: { ext: { data: { jwTargeting: { mediaID: expectedMediaID } } } } };
const targeting = extractPublisherParams(adUnit, config);
expect(targeting).to.have.property('mediaID', expectedMediaID);
expect(targeting).to.have.property('playerID', expectedPlayerID);
expect(targeting).to.have.property('playerDivId', expectedPlayerID);
});

it('should return undefined when Publisher Params are absent', function () {
Expand Down