From bcf9ad80ad719ea3bd62ab4b8207d9592792239b Mon Sep 17 00:00:00 2001 From: Nick Jacob Date: Wed, 28 Oct 2020 13:58:45 -0400 Subject: [PATCH] AMX RTB: improve URL handling in request --- modules/amxBidAdapter.js | 24 +++++++++++---- test/spec/modules/amxBidAdapter_spec.js | 39 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/modules/amxBidAdapter.js b/modules/amxBidAdapter.js index 2e9529b633c..a1fa202c154 100644 --- a/modules/amxBidAdapter.js +++ b/modules/amxBidAdapter.js @@ -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 @@ -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(/=+$/, ''); } @@ -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---', diff --git a/test/spec/modules/amxBidAdapter_spec.js b/test/spec/modules/amxBidAdapter_spec.js index 91315da8801..766045b0f3e 100644 --- a/test/spec/modules/amxBidAdapter_spec.js +++ b/test/spec/modules/amxBidAdapter_spec.js @@ -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