Skip to content

Commit

Permalink
convert bidders: amx
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed May 19, 2022
1 parent fafb541 commit 2ef8eaf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
19 changes: 5 additions & 14 deletions modules/amxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,9 @@ const VAST_RXP = /^\s*<\??(?:vast|xml)/i;
const TRACKING_ENDPOINT = 'https://1x1.a-mo.net/hbx/';
const AMUID_KEY = '__amuidpb';

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);
function getLocation(request) {
// TODO: does it make sense to fall back to window.location?
return parseUrl(request.refererInfo?.topmostLocation || window.location.href)
};

const largestSize = (sizes, mediaTypes) => {
Expand Down Expand Up @@ -243,8 +233,9 @@ export const spec = {
gs: deepAccess(bidderRequest, 'gdprConsent.gdprApplies', ''),
gc: deepAccess(bidderRequest, 'gdprConsent.consentString', ''),
u: deepAccess(bidderRequest, 'refererInfo.canonicalUrl', loc.href),
// TODO: are these referer values correct?
do: loc.hostname,
re: deepAccess(bidderRequest, 'refererInfo.referer'),
re: deepAccess(bidderRequest, 'refererInfo.ref'),
am: getUIDSafe(),
usp: bidderRequest.uspConsent || '1---',
smt: 1,
Expand Down
28 changes: 8 additions & 20 deletions test/spec/modules/amxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const sampleBidderRequest = {
auctionId: utils.getUniqueIdentifierStr(),
uspConsent: '1YYY',
refererInfo: {
referer: 'https://www.prebid.org',
location: 'https://www.prebid.org',
topmostLocation: 'https://www.prebid.org',
canonicalUrl: 'https://www.prebid.org/the/link/to/the/page'
},
ortb2: sampleFPD
Expand Down Expand Up @@ -227,35 +228,22 @@ describe('AmxBidAdapter', () => {
const { data } = spec.buildRequests([sampleBidRequestBase], {
...sampleBidderRequest,
refererInfo: {
numIframes: 1,
referer: 'http://search-traffic-source.com',
stack: []
location: null,
topmostLocation: null,
ref: 'http://search-traffic-source.com',
}
});
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']
location: null,
topmostLocation: 'http://top-site.com',
ref: 'http://search-traffic-source.com',
}
});
expect(data.do).to.equal('top-site.com');
Expand Down

0 comments on commit 2ef8eaf

Please sign in to comment.