Skip to content

Commit

Permalink
consolidated referrer logic and added pageUrl support from config in …
Browse files Browse the repository at this point in the history
…rubicon (prebid#2087)
  • Loading branch information
snapwich authored and dluxemburg committed Jul 17, 2018
1 parent 592ef8e commit 6cc9fc3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
17 changes: 12 additions & 5 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,21 @@ export const spec = {
return bidRequests.map(bidRequest => {
bidRequest.startTime = new Date().getTime();

let page_url = config.getConfig('pageUrl');
if (bidRequest.params.referrer) {
page_url = bidRequest.params.referrer;
} else if (!page_url) {
page_url = utils.getTopWindowUrl();
}

page_url = bidRequest.params.secure ? page_url.replace(/^http:/i, 'https:') : page_url;

if (bidRequest.mediaType === 'video') {
let params = bidRequest.params;
let size = parseSizes(bidRequest);
let page_rf = !params.referrer ? utils.getTopWindowUrl() : params.referrer;

let data = {
page_url: params.secure ? page_rf.replace(/^http:/i, 'https:') : page_rf,
page_url,
resolution: _getScreenResolution(),
account_id: params.accountId,
integration: INTEGRATION,
Expand Down Expand Up @@ -172,8 +180,7 @@ export const spec = {
keywords,
visitor,
inventory,
userId,
referrer: pageUrl
userId
} = bidRequest.params;

// defaults
Expand Down Expand Up @@ -210,7 +217,7 @@ export const spec = {

data.push(
'rand', Math.random(),
'rf', !pageUrl ? utils.getTopWindowUrl() : pageUrl
'rf', page_url
);

data = data.concat(_getDigiTrustQueryParams());
Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parse as parseQuery } from 'querystring';
import { newBidder } from 'src/adapters/bidderFactory';
import { userSync } from 'src/userSync';
import { config } from 'src/config';
import * as utils from 'src/utils';

var CONSTANTS = require('src/constants.json');

Expand Down Expand Up @@ -159,6 +160,31 @@ describe('the rubicon adapter', () => {
});
});

it('page_url should use params.referrer, config.getConfig("pageUrl"), utils.getTopWindowUrl() in that order', () => {
sandbox.stub(utils, 'getTopWindowUrl', () => 'http://www.prebid.org');

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
expect(parseQuery(request.data).rf).to.equal('localhost');

delete bidderRequest.bids[0].params.referrer;
[request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
expect(parseQuery(request.data).rf).to.equal('http://www.prebid.org');

let origGetConfig = config.getConfig;
sandbox.stub(config, 'getConfig', function(key) {
if (key === 'pageUrl') {
return 'http://www.rubiconproject.com';
}
return origGetConfig.apply(config, arguments);
});
[request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
expect(parseQuery(request.data).rf).to.equal('http://www.rubiconproject.com');

bidderRequest.bids[0].params.secure = true;
[request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
expect(parseQuery(request.data).rf).to.equal('https://www.rubiconproject.com');
});

it('should use rubicon sizes if present (including non-mappable sizes)', () => {
var sizesBidderRequest = clone(bidderRequest);
sizesBidderRequest.bids[0].params.sizes = [55, 57, 59, 801];
Expand Down

0 comments on commit 6cc9fc3

Please sign in to comment.