Skip to content

Commit 36e0c2a

Browse files
jsnellbakerdluxemburg
authored andcommitted
include targeting data in buildVideoUrl function (prebid#2826)
1 parent c782171 commit 36e0c2a

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

modules/dfpAdServerVideo.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function buildDfpVideoUrl(options) {
7373
urlComponents = parse(options.url, {noDecodeWholeURL: true});
7474

7575
if (isEmpty(options.params)) {
76-
return buildUrlFromAdserverUrlComponents(urlComponents, bid);
76+
return buildUrlFromAdserverUrlComponents(urlComponents, bid, options);
7777
}
7878
}
7979

@@ -108,13 +108,14 @@ export default function buildDfpVideoUrl(options) {
108108
* Prebid-specific key-values.
109109
* @param {Object} components base video adserver url parsed into components object
110110
* @param {AdapterBidResponse} bid winning bid object to append parameters from
111+
* @param {Object} options Options which should be used to construct the URL (used for custom params).
111112
* @return {string} video url
112113
*/
113-
function buildUrlFromAdserverUrlComponents(components, bid) {
114+
function buildUrlFromAdserverUrlComponents(components, bid, options) {
114115
const descriptionUrl = getDescriptionUrl(bid, components, 'search');
115116
if (descriptionUrl) { components.search.description_url = descriptionUrl; }
116117

117-
const encodedCustomParams = getCustParams(bid);
118+
const encodedCustomParams = getCustParams(bid, options);
118119
components.search.cust_params = (components.search.cust_params) ? components.search.cust_params + '%26' + encodedCustomParams : encodedCustomParams;
119120

120121
return buildUrl(components);
@@ -147,8 +148,17 @@ function getDescriptionUrl(bid, components, prop) {
147148
*/
148149
function getCustParams(bid, options) {
149150
const adserverTargeting = (bid && bid.adserverTargeting) || {};
151+
152+
let allTargetingData = {};
153+
const adUnit = options && options.adUnit;
154+
if (adUnit) {
155+
let allTargeting = targeting.getAllTargeting(adUnit.code);
156+
allTargetingData = (allTargeting) ? allTargeting[adUnit.code] : {};
157+
}
158+
150159
const optCustParams = deepAccess(options, 'params.cust_params');
151160
let customParams = Object.assign({},
161+
allTargetingData,
152162
adserverTargeting,
153163
{ hb_uuid: bid && bid.videoCacheKey },
154164
// hb_uuid will be deprecated and replaced by hb_cache_id

test/spec/modules/dfpAdServerVideo_spec.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import parse from 'url-parse';
44
import buildDfpVideoUrl from 'modules/dfpAdServerVideo';
55
import { parseQS } from 'src/url';
66
import adUnit from 'test/fixtures/video/adUnit';
7+
import * as utils from 'src/utils';
8+
import { config } from 'src/config';
9+
import { targeting } from 'src/targeting';
710

811
const bid = {
912
videoCacheKey: 'abc',
@@ -107,6 +110,79 @@ describe('The DFP video support module', () => {
107110
expect(customParams).to.have.property('hb_cache_id', bid.videoCacheKey);
108111
});
109112

113+
describe('special targeting unit test', () => {
114+
const allTargetingData = {
115+
'hb_format': 'video',
116+
'hb_source': 'client',
117+
'hb_size': '640x480',
118+
'hb_pb': '5.00',
119+
'hb_adid': '2c4f6cc3ba128a',
120+
'hb_bidder': 'testBidder2',
121+
'hb_format_testBidder2': 'video',
122+
'hb_source_testBidder2': 'client',
123+
'hb_size_testBidder2': '640x480',
124+
'hb_pb_testBidder2': '5.00',
125+
'hb_adid_testBidder2': '2c4f6cc3ba128a',
126+
'hb_bidder_testBidder2': 'testBidder2',
127+
'hb_format_appnexus': 'video',
128+
'hb_source_appnexus': 'client',
129+
'hb_size_appnexus': '640x480',
130+
'hb_pb_appnexus': '5.00',
131+
'hb_adid_appnexus': '44e0b5f2e5cace',
132+
'hb_bidder_appnexus': 'appnexus'
133+
};
134+
let targetingStub;
135+
136+
before(() => {
137+
targetingStub = sinon.stub(targeting, 'getAllTargeting');
138+
targetingStub.returns({'video1': allTargetingData});
139+
140+
config.setConfig({
141+
enableSendAllBids: true
142+
});
143+
});
144+
145+
after(() => {
146+
config.resetConfig();
147+
targetingStub.restore();
148+
});
149+
150+
it('should include all adserver targeting in cust_params if pbjs.enableSendAllBids is true', () => {
151+
const adUnitsCopy = utils.deepClone(adUnit);
152+
adUnitsCopy.bids.push({
153+
'bidder': 'testBidder2',
154+
'params': {
155+
'placementId': '9333431',
156+
'video': {
157+
'skipppable': false,
158+
'playback_methods': ['auto_play_sound_off']
159+
}
160+
}
161+
});
162+
163+
const bidCopy = Object.assign({ }, bid);
164+
bidCopy.adserverTargeting = {
165+
hb_adid: 'ad_id',
166+
};
167+
168+
const url = parse(buildDfpVideoUrl({
169+
adUnit: adUnitsCopy,
170+
bid: bidCopy,
171+
params: {
172+
'iu': 'my/adUnit'
173+
}
174+
}));
175+
const queryObject = parseQS(url.query);
176+
const customParams = parseQS('?' + decodeURIComponent(queryObject.cust_params));
177+
178+
expect(customParams).to.have.property('hb_adid', 'ad_id');
179+
expect(customParams).to.have.property('hb_uuid', bid.videoCacheKey);
180+
expect(customParams).to.have.property('hb_cache_id', bid.videoCacheKey);
181+
expect(customParams).to.have.property('hb_bidder_appnexus', 'appnexus');
182+
expect(customParams).to.have.property('hb_bidder_testBidder2', 'testBidder2');
183+
});
184+
});
185+
110186
it('should merge the user-provided cust_params with the default ones', () => {
111187
const bidCopy = Object.assign({ }, bid);
112188
bidCopy.adserverTargeting = {

0 commit comments

Comments
 (0)