Skip to content

Commit

Permalink
convert bidders: apacdex
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed May 19, 2022
1 parent 2ef8eaf commit 2d57f41
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 66 deletions.
5 changes: 3 additions & 2 deletions modules/amxIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ export const amxIdSubmodule = {

const params = {
tagId: deepAccess(config, 'params.tagId', ''),
ref: ref.referer,
u: ref.stack[0] || getWindowTop().location.href,
// TODO: are these referer values correct?
ref: ref.ref,
u: ref.location,
v: '$prebid.version$',
vg: '$$PREBID_GLOBAL$$',
us_privacy: usp,
Expand Down
7 changes: 2 additions & 5 deletions modules/aniviewBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ function buildRequests(validBidRequests, bidderRequest) {

if (s2sParams.AV_APPPKGNAME && !s2sParams.AV_URL) { s2sParams.AV_URL = s2sParams.AV_APPPKGNAME; }
if (!s2sParams.AV_IDFA && !s2sParams.AV_URL) {
if (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer) {
s2sParams.AV_URL = bidderRequest.refererInfo.referer;
} else {
s2sParams.AV_URL = window.location.href;
}
// TODO: does it make sense to fall back to window.location here?
s2sParams.AV_URL = bidderRequest?.refererInfo?.page || window.location.href;
}
if (s2sParams.AV_IDFA && !s2sParams.AV_AID) { s2sParams.AV_AID = s2sParams.AV_IDFA; }
if (s2sParams.AV_AID && !s2sParams.AV_IDFA) { s2sParams.AV_IDFA = s2sParams.AV_AID; }
Expand Down
48 changes: 7 additions & 41 deletions modules/apacdexBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { deepAccess, isPlainObject, isArray, replaceAuctionPrice, isFn } from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import {parseDomain} from '../src/refererDetection.js';
const BIDDER_CODE = 'apacdex';
const ENDPOINT = 'https://useast.quantumdex.io/auction/pbjs'
const USERSYNC = 'https://sync.quantumdex.io/usersync/pbjs'
Expand Down Expand Up @@ -103,7 +104,8 @@ export const spec = {
payload.site = {};
payload.site.page = pageUrl
payload.site.referrer = _extractTopWindowReferrerFromBidderRequest(bidderRequest);
payload.site.hostname = getDomain(pageUrl);
// TODO: does it make sense to fall back to window.location for the domain?
payload.site.hostname = bidderRequest.refererInfo?.domain || parseDomain(pageUrl);

// Apply GDPR parameters to request.
if (bidderRequest && bidderRequest.gdprConsent) {
Expand Down Expand Up @@ -283,18 +285,8 @@ function _getDoNotTrack() {
* @returns {string}
*/
function _extractTopWindowUrlFromBidderRequest(bidderRequest) {
if (config.getConfig('pageUrl')) {
return config.getConfig('pageUrl');
}
if (deepAccess(bidderRequest, 'refererInfo.referer')) {
return bidderRequest.refererInfo.referer;
}

try {
return window.top.location.href;
} catch (e) {
return window.location.href;
}
// TODO: does it make sense to fall back to window.location?
return bidderRequest?.refererInfo?.page || window.location.href;
}

/**
Expand All @@ -304,34 +296,8 @@ function _extractTopWindowUrlFromBidderRequest(bidderRequest) {
* @returns {string}
*/
function _extractTopWindowReferrerFromBidderRequest(bidderRequest) {
if (bidderRequest && deepAccess(bidderRequest, 'refererInfo.referer')) {
return bidderRequest.refererInfo.referer;
}

try {
return window.top.document.referrer;
} catch (e) {
return window.document.referrer;
}
}

/**
* Extracts the domain from given page url
*
* @param {string} url
* @returns {string}
*/
export function getDomain(pageUrl) {
if (config.getConfig('publisherDomain')) {
var publisherDomain = config.getConfig('publisherDomain');
return publisherDomain.replace('http://', '').replace('https://', '').replace('www.', '').split(/[/?#:]/)[0];
}

if (!pageUrl) {
return pageUrl;
}

return pageUrl.replace('http://', '').replace('https://', '').replace('www.', '').split(/[/?#:]/)[0];
// TODO: does it make sense to fall back to window.document.referrer?
return bidderRequest?.refererInfo?.ref || window.document.referrer;
}

/**
Expand Down
18 changes: 0 additions & 18 deletions test/spec/modules/apacdexBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,22 +730,4 @@ describe('ApacdexBidAdapter', function () {
expect(validateGeoObject(geoObject)).to.equal(false);
});
});

describe('getDomain', function () {
it('should return valid domain from publisherDomain config', () => {
let pageUrl = 'https://www.example.com/page/prebid/exam.html';
config.setConfig({ publisherDomain: pageUrl });
expect(getDomain(pageUrl)).to.equal('example.com');
});
it('should return valid domain from pageUrl argument', () => {
let pageUrl = 'https://www.example.com/page/prebid/exam.html';
config.setConfig({ publisherDomain: '' });
expect(getDomain(pageUrl)).to.equal('example.com');
});
it('should return undefined if pageUrl and publisherDomain not config', () => {
let pageUrl;
config.setConfig({ publisherDomain: '' });
expect(getDomain(pageUrl)).to.equal(pageUrl);
});
});
});

0 comments on commit 2d57f41

Please sign in to comment.