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

AdagioBidAdapter: site information detection (use refererInfo) #8407

Merged
merged 1 commit into from
May 11, 2022
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
28 changes: 5 additions & 23 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,32 +269,14 @@ function getDevice() {
};

function getSite(bidderRequest) {
let domain = '';
let page = '';
let referrer = '';

const { refererInfo } = bidderRequest;

if (canAccessTopWindow()) {
const wt = getWindowTop();
domain = wt.location.hostname;
page = wt.location.href;
referrer = wt.document.referrer || '';
} else if (refererInfo.reachedTop) {
const url = parseUrl(refererInfo.referer);
domain = url.hostname;
page = refererInfo.referer;
} else if (refererInfo.stack && refererInfo.stack.length && refererInfo.stack[0]) {
// important note check if refererInfo.stack[0] is 'thruly' because a `null` value
// will be considered as "localhost" by the parseUrl function.
const url = parseUrl(refererInfo.stack[0]);
domain = url.hostname;
}
const url = parseUrl(refererInfo.referer);

return {
domain,
page,
referrer
domain: url.hostname || '',
page: refererInfo.referer || '',
referrer: canAccessTopWindow() ? getWindowTop().document.referrer || '' : getWindowSelf().document.referrer || '',
top: refererInfo.reachedTop
};
};

Expand Down
51 changes: 16 additions & 35 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1395,19 +1395,25 @@ describe('Adagio bid adapter', () => {
refererInfo: {
numIframes: 0,
reachedTop: true,
referer: 'http://test.io/index.html?pbjs_debug=true'
referer: 'https://test.io/article/a.html'
}
}).build();

expect(adagio.getSite(bidderRequest)).to.deep.equal({
domain: 'test.io',
page: 'https://test.io/article/a.html',
referrer: 'https://google.com'
referrer: 'https://google.com',
top: true
});
});

it('should returns domain and page in a cross-domain w/ top domain reached context', function() {
sandbox.stub(utils, 'getWindowTop').throws();
sandbox.stub(utils, 'getWindowSelf').returns({
document: {
referrer: 'https://google.com'
}
});

const info = {
numIframes: 0,
Expand All @@ -1428,11 +1434,12 @@ describe('Adagio bid adapter', () => {
expect(adagio.getSite(bidderRequest)).to.deep.equal({
domain: 'level.io',
page: 'http://level.io/',
referrer: ''
referrer: 'https://google.com',
top: true
});
});

it('should not return anything in a cross-domain w/o top domain reached and w/o ancestor context', function() {
it('should return info in a cross-domain w/o top domain reached and w/o ancestor context', function() {
sandbox.stub(utils, 'getWindowTop').throws();

const info = {
Expand All @@ -1451,37 +1458,11 @@ describe('Adagio bid adapter', () => {
refererInfo: info
}).build();

expect(adagio.getSite(bidderRequest)).to.deep.equal({
domain: '',
page: '',
referrer: ''
});
});

it('should return domain only in a cross-domain w/o top domain reached and w/ ancestors context', function() {
sandbox.stub(utils, 'getWindowTop').throws();

const info = {
numIframes: 2,
reachedTop: false,
referer: 'http://example.com/iframe1.html',
stack: [
'http://mytest.com/',
'http://example.com/iframe1.html',
'http://example.com/iframe2.html'
],
canonicalUrl: ''
};

const bidderRequest = new BidderRequestBuilder({
refererInfo: info
}).build();

expect(adagio.getSite(bidderRequest)).to.deep.equal({
domain: 'mytest.com',
page: '',
referrer: ''
});
const s = adagio.getSite(bidderRequest)
expect(s.domain).equal('example.com')
expect(s.page).equal('http://example.com/iframe1.html')
expect(s.referrer).match(/^https?:\/\/.+/);
expect(s.top).equal(false)
});
});

Expand Down