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

AMX RTB: improve URL handling in request #5905

Merged
merged 1 commit into from
Nov 2, 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
24 changes: 18 additions & 6 deletions modules/amxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@ import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'amx';
const storage = getStorageManager(737, BIDDER_CODE);
const SIMPLE_TLD_TEST = /\.co\.\w{2,4}$/;
const SIMPLE_TLD_TEST = /\.com?\.\w{2,4}$/;
const DEFAULT_ENDPOINT = 'https://prebid.a-mo.net/a/c';
const VERSION = 'pba1.2';
const VERSION = 'pba1.2.1';
const xmlDTDRxp = /^\s*<\?xml[^\?]+\?>/;
const VAST_RXP = /^\s*<\??(?:vast|xml)/i;
const TRACKING_ENDPOINT = 'https://1x1.a-mo.net/hbx/';
const AMUID_KEY = '__amuidpb';

const getLocation = (request) =>
parseUrl(deepAccess(request, 'refererInfo.canonicalUrl', location.href))
function getLocation (request) {
const refInfo = request.refererInfo;
if (refInfo == null) {
return parseUrl(location.href);
}

if (refInfo.isAmp && refInfo.referer != null) {
return parseUrl(refInfo.referer)
}

const topUrl = refInfo.numIframes > 0 && refInfo.stack[0] != null
? refInfo.stack[0] : location.href;
return parseUrl(topUrl);
};

const largestSize = (sizes, mediaTypes) => {
const allSizes = sizes
Expand Down Expand Up @@ -44,7 +56,7 @@ const nullOrType = (value, type) =>
function getID(loc) {
const host = loc.hostname.split('.');
const short = host.slice(
host.length - (SIMPLE_TLD_TEST.test(loc.host) ? 3 : 2)
host.length - (SIMPLE_TLD_TEST.test(loc.hostname) ? 3 : 2)
).join('.');
return btoa(short).replace(/=+$/, '');
}
Expand Down Expand Up @@ -239,7 +251,7 @@ export const spec = {
gs: deepAccess(bidderRequest, 'gdprConsent.gdprApplies', ''),
gc: deepAccess(bidderRequest, 'gdprConsent.consentString', ''),
u: deepAccess(bidderRequest, 'refererInfo.canonicalUrl', loc.href),
do: loc.host,
do: loc.hostname,
re: deepAccess(bidderRequest, 'refererInfo.referer'),
am: getUIDSafe(),
usp: bidderRequest.uspConsent || '1---',
Expand Down
39 changes: 39 additions & 0 deletions test/spec/modules/amxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,45 @@ describe('AmxBidAdapter', () => {
expect(data.tm).to.equal(true);
});

it('if prebid is in an iframe, will use the frame url as domain, if the topmost is not avialable', () => {
const { data } = spec.buildRequests([sampleBidRequestBase], {
...sampleBidderRequest,
refererInfo: {
numIframes: 1,
referer: 'http://search-traffic-source.com',
stack: []
}
});
expect(data.do).to.equal('localhost')
expect(data.re).to.equal('http://search-traffic-source.com');
});

it('if we are in AMP, make sure we use the canonical URL or the referrer (which is sourceUrl)', () => {
const { data } = spec.buildRequests([sampleBidRequestBase], {
...sampleBidderRequest,
refererInfo: {
isAmp: true,
referer: 'http://real-publisher-site.com/content',
stack: []
}
});
expect(data.do).to.equal('real-publisher-site.com')
expect(data.re).to.equal('http://real-publisher-site.com/content');
})

it('if prebid is in an iframe, will use the topmost url as domain', () => {
const { data } = spec.buildRequests([sampleBidRequestBase], {
...sampleBidderRequest,
refererInfo: {
numIframes: 1,
referer: 'http://search-traffic-source.com',
stack: ['http://top-site.com', 'http://iframe.com']
}
});
expect(data.do).to.equal('top-site.com');
expect(data.re).to.equal('http://search-traffic-source.com');
});

it('handles referer data and GDPR, USP Consent, COPPA', () => {
const { data } = spec.buildRequests([sampleBidRequestBase], sampleBidderRequest);
delete data.m; // don't deal with "m" in this test
Expand Down