Skip to content

Commit

Permalink
[AD-1020] JWPlayer RTD: Obtain targeting params from FPD (#5892)
Browse files Browse the repository at this point in the history
* reads jwTargeting from fpd

* refactors param extraction

* updates documentation

* mentions support of config fpd

* reduces auction delay examples

Co-authored-by: karimJWP <karimJWP@github.com>
  • Loading branch information
karimMourra and karimJWP committed Oct 27, 2020
1 parent 6360492 commit 894c1d7
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 46 deletions.
17 changes: 12 additions & 5 deletions integrationExamples/gpt/jwplayerRtdProvider_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@

var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
jwTargeting: {
// Note: the following Ids are placeholders and should be replaced with your Ids.
playerID: '123',
mediaID: 'abc'
fpd: {
context: {
data: {
jwTargeting: {
// Note: the following Ids are placeholders and should be replaced with your Ids.
playerID: '123',
mediaID: 'abc'
}
},
}
},

mediaTypes: {
banner: {
sizes: [[300, 250], [300,600]],
Expand Down Expand Up @@ -45,7 +52,7 @@
pbjs.que.push(function() {
pbjs.setConfig({
realTimeData: {
auctionDelay: 5000,
auctionDelay: 100,
dataProviders: [{
name: "jwplayer",
waitForIt: true,
Expand Down
14 changes: 12 additions & 2 deletions modules/jwplayerRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function enrichBidRequest(bidReqConfig, onDone) {
* @param {function} onDone
*/
export function enrichAdUnits(adUnits) {
const fpdFallback = config.getConfig('fpd.context.data.jwTargeting');
adUnits.forEach(adUnit => {
const onVatResponse = function (vat) {
if (!vat) {
Expand All @@ -153,12 +154,21 @@ export function enrichAdUnits(adUnits) {
addTargetingToBids(adUnit.bids, targeting);
};

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

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) {
if (!params || !Object.keys(params).length) {
return;
}

Expand Down
35 changes: 17 additions & 18 deletions modules/jwplayerRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ pbjs.setConfig({
}
});
```
Lastly, include the content's media ID and/or the player's ID in the matching AdUnit:
Lastly, include the content's media ID and/or the player's ID in the matching AdUnit's `fpd.context.data`:

```javascript
const adUnit = {
code: '/19968336/prebid_native_example_1',
...
jwTargeting: {
waitForIt: true,
playerID: 'abcd',
mediaID: '1234'
fpd: {
context: {
data: {
jwTargeting: {
// Note: the following Ids are placeholders and should be replaced with your Ids.
playerID: 'abcd',
mediaID: '1234'
}
}
}
}
};

Expand All @@ -45,34 +51,27 @@ pbjs.que.push(function() {
});
});
```

**Note**: You may also include `jwTargeting` information in the prebid config's `fpd.context.data`. Information provided in the adUnit will always supersede, and information in the config will be used as a fallback.

##Prefetching
In order to prefetch targeting information for certain media, include the media IDs in the `jwplayerDataProvider` var:
In order to prefetch targeting information for certain media, include the media IDs in the `jwplayerDataProvider` var and set `waitForIt` to `true`:

```javascript
const jwplayerDataProvider = {
name: "jwplayer",
waitForIt: true,
params: {
mediaIDs: ['abc', 'def', 'ghi', 'jkl']
}
};
```

To ensure that the prefetched targeting information is added to your bid, we strongly suggest setting
`jwTargeting.waitForIt` to `true`. If the prefetch is still in progress at the time of the bid request, the auction will
be delayed until the targeting information specific to the requested adUnits has been obtained.

```javascript
jwTargeting: {
waitForIt: true,
...
}
```

You must also set a value to `auctionDelay` in the config's `realTimeData` object

```javascript
realTimeData = {
auctionDelay: 1000,
auctionDelay: 100,
...
};
```
Expand Down
146 changes: 125 additions & 21 deletions test/spec/modules/jwplayerRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fetchTargetingForMediaId, enrichBidRequest,
getVatFromCache, formatTargetingResponse, getVatFromPlayer, enrichAdUnits,
import { fetchTargetingForMediaId, getVatFromCache, extractPublisherParams,
formatTargetingResponse, getVatFromPlayer, enrichAdUnits,
fetchTargetingInformation, jwplayerSubmodule } from 'modules/jwplayerRtdProvider.js';
import { server } from 'test/mocks/xhr.js';

Expand Down Expand Up @@ -229,9 +229,15 @@ describe('jwplayerRtdProvider', function() {

const bid = {};
const adUnit = {
jwTargeting: {
mediaID: mediaIdWithSegment,
playerID: validPlayerID
fpd: {
context: {
data: {
jwTargeting: {
mediaID: mediaIdWithSegment,
playerID: validPlayerID
}
}
}
},
bids: [
bid
Expand Down Expand Up @@ -292,8 +298,14 @@ describe('jwplayerRtdProvider', function() {
}
];
const adUnit = {
jwTargeting: {
mediaID: testIdForSuccess
fpd: {
context: {
data: {
jwTargeting: {
mediaID: testIdForSuccess
}
}
}
},
bids
};
Expand Down Expand Up @@ -333,8 +345,14 @@ describe('jwplayerRtdProvider', function() {
}
];
const adUnit = {
jwTargeting: {
mediaID: testIdForSuccess
fpd: {
context: {
data: {
jwTargeting: {
mediaID: testIdForSuccess
}
}
}
},
bids
};
Expand Down Expand Up @@ -374,8 +392,14 @@ describe('jwplayerRtdProvider', function() {
}
];
const adUnit = {
jwTargeting: {
mediaID: testIdForFailure
fpd: {
context: {
data: {
jwTargeting: {
mediaID: testIdForFailure
}
}
}
},
bids
};
Expand All @@ -388,6 +412,50 @@ describe('jwplayerRtdProvider', function() {
});
});

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

const adUnit1 = { fpd: { context: {} } };
const targeting1 = extractPublisherParams(adUnit1, config);
expect(targeting1).to.deep.equal(config);

const adUnit2 = { fpd: { context: { data: { jwTargeting: {} } } } };
const targeting2 = extractPublisherParams(adUnit2, config);
expect(targeting2).to.deep.equal(config);

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

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 adUnit = { fpd: { context: { data: { jwTargeting: { mediaID: expectedMediaID, playerID: expectedPlayerID } } } } };
const targeting = extractPublisherParams(adUnit, config);
expect(targeting).to.have.property('mediaID', expectedMediaID);
expect(targeting).to.have.property('playerID', 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 adUnit = { fpd: { context: { data: { jwTargeting: { mediaID: expectedMediaID } } } } };
const targeting = extractPublisherParams(adUnit, config);
expect(targeting).to.have.property('mediaID', expectedMediaID);
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({});
})
});

describe('jwplayerSubmodule', function () {
it('successfully instantiates', function () {
expect(jwplayerSubmodule.init()).to.equal(true);
Expand All @@ -404,16 +472,28 @@ describe('jwplayerRtdProvider', function() {
bidReqConfig = {
adUnits: [
{
jwTargeting: {
mediaID: validMediaIDs[0]
fpd: {
context: {
data: {
jwTargeting: {
mediaID: validMediaIDs[0]
}
}
}
},
bids: [
{}, {}
]
},
{
jwTargeting: {
mediaID: validMediaIDs[1]
fpd: {
context: {
data: {
jwTargeting: {
mediaID: validMediaIDs[1]
}
}
}
},
bids: [
{}, {}
Expand Down Expand Up @@ -473,8 +553,14 @@ describe('jwplayerRtdProvider', function() {
it('sets targeting data in proper structure', function () {
const bid = {};
const adUnitWithMediaId = {
jwTargeting: {
mediaID: testIdForSuccess
fpd: {
context: {
data: {
jwTargeting: {
mediaID: testIdForSuccess
}
}
}
},
bids: [
bid
Expand All @@ -499,12 +585,18 @@ describe('jwplayerRtdProvider', function() {
const adUnitCode = 'test_ad_unit';
const bid = {};
const adUnit = {
jwTargeting: {
mediaID: testIdForFailure
fpd: {
context: {
data: {
jwTargeting: {
mediaID: testIdForFailure
}
}
}
},
bids: [ bid ]
};
const expectedContentId = 'jw_' + adUnit.jwTargeting.mediaID;
const expectedContentId = 'jw_' + adUnit.fpd.context.data.jwTargeting.mediaID;
const expectedTargeting = {
content: {
id: expectedContentId
Expand All @@ -522,6 +614,7 @@ describe('jwplayerRtdProvider', function() {
const adUnitCode = 'test_ad_unit';
const bid1 = {};
const bid2 = {};
const bid3 = {};
const adUnitWithMediaId = {
code: adUnitCode,
mediaID: testIdForSuccess,
Expand All @@ -532,10 +625,21 @@ describe('jwplayerRtdProvider', function() {
bids: [ bid2 ]
};

jwplayerSubmodule.getBidRequestData({ adUnits: [adUnitWithMediaId, adUnitEmpty] }, bidRequestSpy);
const adUnitEmptyfpd = {
code: 'test_ad_unit_empty_fpd',
fpd: {
context: {
id: 'sthg'
}
},
bids: [ bid3 ]
};

jwplayerSubmodule.getBidRequestData({ adUnits: [adUnitWithMediaId, adUnitEmpty, adUnitEmptyfpd] }, bidRequestSpy);
expect(bidRequestSpy.calledOnce).to.be.true;
expect(bid1).to.not.have.property('jwTargeting');
expect(bid2).to.not.have.property('jwTargeting');
expect(bid3).to.not.have.property('jwTargeting');
});
});
});
Expand Down

0 comments on commit 894c1d7

Please sign in to comment.