Skip to content

Commit

Permalink
AMX bid adapter: fix timeout handler, bump version (#10744)
Browse files Browse the repository at this point in the history
* amx bid adapter: fix timeout handler, bump version

* restore package-lock to master

* remove sendbeacon, use mock xhr

* add keepalive option for ajax

* fix firefox test

* CR changes

* CR changes: restore files

* CR changes
  • Loading branch information
nickjacob authored Dec 20, 2023
1 parent 104f53f commit 2548949
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 83 deletions.
116 changes: 94 additions & 22 deletions modules/amxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,31 @@ import {
} from '../src/utils.js';
import { config } from '../src/config.js';
import { getStorageManager } from '../src/storageManager.js';
import { fetch } from '../src/ajax.js';

const BIDDER_CODE = 'amx';
const storage = getStorageManager({ bidderCode: BIDDER_CODE });
const SIMPLE_TLD_TEST = /\.com?\.\w{2,4}$/;
const DEFAULT_ENDPOINT = 'https://prebid.a-mo.net/a/c';
const VERSION = 'pba1.3.3';
const VERSION = 'pba1.3.4';
const VAST_RXP = /^\s*<\??(?:vast|xml)/i;
const TRACKING_ENDPOINT = 'https://1x1.a-mo.net/hbx/';
const TRACKING_BASE = 'https://1x1.a-mo.net/';
const TRACKING_ENDPOINT = TRACKING_BASE + 'hbx/';
const POST_TRACKING_ENDPOINT = TRACKING_BASE + 'e';
const AMUID_KEY = '__amuidpb';

function getLocation(request) {
return parseUrl(request.refererInfo?.topmostLocation || window.location.href);
}

function getTimeoutSize(timeoutData) {
if (timeoutData.sizes == null || timeoutData.sizes.length === 0) {
return [0, 0];
}

return timeoutData.sizes[0];
}

const largestSize = (sizes, mediaTypes) => {
const allSizes = sizes
.concat(deepAccess(mediaTypes, `${BANNER}.sizes`, []) || [])
Expand Down Expand Up @@ -149,7 +160,9 @@ function convertRequest(bid) {
const tid = deepAccess(bid, 'params.tagId');

const au =
bid.params != null && typeof bid.params.adUnitId === 'string' && bid.params.adUnitId !== ''
bid.params != null &&
typeof bid.params.adUnitId === 'string' &&
bid.params.adUnitId !== ''
? bid.params.adUnitId
: bid.adUnitCode;

Expand Down Expand Up @@ -202,7 +215,10 @@ function isSyncEnabled(syncConfigP, syncType) {
return false;
}

if (syncConfig.bidders === '*' || (isArray(syncConfig.bidders) && syncConfig.bidders.indexOf('amx') !== -1)) {
if (
syncConfig.bidders === '*' ||
(isArray(syncConfig.bidders) && syncConfig.bidders.indexOf('amx') !== -1)
) {
return syncConfig.filter == null || syncConfig.filter === 'include';
}

Expand All @@ -219,12 +235,17 @@ function getSyncSettings() {
d: 0,
l: 0,
t: 0,
e: true
e: true,
};
}

const settings = { d: syncConfig.syncDelay, l: syncConfig.syncsPerBidder, t: 0, e: syncConfig.syncEnabled }
const all = isSyncEnabled(syncConfig.filterSettings, 'all')
const settings = {
d: syncConfig.syncDelay,
l: syncConfig.syncsPerBidder,
t: 0,
e: syncConfig.syncEnabled,
};
const all = isSyncEnabled(syncConfig.filterSettings, 'all');

if (all) {
settings.t = SYNC_IMAGE & SYNC_IFRAME;
Expand Down Expand Up @@ -256,12 +277,14 @@ function getGpp(bidderRequest) {
return bidderRequest.gppConsent;
}

return bidderRequest?.ortb2?.regs?.gpp ?? { gppString: '', applicableSections: '' };
return (
bidderRequest?.ortb2?.regs?.gpp ?? { gppString: '', applicableSections: '' }
);
}

function buildReferrerInfo(bidderRequest) {
if (bidderRequest.refererInfo == null) {
return { r: '', t: false, c: '', l: 0, s: [] }
return { r: '', t: false, c: '', l: 0, s: [] };
}

const re = bidderRequest.refererInfo;
Expand All @@ -272,7 +295,7 @@ function buildReferrerInfo(bidderRequest) {
l: re.numIframes,
s: re.stack,
c: re.canonicalUrl,
}
};
}

const isTrue = (boolValue) =>
Expand Down Expand Up @@ -358,28 +381,35 @@ export const spec = {
return {
data: payload,
method: 'POST',
browsingTopics: true,
url: deepAccess(bidRequests[0], 'params.endpoint', DEFAULT_ENDPOINT),
withCredentials: true,
};
},

getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) {
getUserSyncs(
syncOptions,
serverResponses,
gdprConsent,
uspConsent,
gppConsent
) {
const qp = {
gdpr_consent: enc(gdprConsent?.consentString || ''),
gdpr: enc(gdprConsent?.gdprApplies ? 1 : 0),
us_privacy: enc(uspConsent || ''),
gpp: enc(gppConsent?.gppString || ''),
gpp_sid: enc(gppConsent?.applicableSections || '')
gpp_sid: enc(gppConsent?.applicableSections || ''),
};

const iframeSync = {
url: `https://prebid.a-mo.net/isyn?${formatQS(qp)}`,
type: 'iframe'
type: 'iframe',
};

if (serverResponses == null || serverResponses.length === 0) {
if (syncOptions.iframeEnabled) {
return [iframeSync]
return [iframeSync];
}

return [];
Expand All @@ -394,7 +424,10 @@ export const spec = {
const pixelType =
syncPixel.indexOf('__st=iframe') !== -1 ? 'iframe' : 'image';
if (syncOptions.iframeEnabled || pixelType === 'image') {
hasFrame = hasFrame || (pixelType === 'iframe') || (syncPixel.indexOf('cchain') !== -1)
hasFrame =
hasFrame ||
pixelType === 'iframe' ||
syncPixel.indexOf('cchain') !== -1;
output.push({
url: syncPixel,
type: pixelType,
Expand All @@ -405,7 +438,7 @@ export const spec = {
});

if (!hasFrame && output.length < 2) {
output.push(iframeSync)
output.push(iframeSync);
}

return output;
Expand Down Expand Up @@ -470,19 +503,58 @@ export const spec = {
aud: targetingData.requestId,
a: targetingData.adUnitCode,
c2: nestedQs(targetingData.adserverTargeting),
cn3: targetingData.timeToRespond,
});
},

onTimeout(timeoutData) {
if (timeoutData == null) {
if (timeoutData == null || !timeoutData.length) {
return;
}

trackEvent('pbto', {
A: timeoutData.bidder,
bid: timeoutData.bidId,
a: timeoutData.adUnitCode,
cn: timeoutData.timeout,
let common = null;
const events = timeoutData.map((timeout) => {
const params = timeout.params || {};
const size = getTimeoutSize(timeout);
const { domain, page, ref } =
timeout.ortb2 != null && timeout.ortb2.site != null
? timeout.ortb2.site
: {};

if (common == null) {
common = {
do: domain,
u: page,
U: getUIDSafe(),
re: ref,
V: '$prebid.version$',
vg: '$$PREBID_GLOBAL$$',
};
}

return {
A: timeout.bidder,
mid: params.tagId,
a: params.adunitId || timeout.adUnitCode,
bid: timeout.bidId,
n: 'g_pbto',
aud: timeout.transactionId,
w: size[0],
h: size[1],
cn: timeout.timeout,
cn2: timeout.bidderRequestsCount,
cn3: timeout.bidderWinsCount,
};
});

const payload = JSON.stringify({ c: common, e: events });
fetch(POST_TRACKING_ENDPOINT, {
body: payload,
keepalive: true,
withCredentials: true,
method: 'POST'
}).catch((_e) => {
// do nothing; ignore errors
});
},

Expand Down
Loading

0 comments on commit 2548949

Please sign in to comment.