Skip to content

Commit

Permalink
rename referer to topmostLocation, make location all-or-nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed May 18, 2022
1 parent b31e7cd commit e861922
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 114 deletions.
2 changes: 1 addition & 1 deletion modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function _buildRequestParams(bidRequests, bidderRequest) {

const uspConsent = bidderRequest && bidderRequest.uspConsent;

const pageUrl = (bidderRequest && bidderRequest.refererInfo) ? (bidderRequest.refererInfo.referer) : (undefined);
const pageUrl = bidderRequest?.refererInfo?.page

adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(uniques);

Expand Down
2 changes: 1 addition & 1 deletion modules/a4gBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const spec = {

let data = {
[IFRAME_PARAM_NAME]: 0,
[LOCATION_PARAM_NAME]: (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) ? bidderRequest.refererInfo.referer : window.location.href,
[LOCATION_PARAM_NAME]: bidderRequest.refererInfo?.page,
[SIZE_PARAM_NAME]: sizeParams.join(ARRAY_PARAM_SEPARATOR),
[ID_PARAM_NAME]: idParams.join(ARRAY_PARAM_SEPARATOR),
[ZONE_ID_PARAM_NAME]: zoneIds.join(ARRAY_PARAM_SEPARATOR)
Expand Down
3 changes: 2 additions & 1 deletion modules/ablidaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export const spec = {
sizes: sizes,
bidId: bidRequest.bidId,
categories: bidRequest.params.categories,
referer: bidderRequest.refererInfo.referer,
// TODO: should referer be 'ref'?
referer: bidderRequest.refererInfo.page,
jaySupported: jaySupported,
device: device,
adapterVersion: 5,
Expand Down
15 changes: 3 additions & 12 deletions modules/enrichmentFpdModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,21 @@ export function findRootDomain(fullDomain = window.location.hostname) {
* Checks for referer and if exists merges into ortb2 global data
*/
function setReferer() {
if (getRefererInfo().referer) mergeDeep(ortb2, { site: { ref: getRefererInfo().referer } });
if (getRefererInfo().ref) mergeDeep(ortb2, { site: { ref: getRefererInfo().ref } });
}

/**
* Checks for canonical url and if exists merges into ortb2 global data
*/
function setPage() {
if (getRefererInfo().canonicalUrl) mergeDeep(ortb2, { site: { page: getRefererInfo().canonicalUrl } });
if (getRefererInfo().page) mergeDeep(ortb2, { site: { page: getRefererInfo().page } });
}

/**
* Checks for canonical url and if exists retrieves domain and merges into ortb2 global data
*/
function setDomain() {
let parseDomain = function(url) {
if (!url || typeof url !== 'string' || url.length === 0) return;

var match = url.match(/^(?:https?:\/\/)?(?:www\.)?(.*?(?=(\?|\#|\/|$)))/i);

return match && match[1];
};

let domain = parseDomain(getRefererInfo().canonicalUrl)

const domain = getRefererInfo().domain;
if (domain) {
mergeDeep(ortb2, { site: { domain: domain } });
mergeDeep(ortb2, { site: { publisher: { domain: findRootDomain(domain) } } });
Expand Down
5 changes: 2 additions & 3 deletions modules/koblerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ export const onBidWon = function (bid) {
export const onTimeout = function (timeoutDataArray) {
if (isArray(timeoutDataArray)) {
const refererInfo = getRefererInfo();
const pageUrl = (refererInfo && refererInfo.referer)
? refererInfo.referer
: window.location.href;
// TODO: does it make sense to fall back to window.location.href?
const pageUrl = refererInfo?.page || window.location.href;
timeoutDataArray.forEach(timeoutData => {
const query = parseQueryStringParameters({
ad_unit_code: timeoutData.adUnitCode,
Expand Down
2 changes: 1 addition & 1 deletion modules/parrableIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function fetchId(configParams, gdprConsentData) {
const data = {
eid,
trackers,
url: refererInfo.referer,
url: refererInfo.page,
prebidVersion: '$prebid.version$',
isIframe: inIframe(),
tpcSupport
Expand Down
2 changes: 1 addition & 1 deletion modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ Object.assign(ORTB2.prototype, {
request.cur = [adServerCur[0]];
}

_appendSiteAppDevice(request, bidRequests[0].refererInfo.referer, s2sConfig.accountId);
_appendSiteAppDevice(request, bidRequests[0].refererInfo.page, s2sConfig.accountId);

// pass schain object if it is present
const schain = deepAccess(bidRequests, '0.bids.0.schain');
Expand Down
3 changes: 2 additions & 1 deletion modules/rakutenBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export const spec = {
l: navigator.browserLanguage ||
navigator.language,
d: document.domain,
// TODO: what are 'tp' and 'pp'?
tp: bidderRequest.refererInfo.stack[0] || window.location.href,
pp: bidderRequest.refererInfo.referer,
pp: bidderRequest.refererInfo.topmostLocation,
gdpr: ((_a = bidderRequest.gdprConsent) === null || _a === void 0 ? void 0 : _a.gdprApplies) ? 1 : 0,
...((_b = bidderRequest.gdprConsent) === null || _b === void 0 ? void 0 : _b.consentString) && {
cd: bidderRequest.gdprConsent.consentString
Expand Down
7 changes: 4 additions & 3 deletions modules/staqAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ const STAQ_EVENTS = {
}

function buildRequestTemplate(connId) {
const url = staqAdapterRefWin.referer;
const ref = staqAdapterRefWin.referer;
const topLocation = staqAdapterRefWin.referer;
// TODO: what should these pick from refererInfo?
const url = staqAdapterRefWin.topmostLocation;
const ref = staqAdapterRefWin.topmostLocation;
const topLocation = staqAdapterRefWin.topmostLocation;

return {
ver: ANALYTICS_VERSION,
Expand Down
36 changes: 30 additions & 6 deletions src/refererDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { config } from './config.js';
import {logWarn} from './utils.js';

/**
* Convert urls of the form "example.com" or "//example.com" to "http(s)://example.com"
* Prepend a URL with the page's protocol (http/https), if necessary.
*/
export function ensureProtocol(url, win = window) {
if (!url) return url;
Expand All @@ -32,6 +32,23 @@ export function ensureProtocol(url, win = window) {
}
}

/**
* Extract the domain portion from a URL.
* @param url
*/
export function parseDomain(url) {
try {
url = new URL(ensureProtocol(url));
} catch (e) {
return;
}
url = url.host;
if (url.startsWith('www.')) {
url = url.substring(4);
}
return url;
}

/**
* @param {Window} win Window
* @returns {Function}
Expand Down Expand Up @@ -106,6 +123,7 @@ export function detectReferer(win) {
let level = 0;
let valuesFromAmp = false;
let inAmpFrame = false;
let hasTopLocation = false;

do {
const previousWindow = currentWindow;
Expand All @@ -130,6 +148,7 @@ export function detectReferer(win) {
try {
foundLocation = context.sourceUrl;
bestLocation = foundLocation;
hasTopLocation = true;

valuesFromAmp = true;

Expand Down Expand Up @@ -159,6 +178,9 @@ export function detectReferer(win) {

if (!foundLocation && ancestors && ancestors[level - 1]) {
foundLocation = ancestors[level - 1];
if (currentWindow === win.top) {
hasTopLocation = true;
}
}

if (foundLocation && !valuesFromAmp) {
Expand Down Expand Up @@ -193,22 +215,24 @@ export function detectReferer(win) {

stack.reverse();

let topLocation, ref;
let ref;
try {
topLocation = win.top.location.href;
ref = win.top.document.referrer;
} catch (e) {}

const page = ensureProtocol(bestCanonicalUrl, win) || topLocation || bestLocation || null;
const location = reachedTop || hasTopLocation ? bestLocation : null;
const page = ensureProtocol(bestCanonicalUrl, win) || location;

return {
reachedTop,
isAmp: valuesFromAmp,
numIframes: level - 1,
stack,
location: bestLocation || null, // our best guess at page location - the topmost reachable frame URL
topmostLocation: bestLocation || null, // location of the topmost accessible frame
location, // location of window.top, if available
canonicalUrl: bestCanonicalUrl || null, // canonical URL as provided with setConfig({pageUrl}) or link[rel="canonical"], in that order of priority
page: page, // canonicalUrl, falling back to location
page, // canonicalUrl, falling back to location
domain: parseDomain(page) || null, // the domain portion of `page`
ref: ref || null, // window.top.document.referrer, if available
};
}
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/33acrossBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ describe('33acrossBidAdapter:', function () {
it('returns corresponding server requests with site.page set', function() {
const bidderRequest = {
refererInfo: {
referer: 'http://foo.com/bar'
page: 'http://foo.com/bar'
}
};

Expand Down
14 changes: 5 additions & 9 deletions test/spec/modules/enrichmentFpdModule_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ describe('the first party data enrichment module', function() {

let validated = processFpd({}, {}).global;

expect(validated.site.ref).to.equal(getRefererInfo().referer);
expect(validated.site.page).to.be.undefined;
expect(validated.site.domain).to.be.undefined;
const {ref, page, domain} = getRefererInfo();
expect(validated.site.ref).to.equal(ref || undefined);
expect(validated.site.page).to.equal(page || undefined)
expect(validated.site.domain).to.equal(domain || undefined)
expect(validated.device).to.deep.equal({ w: 800, h: 500 });
expect(validated.site.keywords).to.be.undefined;
});
Expand All @@ -68,7 +69,7 @@ describe('the first party data enrichment module', function() {

let validated = processFpd({}, {}).global;

expect(validated.site.ref).to.equal(getRefererInfo().referer);
expect(validated.site.ref).to.equal(getRefererInfo().ref || undefined);
expect(validated.site.page).to.equal('https://www.subdomain.domain.co.uk/path?query=12345');
expect(validated.site.domain).to.equal('subdomain.domain.co.uk');
expect(validated.site.publisher.domain).to.equal('domain.co.uk');
Expand All @@ -83,10 +84,6 @@ describe('the first party data enrichment module', function() {

let validated = processFpd({}, {}).global;

expect(validated.site.ref).to.equal(getRefererInfo().referer);
expect(validated.site.page).to.be.undefined;
expect(validated.site.domain).to.be.undefined;
expect(validated.device).to.deep.equal({ w: 800, h: 500 });
expect(validated.site.keywords).to.equal('value1,value2,value3');
});

Expand All @@ -98,7 +95,6 @@ describe('the first party data enrichment module', function() {

expect(validated.site.ref).to.equal('https://someUrl.com');
expect(validated.site.page).to.equal('test.com');
expect(validated.site.domain).to.be.undefined;
expect(validated.device).to.deep.equal({ w: 1200, h: 700 });
expect(validated.site.keywords).to.be.undefined;
});
Expand Down
57 changes: 0 additions & 57 deletions test/spec/modules/fpdModule_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,63 +51,6 @@ describe('the first party data module', function () {
keywords.name = 'keywords';
});

it('sets default referer and dimension values to ortb2 data', function () {
registerSubmodules(enrichments);
registerSubmodules(validations);

let validated;

width = 1120;
height = 750;

({global: validated} = processFpd());

expect(validated.site.ref).to.equal(getRefererInfo().referer);
expect(validated.site.page).to.be.undefined;
expect(validated.site.domain).to.be.undefined;
expect(validated.device).to.deep.equal({w: 1120, h: 750});
expect(validated.site.keywords).to.be.undefined;
});

it('sets page and domain values to ortb2 data if canonical link exists', function () {
let validated;

canonical.href = 'https://www.domain.com/path?query=12345';

({global: validated} = processFpd());
expect(validated.site.ref).to.equal(getRefererInfo().referer);
expect(validated.site.page).to.equal('https://www.domain.com/path?query=12345');
expect(validated.site.domain).to.equal('domain.com');
expect(validated.device).to.deep.to.equal({w: 1120, h: 750});
expect(validated.site.keywords).to.be.undefined;
});

it('sets keyword values to ortb2 data if keywords meta exists', function () {
let validated;

keywords.content = 'value1,value2,value3';

({global: validated} = processFpd());
expect(validated.site.ref).to.equal(getRefererInfo().referer);
expect(validated.site.page).to.be.undefined;
expect(validated.site.domain).to.be.undefined;
expect(validated.device).to.deep.to.equal({w: 1120, h: 750});
expect(validated.site.keywords).to.equal('value1,value2,value3');
});

it('only sets values that do not exist in ortb2 config', function () {
let validated;

const global = {site: {ref: 'https://testpage.com', domain: 'newDomain.com'}};

({global: validated} = processFpd({global}));
expect(validated.site.ref).to.equal('https://testpage.com');
expect(validated.site.page).to.be.undefined;
expect(validated.site.domain).to.equal('newDomain.com');
expect(validated.device).to.deep.to.equal({w: 1120, h: 750});
expect(validated.site.keywords).to.be.undefined;
});

it('filters ortb2 data that is set', function () {
let validated;
const global = {
Expand Down
4 changes: 2 additions & 2 deletions test/spec/modules/koblerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,12 @@ describe('KoblerAdapter', function () {
expect(utils.triggerPixel.getCall(0).args[0]).to.be.equal(
'https://bid.essrtb.com/notify/prebid_timeout?ad_unit_code=adunit-code&' +
'auction_id=a1fba829-dd41-409f-acfb-b7b0ac5f30c6&bid_id=ef236c6c-e934-406b-a877-d7be8e8a839a&timeout=100&' +
'placement_id=xrwg62731&page_url=' + encodeURIComponent(getRefererInfo().referer)
'placement_id=xrwg62731&page_url=' + encodeURIComponent(getRefererInfo().page)
);
expect(utils.triggerPixel.getCall(1).args[0]).to.be.equal(
'https://bid.essrtb.com/notify/prebid_timeout?ad_unit_code=adunit-code-2&' +
'auction_id=a1fba829-dd41-409f-acfb-b7b0ac5f30c6&bid_id=ca4121c8-9a4a-46ba-a624-e9b64af206f2&timeout=100&' +
'placement_id=bc482234&page_url=' + encodeURIComponent(getRefererInfo().referer)
'placement_id=bc482234&page_url=' + encodeURIComponent(getRefererInfo().page)
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/parrableIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Parrable ID System', function() {
expect(data).to.deep.equal({
eid: P_COOKIE_EID,
trackers: P_CONFIG_MOCK.params.partners.split(','),
url: getRefererInfo().referer,
url: getRefererInfo().page,
prebidVersion: '$prebid.version$',
isIframe: true
});
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ describe('S2S Adapter', function () {
'src': 's2s',
'doneCbCallCount': 0,
'refererInfo': {
'referer': 'http://mytestpage.com'
'page': 'http://mytestpage.com'
}
}
];
Expand Down
Loading

0 comments on commit e861922

Please sign in to comment.