Skip to content

Commit e861922

Browse files
committed
rename referer to topmostLocation, make location all-or-nothing
1 parent b31e7cd commit e861922

17 files changed

+115
-114
lines changed

modules/33acrossBidAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function _buildRequestParams(bidRequests, bidderRequest) {
195195

196196
const uspConsent = bidderRequest && bidderRequest.uspConsent;
197197

198-
const pageUrl = (bidderRequest && bidderRequest.refererInfo) ? (bidderRequest.refererInfo.referer) : (undefined);
198+
const pageUrl = bidderRequest?.refererInfo?.page
199199

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

modules/a4gBidAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const spec = {
4444

4545
let data = {
4646
[IFRAME_PARAM_NAME]: 0,
47-
[LOCATION_PARAM_NAME]: (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) ? bidderRequest.refererInfo.referer : window.location.href,
47+
[LOCATION_PARAM_NAME]: bidderRequest.refererInfo?.page,
4848
[SIZE_PARAM_NAME]: sizeParams.join(ARRAY_PARAM_SEPARATOR),
4949
[ID_PARAM_NAME]: idParams.join(ARRAY_PARAM_SEPARATOR),
5050
[ZONE_ID_PARAM_NAME]: zoneIds.join(ARRAY_PARAM_SEPARATOR)

modules/ablidaBidAdapter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export const spec = {
4545
sizes: sizes,
4646
bidId: bidRequest.bidId,
4747
categories: bidRequest.params.categories,
48-
referer: bidderRequest.refererInfo.referer,
48+
// TODO: should referer be 'ref'?
49+
referer: bidderRequest.refererInfo.page,
4950
jaySupported: jaySupported,
5051
device: device,
5152
adapterVersion: 5,

modules/enrichmentFpdModule.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,21 @@ export function findRootDomain(fullDomain = window.location.hostname) {
7070
* Checks for referer and if exists merges into ortb2 global data
7171
*/
7272
function setReferer() {
73-
if (getRefererInfo().referer) mergeDeep(ortb2, { site: { ref: getRefererInfo().referer } });
73+
if (getRefererInfo().ref) mergeDeep(ortb2, { site: { ref: getRefererInfo().ref } });
7474
}
7575

7676
/**
7777
* Checks for canonical url and if exists merges into ortb2 global data
7878
*/
7979
function setPage() {
80-
if (getRefererInfo().canonicalUrl) mergeDeep(ortb2, { site: { page: getRefererInfo().canonicalUrl } });
80+
if (getRefererInfo().page) mergeDeep(ortb2, { site: { page: getRefererInfo().page } });
8181
}
8282

8383
/**
8484
* Checks for canonical url and if exists retrieves domain and merges into ortb2 global data
8585
*/
8686
function setDomain() {
87-
let parseDomain = function(url) {
88-
if (!url || typeof url !== 'string' || url.length === 0) return;
89-
90-
var match = url.match(/^(?:https?:\/\/)?(?:www\.)?(.*?(?=(\?|\#|\/|$)))/i);
91-
92-
return match && match[1];
93-
};
94-
95-
let domain = parseDomain(getRefererInfo().canonicalUrl)
96-
87+
const domain = getRefererInfo().domain;
9788
if (domain) {
9889
mergeDeep(ortb2, { site: { domain: domain } });
9990
mergeDeep(ortb2, { site: { publisher: { domain: findRootDomain(domain) } } });

modules/koblerBidAdapter.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ export const onBidWon = function (bid) {
7474
export const onTimeout = function (timeoutDataArray) {
7575
if (isArray(timeoutDataArray)) {
7676
const refererInfo = getRefererInfo();
77-
const pageUrl = (refererInfo && refererInfo.referer)
78-
? refererInfo.referer
79-
: window.location.href;
77+
// TODO: does it make sense to fall back to window.location.href?
78+
const pageUrl = refererInfo?.page || window.location.href;
8079
timeoutDataArray.forEach(timeoutData => {
8180
const query = parseQueryStringParameters({
8281
ad_unit_code: timeoutData.adUnitCode,

modules/parrableIdSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function fetchId(configParams, gdprConsentData) {
244244
const data = {
245245
eid,
246246
trackers,
247-
url: refererInfo.referer,
247+
url: refererInfo.page,
248248
prebidVersion: '$prebid.version$',
249249
isIframe: inIframe(),
250250
tpcSupport

modules/prebidServerBidAdapter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ Object.assign(ORTB2.prototype, {
874874
request.cur = [adServerCur[0]];
875875
}
876876

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

879879
// pass schain object if it is present
880880
const schain = deepAccess(bidRequests, '0.bids.0.schain');

modules/rakutenBidAdapter/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export const spec = {
2222
l: navigator.browserLanguage ||
2323
navigator.language,
2424
d: document.domain,
25+
// TODO: what are 'tp' and 'pp'?
2526
tp: bidderRequest.refererInfo.stack[0] || window.location.href,
26-
pp: bidderRequest.refererInfo.referer,
27+
pp: bidderRequest.refererInfo.topmostLocation,
2728
gdpr: ((_a = bidderRequest.gdprConsent) === null || _a === void 0 ? void 0 : _a.gdprApplies) ? 1 : 0,
2829
...((_b = bidderRequest.gdprConsent) === null || _b === void 0 ? void 0 : _b.consentString) && {
2930
cd: bidderRequest.gdprConsent.consentString

modules/staqAnalyticsAdapter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ const STAQ_EVENTS = {
2424
}
2525

2626
function buildRequestTemplate(connId) {
27-
const url = staqAdapterRefWin.referer;
28-
const ref = staqAdapterRefWin.referer;
29-
const topLocation = staqAdapterRefWin.referer;
27+
// TODO: what should these pick from refererInfo?
28+
const url = staqAdapterRefWin.topmostLocation;
29+
const ref = staqAdapterRefWin.topmostLocation;
30+
const topLocation = staqAdapterRefWin.topmostLocation;
3031

3132
return {
3233
ver: ANALYTICS_VERSION,

src/refererDetection.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { config } from './config.js';
1212
import {logWarn} from './utils.js';
1313

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

35+
/**
36+
* Extract the domain portion from a URL.
37+
* @param url
38+
*/
39+
export function parseDomain(url) {
40+
try {
41+
url = new URL(ensureProtocol(url));
42+
} catch (e) {
43+
return;
44+
}
45+
url = url.host;
46+
if (url.startsWith('www.')) {
47+
url = url.substring(4);
48+
}
49+
return url;
50+
}
51+
3552
/**
3653
* @param {Window} win Window
3754
* @returns {Function}
@@ -106,6 +123,7 @@ export function detectReferer(win) {
106123
let level = 0;
107124
let valuesFromAmp = false;
108125
let inAmpFrame = false;
126+
let hasTopLocation = false;
109127

110128
do {
111129
const previousWindow = currentWindow;
@@ -130,6 +148,7 @@ export function detectReferer(win) {
130148
try {
131149
foundLocation = context.sourceUrl;
132150
bestLocation = foundLocation;
151+
hasTopLocation = true;
133152

134153
valuesFromAmp = true;
135154

@@ -159,6 +178,9 @@ export function detectReferer(win) {
159178

160179
if (!foundLocation && ancestors && ancestors[level - 1]) {
161180
foundLocation = ancestors[level - 1];
181+
if (currentWindow === win.top) {
182+
hasTopLocation = true;
183+
}
162184
}
163185

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

194216
stack.reverse();
195217

196-
let topLocation, ref;
218+
let ref;
197219
try {
198-
topLocation = win.top.location.href;
199220
ref = win.top.document.referrer;
200221
} catch (e) {}
201222

202-
const page = ensureProtocol(bestCanonicalUrl, win) || topLocation || bestLocation || null;
223+
const location = reachedTop || hasTopLocation ? bestLocation : null;
224+
const page = ensureProtocol(bestCanonicalUrl, win) || location;
203225

204226
return {
205227
reachedTop,
206228
isAmp: valuesFromAmp,
207229
numIframes: level - 1,
208230
stack,
209-
location: bestLocation || null, // our best guess at page location - the topmost reachable frame URL
231+
topmostLocation: bestLocation || null, // location of the topmost accessible frame
232+
location, // location of window.top, if available
210233
canonicalUrl: bestCanonicalUrl || null, // canonical URL as provided with setConfig({pageUrl}) or link[rel="canonical"], in that order of priority
211-
page: page, // canonicalUrl, falling back to location
234+
page, // canonicalUrl, falling back to location
235+
domain: parseDomain(page) || null, // the domain portion of `page`
212236
ref: ref || null, // window.top.document.referrer, if available
213237
};
214238
}

test/spec/modules/33acrossBidAdapter_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ describe('33acrossBidAdapter:', function () {
919919
it('returns corresponding server requests with site.page set', function() {
920920
const bidderRequest = {
921921
refererInfo: {
922-
referer: 'http://foo.com/bar'
922+
page: 'http://foo.com/bar'
923923
}
924924
};
925925

test/spec/modules/enrichmentFpdModule_spec.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ describe('the first party data enrichment module', function() {
5454

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

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

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

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

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

86-
expect(validated.site.ref).to.equal(getRefererInfo().referer);
87-
expect(validated.site.page).to.be.undefined;
88-
expect(validated.site.domain).to.be.undefined;
89-
expect(validated.device).to.deep.equal({ w: 800, h: 500 });
9087
expect(validated.site.keywords).to.equal('value1,value2,value3');
9188
});
9289

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

9996
expect(validated.site.ref).to.equal('https://someUrl.com');
10097
expect(validated.site.page).to.equal('test.com');
101-
expect(validated.site.domain).to.be.undefined;
10298
expect(validated.device).to.deep.equal({ w: 1200, h: 700 });
10399
expect(validated.site.keywords).to.be.undefined;
104100
});

test/spec/modules/fpdModule_spec.js

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -51,63 +51,6 @@ describe('the first party data module', function () {
5151
keywords.name = 'keywords';
5252
});
5353

54-
it('sets default referer and dimension values to ortb2 data', function () {
55-
registerSubmodules(enrichments);
56-
registerSubmodules(validations);
57-
58-
let validated;
59-
60-
width = 1120;
61-
height = 750;
62-
63-
({global: validated} = processFpd());
64-
65-
expect(validated.site.ref).to.equal(getRefererInfo().referer);
66-
expect(validated.site.page).to.be.undefined;
67-
expect(validated.site.domain).to.be.undefined;
68-
expect(validated.device).to.deep.equal({w: 1120, h: 750});
69-
expect(validated.site.keywords).to.be.undefined;
70-
});
71-
72-
it('sets page and domain values to ortb2 data if canonical link exists', function () {
73-
let validated;
74-
75-
canonical.href = 'https://www.domain.com/path?query=12345';
76-
77-
({global: validated} = processFpd());
78-
expect(validated.site.ref).to.equal(getRefererInfo().referer);
79-
expect(validated.site.page).to.equal('https://www.domain.com/path?query=12345');
80-
expect(validated.site.domain).to.equal('domain.com');
81-
expect(validated.device).to.deep.to.equal({w: 1120, h: 750});
82-
expect(validated.site.keywords).to.be.undefined;
83-
});
84-
85-
it('sets keyword values to ortb2 data if keywords meta exists', function () {
86-
let validated;
87-
88-
keywords.content = 'value1,value2,value3';
89-
90-
({global: validated} = processFpd());
91-
expect(validated.site.ref).to.equal(getRefererInfo().referer);
92-
expect(validated.site.page).to.be.undefined;
93-
expect(validated.site.domain).to.be.undefined;
94-
expect(validated.device).to.deep.to.equal({w: 1120, h: 750});
95-
expect(validated.site.keywords).to.equal('value1,value2,value3');
96-
});
97-
98-
it('only sets values that do not exist in ortb2 config', function () {
99-
let validated;
100-
101-
const global = {site: {ref: 'https://testpage.com', domain: 'newDomain.com'}};
102-
103-
({global: validated} = processFpd({global}));
104-
expect(validated.site.ref).to.equal('https://testpage.com');
105-
expect(validated.site.page).to.be.undefined;
106-
expect(validated.site.domain).to.equal('newDomain.com');
107-
expect(validated.device).to.deep.to.equal({w: 1120, h: 750});
108-
expect(validated.site.keywords).to.be.undefined;
109-
});
110-
11154
it('filters ortb2 data that is set', function () {
11255
let validated;
11356
const global = {

test/spec/modules/koblerBidAdapter_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ describe('KoblerAdapter', function () {
693693
expect(utils.triggerPixel.getCall(0).args[0]).to.be.equal(
694694
'https://bid.essrtb.com/notify/prebid_timeout?ad_unit_code=adunit-code&' +
695695
'auction_id=a1fba829-dd41-409f-acfb-b7b0ac5f30c6&bid_id=ef236c6c-e934-406b-a877-d7be8e8a839a&timeout=100&' +
696-
'placement_id=xrwg62731&page_url=' + encodeURIComponent(getRefererInfo().referer)
696+
'placement_id=xrwg62731&page_url=' + encodeURIComponent(getRefererInfo().page)
697697
);
698698
expect(utils.triggerPixel.getCall(1).args[0]).to.be.equal(
699699
'https://bid.essrtb.com/notify/prebid_timeout?ad_unit_code=adunit-code-2&' +
700700
'auction_id=a1fba829-dd41-409f-acfb-b7b0ac5f30c6&bid_id=ca4121c8-9a4a-46ba-a624-e9b64af206f2&timeout=100&' +
701-
'placement_id=bc482234&page_url=' + encodeURIComponent(getRefererInfo().referer)
701+
'placement_id=bc482234&page_url=' + encodeURIComponent(getRefererInfo().page)
702702
);
703703
});
704704
});

test/spec/modules/parrableIdSystem_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('Parrable ID System', function() {
128128
expect(data).to.deep.equal({
129129
eid: P_COOKIE_EID,
130130
trackers: P_CONFIG_MOCK.params.partners.split(','),
131-
url: getRefererInfo().referer,
131+
url: getRefererInfo().page,
132132
prebidVersion: '$prebid.version$',
133133
isIframe: true
134134
});

test/spec/modules/prebidServerBidAdapter_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ describe('S2S Adapter', function () {
510510
'src': 's2s',
511511
'doneCbCallCount': 0,
512512
'refererInfo': {
513-
'referer': 'http://mytestpage.com'
513+
'page': 'http://mytestpage.com'
514514
}
515515
}
516516
];

0 commit comments

Comments
 (0)