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 bid adapter: fix timeout handler, bump version #10744

Merged
merged 8 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
115 changes: 94 additions & 21 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 { ajax } 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 @@ -363,23 +386,29 @@ export const spec = {
};
},

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 +423,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 +437,7 @@ export const spec = {
});

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

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

Expand All @@ -478,11 +511,51 @@ export const spec = {
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,
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 });
const url = POST_TRACKING_ENDPOINT + '/g_pbto';

if (navigator.sendBeacon != null) {
navigator.sendBeacon(url, payload);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to use core methods for network communication. If sendBeacom is useful, feel free to write a core method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the sendBeacon usage and instead added the keepalive option to ajax() -- https://fetch.spec.whatwg.org/#request-keepalive-flag which should be the same as navigator.sendBeacon and requires less additional code for Prebid

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's excellent, ty!!

return;
}

ajax(url, null, payload, {
method: 'POST',
withCredentials: true,
});
},

Expand Down
Loading