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

Rubicon: PVID & Standardize rubicon get config calls #5780

Merged
merged 2 commits into from
Sep 29, 2020
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
46 changes: 17 additions & 29 deletions modules/rubiconAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,16 @@ const cache = {

const BID_REJECTED_IPF = 'rejected-ipf';

let fpkvs = {};
function updateFpkvs(fpkvs, newKvs) {
const isValid = typeof newKvs === 'object' && Object.keys(newKvs).every(key => typeof newKvs[key] === 'string');
if (!isValid) {
utils.logError('Rubicon Analytics: fpkvs must be object with string keys and values');
return fpkvs;
} else {
return {...fpkvs, ...newKvs};
}
}

let integration, ruleId, wrapperName;
// listen for any rubicon setConfig events and save them to appropriate fields!
export let rubiConf = {
pvid: utils.generateUUID().slice(0, 8)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On intial page load we set first pvid automatically

};
// we are saving these as global to this module so that if a pub accidentally overwrites the entire
// rubicon object, then we do not lose other data
config.getConfig('rubicon', config => {
let rubiConf = config.rubicon;
integration = rubiConf.int_type || integration || DEFAULT_INTEGRATION;
ruleId = rubiConf.rule_name || ruleId;
wrapperName = rubiConf.wrapperName || wrapperName;
fpkvs = rubiConf.fpkvs ? updateFpkvs(fpkvs, rubiConf.fpkvs) : fpkvs
utils.mergeDeep(rubiConf, config.rubicon);
if (utils.deepAccess(config, 'rubicon.updatePageView') === true) {
rubiConf.pvid = utils.generateUUID().slice(0, 8)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deep merge everything, but if this specific setConfig call wants us to regenerate the pvid, we do so.

});

export function getHostNameFromReferer(referer) {
Expand Down Expand Up @@ -163,13 +152,13 @@ function sendMessage(auctionId, bidWonId) {
let referrer = config.getConfig('pageUrl') || (auctionCache && auctionCache.referrer);
let message = {
eventTimeMillis: Date.now(),
integration,
ruleId,
integration: rubiConf.int_type || DEFAULT_INTEGRATION,
ruleId: rubiConf.rule_name,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if never set, then it will be undefined here and thus not sent after the stringify occurs!

version: '$prebid.version$',
referrerUri: referrer,
referrerHostname: rubiconAdapter.referrerHostname || getHostNameFromReferer(referrer),
channel: 'web',
wrapperName
wrapperName: rubiConf.wrapperName
};
if (auctionCache && !auctionCache.sent) {
let adUnitMap = Object.keys(auctionCache.bids).reduce((adUnits, bidId) => {
Expand Down Expand Up @@ -359,10 +348,9 @@ export function parseBidResponse(bid, previousBidResponse, auctionFloorData) {
]);
}

function getPageViewId() {
if (prebidGlobal.rp && typeof prebidGlobal.rp.generatePageViewId === 'function') {
return prebidGlobal.rp.generatePageViewId(false);
}
function getFpkvs() {
const isValid = rubiConf.fpkvs && typeof rubiConf.fpkvs === 'object' && Object.keys(rubiConf.fpkvs).every(key => typeof rubiConf.fpkvs[key] === 'string');
return isValid ? rubiConf.fpkvs : {};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sure any set fpkvs are valid before merging, else just empty

}

let samplingFactor = 1;
Expand Down Expand Up @@ -420,8 +408,8 @@ function updateRpaCookie() {
// possible that decodedRpaCookie is undefined, and if it is, we probably are blocked by storage or some other exception
if (Object.keys(decodedRpaCookie).length) {
decodedRpaCookie.lastSeen = currentTime;
decodedRpaCookie.fpkvs = {...decodedRpaCookie.fpkvs, ...fpkvs};
decodedRpaCookie.pvid = getPageViewId();
decodedRpaCookie.fpkvs = {...decodedRpaCookie.fpkvs, ...getFpkvs()};
decodedRpaCookie.pvid = rubiConf.pvid;
setRpaCookie(decodedRpaCookie)
}
return decodedRpaCookie;
Expand Down Expand Up @@ -495,8 +483,8 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
},
disableAnalytics() {
this.getUrl = baseAdapter.getUrl;
accountId = integration = ruleId = wrapperName = undefined;
fpkvs = {};
accountId = undefined;
rubiConf = {};
cache.gpt.registered = false;
baseAdapter.disableAnalytics.apply(this, arguments);
},
Expand Down
48 changes: 17 additions & 31 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,11 @@ import find from 'core-js-pure/features/array/find.js';
const DEFAULT_INTEGRATION = 'pbjs_lite';
const DEFAULT_PBS_INTEGRATION = 'pbjs';

// always use https, regardless of whether or not current page is secure
export let fastlaneEndpoint = `https://fastlane.rubiconproject.com/a/api/fastlane.json`;
export let videoEndpoint = `https://prebid-server.rubiconproject.com/openrtb2/auction`;
export let syncEndpoint = `https://eus.rubiconproject.com/usync.html`;
let returnVast = false;

let bannerHost = 'fastlane';
let videoHost = 'prebid-server';
let syncHost = 'eus';
let rubiConf = {};
// we are saving these as global to this module so that if a pub accidentally overwrites the entire
// rubicon object, then we do not lose other data
config.getConfig('rubicon', config => {
let rubiConf = config.rubicon;
bannerHost = rubiConf.bannerHost || bannerHost;
fastlaneEndpoint = `https://${bannerHost}.rubiconproject.com/a/api/fastlane.json`;
videoHost = rubiConf.videoHost || videoHost;
videoEndpoint = `https://${videoHost}.rubiconproject.com/openrtb2/auction`;
syncHost = rubiConf.syncHost || syncHost;
syncEndpoint = `https://${syncHost}.rubiconproject.com/usync.html`;
returnVast = rubiConf.returnVast === true; // anything other than true is false
utils.mergeDeep(rubiConf, config.rubicon);
});

const GVLID = 52;
Expand Down Expand Up @@ -192,7 +179,7 @@ export const spec = {
prebid: {
cache: {
vastxml: {
returnCreative: returnVast
returnCreative: rubiConf.returnVast === true
}
},
targeting: {
Expand All @@ -203,7 +190,7 @@ export const spec = {
},
bidders: {
rubicon: {
integration: config.getConfig('rubicon.int_type') || DEFAULT_PBS_INTEGRATION
integration: rubiConf.int_type || DEFAULT_PBS_INTEGRATION
}
}
}
Expand All @@ -218,7 +205,7 @@ export const spec = {
}

let bidFloor;
if (typeof bidRequest.getFloor === 'function' && !config.getConfig('rubicon.disableFloors')) {
if (typeof bidRequest.getFloor === 'function' && !rubiConf.disableFloors) {
let floorInfo;
try {
floorInfo = bidRequest.getFloor({
Expand Down Expand Up @@ -343,19 +330,19 @@ export const spec = {

return {
method: 'POST',
url: videoEndpoint,
url: `https://${rubiConf.videoHost || 'prebid-server'}.rubiconproject.com/openrtb2/auction`,
data,
bidRequest
}
});

if (config.getConfig('rubicon.singleRequest') !== true) {
if (rubiConf.singleRequest !== true) {
// bids are not grouped if single request mode is not enabled
requests = videoRequests.concat(bidRequests.filter(bidRequest => bidType(bidRequest) === 'banner').map(bidRequest => {
const bidParams = spec.createSlotParams(bidRequest, bidderRequest);
return {
method: 'GET',
url: fastlaneEndpoint,
url: `https://${rubiConf.bannerHost || 'fastlane'}.rubiconproject.com/a/api/fastlane.json`,
data: spec.getOrderedParams(bidParams).reduce((paramString, key) => {
const propValue = bidParams[key];
return ((utils.isStr(propValue) && propValue !== '') || utils.isNumber(propValue)) ? `${paramString}${encodeParam(key, propValue)}&` : paramString;
Expand Down Expand Up @@ -386,7 +373,7 @@ export const spec = {
// SRA request returns grouped bidRequest arrays not a plain bidRequest
aggregate.push({
method: 'GET',
url: fastlaneEndpoint,
url: `https://${rubiConf.bannerHost || 'fastlane'}.rubiconproject.com/a/api/fastlane.json`,
data: spec.getOrderedParams(combinedSlotParams).reduce((paramString, key) => {
const propValue = combinedSlotParams[key];
return ((utils.isStr(propValue) && propValue !== '') || utils.isNumber(propValue)) ? `${paramString}${encodeParam(key, propValue)}&` : paramString;
Expand Down Expand Up @@ -493,8 +480,6 @@ export const spec = {

const [latitude, longitude] = params.latLong || [];

const configIntType = config.getConfig('rubicon.int_type');

const data = {
'account_id': params.accountId,
'site_id': params.siteId,
Expand All @@ -503,7 +488,7 @@ export const spec = {
'alt_size_ids': parsedSizes.slice(1).join(',') || undefined,
'rp_floor': (params.floor = parseFloat(params.floor)) > 0.01 ? params.floor : 0.01,
'rp_secure': '1',
'tk_flint': `${configIntType || DEFAULT_INTEGRATION}_v$prebid.version$`,
'tk_flint': `${rubiConf.int_type || DEFAULT_INTEGRATION}_v$prebid.version$`,
'x_source.tid': bidRequest.transactionId,
'x_source.pchain': params.pchain,
'p_screen_res': _getScreenResolution(),
Expand All @@ -515,7 +500,7 @@ export const spec = {
};

// If floors module is enabled and we get USD floor back, send it in rp_hard_floor else undfined
if (typeof bidRequest.getFloor === 'function' && !config.getConfig('rubicon.disableFloors')) {
if (typeof bidRequest.getFloor === 'function' && !rubiConf.disableFloors) {
let floorInfo;
try {
floorInfo = bidRequest.getFloor({
Expand Down Expand Up @@ -698,7 +683,7 @@ export const spec = {
cpm: bid.price || 0,
bidderCode: seatbid.seat,
ttl: 300,
netRevenue: config.getConfig('rubicon.netRevenue') !== false, // If anything other than false, netRev is true
netRevenue: rubiConf.netRevenue !== false, // If anything other than false, netRev is true
width: bid.w || utils.deepAccess(bidRequest, 'mediaTypes.video.w') || utils.deepAccess(bidRequest, 'params.video.playerWidth'),
height: bid.h || utils.deepAccess(bidRequest, 'mediaTypes.video.h') || utils.deepAccess(bidRequest, 'params.video.playerHeight'),
};
Expand Down Expand Up @@ -778,7 +763,7 @@ export const spec = {
cpm: ad.cpm || 0,
dealId: ad.deal,
ttl: 300, // 5 minutes
netRevenue: config.getConfig('rubicon.netRevenue') !== false, // If anything other than false, netRev is true
netRevenue: rubiConf.netRevenue !== false, // If anything other than false, netRev is true
rubicon: {
advertiserId: ad.advertiser, networkId: ad.network
},
Expand Down Expand Up @@ -840,7 +825,7 @@ export const spec = {
hasSynced = true;
return {
type: 'iframe',
url: syncEndpoint + params
url: `https://${rubiConf.syncHost || 'eus'}.rubiconproject.com/usync.html` + params
};
}
},
Expand Down Expand Up @@ -1086,6 +1071,7 @@ function bidType(bid, log = false) {
}
}

export const resetRubiConf = () => rubiConf = {};
export function masSizeOrdering(sizes) {
const MAS_SIZE_PRIORITY = [15, 2, 9];

Expand Down
Loading