Skip to content

Commit

Permalink
Adagio Bid Adapter|Analytics Adapter: use rtd uid as auctionid (preb…
Browse files Browse the repository at this point in the history
…id#11958)

* AdagioAnalyticsAdapter: use adagio rtd.uid as auctionId

* AdagioBidAdapter: use adagio rtd.uid as auctionId

* AdagioAnalyticsAdapter: use common code

---------

Co-authored-by: Olivier <[email protected]>
  • Loading branch information
Abyfall and osazos authored Jul 12, 2024
1 parent d285f79 commit af742ce
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 145 deletions.
69 changes: 24 additions & 45 deletions modules/adagioAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
* Analytics Adapter for Adagio
*/

import { _ADAGIO, getBestWindowForAdagio } from '../libraries/adagioUtils/adagioUtils.js';
import { deepAccess, logError, logInfo } from '../src/utils.js';
import { BANNER } from '../src/mediaTypes.js';
import { EVENTS } from '../src/constants.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import { EVENTS } from '../src/constants.js';
import { ajax } from '../src/ajax.js';
import { BANNER } from '../src/mediaTypes.js';
import { getWindowTop, getWindowSelf, deepAccess, logInfo, logError } from '../src/utils.js';
import { getGlobal } from '../src/prebidGlobal.js';

const emptyUrl = '';
Expand All @@ -19,6 +20,13 @@ const PREBID_VERSION = '$prebid.version$';
const ENDPOINT = 'https://c.4dex.io/pba.gif';
const CURRENCY_USD = 'USD';
const ADAGIO_CODE = 'adagio';

export const _internal = {
getAdagioNs: function() {
return _ADAGIO;
}
};

const cache = {
auctions: {},
getAuction: function(auctionId, adUnitCode) {
Expand Down Expand Up @@ -48,34 +56,6 @@ const cache = {
};
const enc = window.encodeURIComponent;

/**
/* BEGIN ADAGIO.JS CODE
*/

function canAccessTopWindow() {
try {
if (getWindowTop().location.href) {
return true;
}
} catch (error) {
return false;
}
};

function getCurrentWindow() {
return currentWindow;
};

let currentWindow;

const adagioEnqueue = function adagioEnqueue(action, data) {
getCurrentWindow().ADAGIO.queue.push({ action, data, ts: Date.now() });
};

/**
* END ADAGIO.JS CODE
*/

/**
* UTILS FUNCTIONS
*/
Expand Down Expand Up @@ -194,7 +174,7 @@ function getTargetedAuctionId(bid) {
*/

function handlerAuctionInit(event) {
const w = getCurrentWindow();
const w = getBestWindowForAdagio();

const prebidAuctionId = event.auctionId;
const adUnitCodes = removeDuplicates(event.adUnitCodes, adUnitCode => adUnitCode);
Expand All @@ -206,6 +186,8 @@ function handlerAuctionInit(event) {
logInfo(`Adagio is not on the bid requests for auction '${prebidAuctionId}'`)
return;
}
const rtdUid = deepAccess(adagioBidRequest, 'ortb2.site.ext.data.adg_rtd.uid');
cache.addPrebidAuctionIdRef(prebidAuctionId, rtdUid);

cache.auctions[prebidAuctionId] = {};

Expand Down Expand Up @@ -250,22 +232,22 @@ function handlerAuctionInit(event) {
// We assume that all Adagio bids for a same adunit have the same params.
const params = adagioAdUnitBids[0].params;

const adagioAuctionId = params.adagioAuctionId;
cache.addPrebidAuctionIdRef(prebidAuctionId, adagioAuctionId);

// Get all media types requested for Adagio.
const adagioMediaTypes = removeDuplicates(
adagioAdUnitBids.map(bid => Object.keys(bid.mediaTypes)).flat(),
mediaTypeKey => mediaTypeKey
).flat().map(mediaType => getMediaTypeAlias(mediaType)).sort();

// if adagio was involved in the auction we identified it with rtdUid, if not use the prebid auctionId
let auctionId = rtdUid || prebidAuctionId;

const qp = {
v: 0,
pbjsv: PREBID_VERSION,
org_id: params.organizationId,
site: params.site,
pv_id: params.pageviewId,
auct_id: adagioAuctionId,
auct_id: auctionId,
adu_code: adUnitCode,
url_dmn: w.location.hostname,
pgtyp: params.pagetype,
Expand Down Expand Up @@ -344,7 +326,6 @@ function handlerBidWon(event) {
(event.latestTargetedAuctionId && event.latestTargetedAuctionId !== event.auctionId)
? cache.getAdagioAuctionId(event.auctionId)
: null);

cache.updateAuction(auctionId, event.adUnitCode, {
win_bdr: event.bidder,
win_mt: getMediaTypeAlias(event.mediaType),
Expand Down Expand Up @@ -407,7 +388,11 @@ let adagioAdapter = Object.assign(adapter({ emptyUrl, analyticsType }), {

try {
if (typeof args !== 'undefined' && events.indexOf(eventType) !== -1) {
adagioEnqueue('pb-analytics-event', { eventName: eventType, args });
_internal.getAdagioNs().queue.push({
action: 'pb-analytics-event',
data: { eventName: eventType, args },
ts: Date.now()
});
}
} catch (error) {
logError('Error on Adagio Analytics Adapter - adagio.js', error);
Expand All @@ -418,13 +403,7 @@ let adagioAdapter = Object.assign(adapter({ emptyUrl, analyticsType }), {
adagioAdapter.originEnableAnalytics = adagioAdapter.enableAnalytics;

adagioAdapter.enableAnalytics = config => {
const w = (canAccessTopWindow()) ? getWindowTop() : getWindowSelf();
currentWindow = w;

w.ADAGIO = w.ADAGIO || {};
w.ADAGIO.queue = w.ADAGIO.queue || [];
w.ADAGIO.versions = w.ADAGIO.versions || {};
w.ADAGIO.versions.adagioAnalyticsAdapter = VERSION;
_internal.getAdagioNs().versions.adagioAnalyticsAdapter = VERSION;

adagioAdapter.originEnableAnalytics(config);
}
Expand Down
1 change: 0 additions & 1 deletion modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@ export const spec = {
// Those params are not sent to the server.
// They are used for further operations on analytics adapter.
validBidRequests.forEach(rawBidRequest => {
rawBidRequest.params.adagioAuctionId = aucId
rawBidRequest.params.pageviewId = pageviewId
});

Expand Down
Loading

0 comments on commit af742ce

Please sign in to comment.