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

AdagioAnalyticsAdapter: add adg-pba aTag to beacon (#14103) #12264

Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 31 additions & 1 deletion modules/adagioAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { _ADAGIO, getBestWindowForAdagio } from '../libraries/adagioUtils/adagioUtils.js';
import { deepAccess, logError, logInfo, logWarn } from '../src/utils.js';
import { deepAccess, logError, logInfo, logWarn, isPlainObject } from '../src/utils.js';
import { BANNER } from '../src/mediaTypes.js';
import { EVENTS } from '../src/constants.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
Expand Down Expand Up @@ -378,6 +378,33 @@ function handlerAdRender(event, isSuccess) {
sendNewBeacon(auctionId, adUnitCode);
};

/**
* handlerPbsAnalytics add to the cache data coming from Adagio PBS AdResponse.
* The data is retrieved from an AnalyticsTag (set by a custom PBS module named `adg-pba`),
* located in the AdResponse at `response.ext.prebid.analytics.tags[].pba`.
*/
function handlerPbsAnalytics(event) {
const pbaByAdUnit = event.atag.find(e => {
return e.module === 'adg-pba'
})?.pba;

if (!pbaByAdUnit) {
return;
}

const adUnitCodes = cache.getAllAdUnitCodes(event.auctionId);

adUnitCodes.forEach(adUnitCode => {
const pba = pbaByAdUnit[adUnitCode]

if (isPlainObject(pba)) {
cache.updateAuction(event.auctionId, adUnitCode, {
...addKeyPrefix(pba, 'e_')
});
}
})
}

/**
* END HANDLERS
*/
Expand Down Expand Up @@ -405,6 +432,9 @@ let adagioAdapter = Object.assign(adapter({ emptyUrl, analyticsType }), {
case EVENTS.AD_RENDER_FAILED:
handlerAdRender(args, eventType === EVENTS.AD_RENDER_SUCCEEDED);
break;
case EVENTS.PBS_ANALYTICS:
handlerPbsAnalytics(args);
break;
}
} catch (error) {
logError('Error on Adagio Analytics Adapter', error);
Expand Down
70 changes: 70 additions & 0 deletions test/spec/modules/adagioAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,22 @@ const AUCTION_END_ANOTHER_NOBID = Object.assign({}, AUCTION_INIT_ANOTHER, {
bidsReceived: []
});

const PBS_ANALYTICS_ANOTHER = {
atag: [
{
stage: 'auction-response',
module: 'adg-pba',
pba: {
'/19968336/header-bid-tag-1': {
st_id: '53',
splt_cs_id: '731'
}
}
}
],
auctionId: AUCTION_ID,
}

const MOCK = {
SET_TARGETING: {
[BID_ADAGIO.adUnitCode]: BID_ADAGIO.adserverTargeting,
Expand Down Expand Up @@ -972,5 +988,59 @@ describe('adagio analytics adapter', () => {
expect(search.bdrs_cpm).to.equal('1.42,,,');
}
});

it('set adg-pbs aTags in beacon', () => {
events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.another);
events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.another);
events.emit(EVENTS.PBS_ANALYTICS, PBS_ANALYTICS_ANOTHER);
events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END.another);

expect(server.requests.length).to.equal(4, 'requests count');

// server.requests[0] -> AUCTION_INIT - AdUnit header-bid-tag-1
{
const { search } = utils.parseUrl(server.requests[0].url);

expect(search.adu_code).to.equal('/19968336/header-bid-tag-1');
expect(search.v).to.equal('1');

expect(search.e_st_id).to.be.undefined;
expect(search.e_splt_cs_id).to.be.undefined;
}

// server.requests[1] -> AUCTION_INIT - AdUnit footer-bid-tag-1
{
const { search } = utils.parseUrl(server.requests[1].url);

expect(search.adu_code).to.equal('/19968336/footer-bid-tag-1');
expect(search.v).to.equal('1');

expect(search.e_st_id).to.be.undefined;
expect(search.e_splt_cs_id).to.be.undefined;
}

// server.requests[2] -> AUCTION_END - AdUnit header-bid-tag-1
{
const { search } = utils.parseUrl(server.requests[2].url);

expect(search.adu_code).to.equal('/19968336/header-bid-tag-1');
expect(search.v).to.equal('2');

// The adg-pbs aTags fields are set in the beacon !
expect(search.e_st_id).to.equal('53');
expect(search.e_splt_cs_id).to.equal('731');
}

// server.requests[3] -> AUCTION_END - AdUnit footer-bid-tag-1
{
const { search } = utils.parseUrl(server.requests[3].url);

expect(search.adu_code).to.equal('/19968336/footer-bid-tag-1');
expect(search.v).to.equal('2');

expect(search.e_st_id).to.be.undefined;
expect(search.e_splt_cs_id).to.be.undefined;
}
});
});
});