Skip to content

Commit de4153b

Browse files
jlquacciajorgeluisrocha
authored andcommitted
updated ref info page logic (prebid#9241)
1 parent 065ffd1 commit de4153b

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

src/refererDetection.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export function detectReferer(win) {
120120
const stack = [];
121121
const ancestors = getAncestorOrigins(win);
122122
const maxNestedIframes = config.getConfig('maxNestedIframes');
123+
123124
let currentWindow;
124125
let bestLocation;
125126
let bestCanonicalUrl;
@@ -226,7 +227,11 @@ export function detectReferer(win) {
226227

227228
const location = reachedTop || hasTopLocation ? bestLocation : null;
228229
const canonicalUrl = config.getConfig('pageUrl') || bestCanonicalUrl || null;
229-
const page = ensureProtocol(canonicalUrl, win) || location;
230+
let page = config.getConfig('pageUrl') || location || ensureProtocol(canonicalUrl, win);
231+
232+
if (location && location.indexOf('?') > -1 && page.indexOf('?') === -1) {
233+
page = `${page}${location.substring(location.indexOf('?'))}`;
234+
}
230235

231236
return {
232237
reachedTop,

test/spec/modules/enrichmentFpdModule_spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai';
2+
import {config} from 'src/config.js';
23
import { getRefererInfo } from 'src/refererDetection.js';
34
import {processFpd, coreStorage, resetEnrichments} from 'modules/enrichmentFpdModule.js';
45
import * as enrichmentModule from 'modules/enrichmentFpdModule.js';
@@ -77,10 +78,10 @@ describe('the first party data enrichment module', function() {
7778
expect(validated.site.keywords).to.be.undefined;
7879
});
7980

80-
it('adds page domain values if canonical url exists', function() {
81+
it('adds page domain values if pageUrl url exists', function() {
82+
config.setConfig({'pageUrl': 'https://www.subdomain.domain.co.uk/path?query=12345'});
8183
width = 800;
8284
height = 500;
83-
canonical.href = 'https://www.subdomain.domain.co.uk/path?query=12345';
8485

8586
let validated = syncProcessFpd({}, {}).global;
8687

test/spec/modules/fpdModule_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('the first party data module', function () {
130130
}
131131
};
132132

133-
canonical.href = 'https://www.domain.com/path?query=12345';
133+
config.setConfig({'pageUrl': 'https://www.domain.com/path?query=12345'});
134134
width = 1120;
135135
height = 750;
136136

test/spec/refererDetection_spec.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,49 @@ describe('Referer detection', () => {
128128
numIframes: 0,
129129
stack: ['https://example.com/some/page'],
130130
canonicalUrl: 'https://example.com/canonical/page',
131-
page: 'https://example.com/canonical/page',
131+
page: 'https://example.com/some/page',
132132
ref: 'https://othersite.com/',
133133
domain: 'example.com'
134134
});
135135
});
136+
137+
it('Should set page and canonical to pageUrl value set in config if present, even if canonical url is also present in head', () => {
138+
config.setConfig({'pageUrl': 'https://www.set-from-config.com/path'});
139+
const testWindow = buildWindowTree(['https://example.com/some/page'], 'https://othersite.com/', 'https://example.com/canonical/page'),
140+
result = detectReferer(testWindow)();
141+
142+
sinon.assert.match(result, {
143+
topmostLocation: 'https://example.com/some/page',
144+
location: 'https://example.com/some/page',
145+
reachedTop: true,
146+
isAmp: false,
147+
numIframes: 0,
148+
stack: ['https://example.com/some/page'],
149+
canonicalUrl: 'https://www.set-from-config.com/path',
150+
page: 'https://www.set-from-config.com/path',
151+
ref: 'https://othersite.com/',
152+
domain: 'www.set-from-config.com'
153+
});
154+
});
155+
156+
it('Should set page with query params if canonical url is present without query params but the current page does have them', () => {
157+
config.setConfig({'pageUrl': 'https://www.set-from-config.com/path'});
158+
const testWindow = buildWindowTree(['https://example.com/some/page?query1=123&query2=456'], 'https://othersite.com/', 'https://example.com/canonical/page'),
159+
result = detectReferer(testWindow)();
160+
161+
sinon.assert.match(result, {
162+
topmostLocation: 'https://example.com/some/page?query1=123&query2=456',
163+
location: 'https://example.com/some/page?query1=123&query2=456',
164+
reachedTop: true,
165+
isAmp: false,
166+
numIframes: 0,
167+
stack: ['https://example.com/some/page?query1=123&query2=456'],
168+
canonicalUrl: 'https://www.set-from-config.com/path',
169+
page: 'https://www.set-from-config.com/path?query1=123&query2=456',
170+
ref: 'https://othersite.com/',
171+
domain: 'www.set-from-config.com'
172+
});
173+
});
136174
});
137175

138176
describe('Friendly iframes', () => {
@@ -174,7 +212,7 @@ describe('Referer detection', () => {
174212
'https://example.com/third/page'
175213
],
176214
canonicalUrl: 'https://example.com/canonical/page',
177-
page: 'https://example.com/canonical/page',
215+
page: 'https://example.com/some/page',
178216
ref: 'https://othersite.com/',
179217
domain: 'example.com'
180218
});
@@ -317,7 +355,7 @@ describe('Referer detection', () => {
317355
'https://ad-iframe.ampproject.org/ad'
318356
],
319357
canonicalUrl: 'https://example.com/some/page/',
320-
page: 'https://example.com/some/page/',
358+
page: 'https://example.com/some/page/amp/',
321359
ref: null,
322360
domain: 'example.com'
323361
});
@@ -344,7 +382,7 @@ describe('Referer detection', () => {
344382
'https://ad-iframe.ampproject.org/ad'
345383
],
346384
canonicalUrl: 'https://example.com/some/page/',
347-
page: 'https://example.com/some/page/',
385+
page: 'https://example.com/some/page/amp/',
348386
ref: null,
349387
domain: 'example.com'
350388
});
@@ -384,7 +422,7 @@ describe('Referer detection', () => {
384422
'https://ad-iframe.ampproject.org/ad'
385423
],
386424
canonicalUrl: 'https://example.com/some/page/',
387-
page: 'https://example.com/some/page/',
425+
page: 'https://example.com/some/page/amp/',
388426
ref: null,
389427
domain: 'example.com',
390428
});
@@ -412,7 +450,7 @@ describe('Referer detection', () => {
412450
'https://ad-iframe.ampproject.org/ad'
413451
],
414452
canonicalUrl: 'https://example.com/some/page/',
415-
page: 'https://example.com/some/page/',
453+
page: 'https://example.com/some/page/amp/',
416454
ref: null,
417455
domain: 'example.com'
418456
});
@@ -441,7 +479,7 @@ describe('Referer detection', () => {
441479
'https://ad-iframe.ampproject.org/ad'
442480
],
443481
canonicalUrl: 'https://example.com/some/page/',
444-
page: 'https://example.com/some/page/',
482+
page: 'https://example.com/some/page/amp/',
445483
ref: null,
446484
domain: 'example.com',
447485
});

0 commit comments

Comments
 (0)