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

Adagio feature/enforce enable tids #49

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 6 additions & 5 deletions modules/adagioAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,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 +252,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 +346,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
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
86 changes: 71 additions & 15 deletions test/spec/modules/adagioAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ describe('adagio analytics adapter - adagio.js', () => {

// Step 1-3: Send events
Object.entries(testEvents).forEach(([ev, payload]) => events.emit(ev, payload));

function eventItem(eventName, args) {
return sinon.match({
action: 'pb-analytics-event',
Expand Down Expand Up @@ -178,9 +177,9 @@ describe('adagio analytics adapter - adagio.js', () => {
});

const AUCTION_ID = '25c6d7f5-699a-4bfc-87c9-996f915341fa';
const AUCTION_ID_ADAGIO = '6fc53663-bde5-427b-ab63-baa9ed296f47'
const RTD_AUCTION_ID = '753b3784-12a1-44c2-9d08-d0e4ee910e69';
const RTD_AUCTION_ID_CACHE = '04d991be-8f7d-4491-930b-2b7eefb3c447';
const AUCTION_ID_CACHE = 'b43d24a0-13d4-406d-8176-3181402bafc4';
const AUCTION_ID_CACHE_ADAGIO = 'a9cae98f-efb5-477e-9259-27350044f8db';

const BID_ADAGIO = {
bidder: 'adagio',
Expand Down Expand Up @@ -264,6 +263,14 @@ const PARAMS_ADG = {
testVersion: 'version',
};

const ORTB_DATA = {
pagetype: 'article',
};

const ADG_RTD = {
'uid': RTD_AUCTION_ID,
};

const AUCTION_INIT_ANOTHER = {
'auctionId': AUCTION_ID,
'timestamp': 1519767010567,
Expand Down Expand Up @@ -387,6 +394,18 @@ const AUCTION_INIT_ANOTHER = {
'timeout': 3000,
'refererInfo': {
'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html']
},
'ortb2': {
'site': {
'ext': {
'data': {
'adg_rtd': {
...ADG_RTD
},
...ORTB_DATA
}
}
}
}
}, {
'bidderCode': 'adagio',
Expand All @@ -395,8 +414,7 @@ const AUCTION_INIT_ANOTHER = {
'bids': [ {
'bidder': 'adagio',
'params': {
...PARAMS_ADG,
adagioAuctionId: AUCTION_ID_ADAGIO
...PARAMS_ADG
},
'mediaTypes': {
'banner': {
Expand All @@ -416,6 +434,18 @@ const AUCTION_INIT_ANOTHER = {
'timeout': 3000,
'refererInfo': {
'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html']
},
'ortb2': {
'site': {
'ext': {
'data': {
'adg_rtd': {
...ADG_RTD
},
...ORTB_DATA
}
}
}
}
}
],
Expand Down Expand Up @@ -524,6 +554,19 @@ const AUCTION_INIT_CACHE = {
'timeout': 3000,
'refererInfo': {
'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html']
},
'ortb2': {
'site': {
'ext': {
'data': {
'adg_rtd': {
...ADG_RTD,
'uid': RTD_AUCTION_ID_CACHE
},
...ORTB_DATA
}
}
}
}
}, {
'bidderCode': 'adagio',
Expand All @@ -532,8 +575,7 @@ const AUCTION_INIT_CACHE = {
'bids': [ {
'bidder': 'adagio',
'params': {
...PARAMS_ADG,
adagioAuctionId: AUCTION_ID_CACHE_ADAGIO
...PARAMS_ADG
},
'mediaTypes': {
'banner': {
Expand All @@ -553,6 +595,19 @@ const AUCTION_INIT_CACHE = {
'timeout': 3000,
'refererInfo': {
'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html']
},
'ortb2': {
'site': {
'ext': {
'data': {
'adg_rtd': {
...ADG_RTD,
'uid': RTD_AUCTION_ID_CACHE
},
...ORTB_DATA
}
}
}
}
}
],
Expand Down Expand Up @@ -676,7 +731,7 @@ describe('adagio analytics adapter', () => {
expect(pathname).to.equal('/pba.gif');
expect(search.v).to.equal('1');
expect(search.pbjsv).to.equal('$prebid.version$');
expect(search.auct_id).to.equal(AUCTION_ID_ADAGIO);
expect(search.auct_id).to.equal(RTD_AUCTION_ID);
expect(search.adu_code).to.equal('/19968336/header-bid-tag-1');
expect(search.org_id).to.equal('1001');
expect(search.site).to.equal('test-com');
Expand Down Expand Up @@ -708,7 +763,7 @@ describe('adagio analytics adapter', () => {
expect(hostname).to.equal('c.4dex.io');
expect(pathname).to.equal('/pba.gif');
expect(search.v).to.equal('3');
expect(search.auct_id).to.equal(AUCTION_ID_ADAGIO);
expect(search.auct_id).to.equal(RTD_AUCTION_ID);
expect(search.adu_code).to.equal('/19968336/header-bid-tag-1');
expect(search.win_bdr).to.equal('another');
expect(search.win_mt).to.equal('ban');
Expand Down Expand Up @@ -743,13 +798,14 @@ describe('adagio analytics adapter', () => {

expect(server.requests.length).to.equal(5, 'requests count');
{
// the first request is getting cached we expect to see its auction id later when it's re-used
const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[0].url);
expect(protocol).to.equal('https');
expect(hostname).to.equal('c.4dex.io');
expect(pathname).to.equal('/pba.gif');
expect(search.v).to.equal('1');
expect(search.pbjsv).to.equal('$prebid.version$');
expect(search.auct_id).to.equal(AUCTION_ID_CACHE_ADAGIO);
expect(search.auct_id).to.equal(RTD_AUCTION_ID_CACHE);
expect(search.adu_code).to.equal('/19968336/header-bid-tag-1');
expect(search.org_id).to.equal('1001');
expect(search.site).to.equal('test-com');
Expand All @@ -772,7 +828,7 @@ describe('adagio analytics adapter', () => {
expect(pathname).to.equal('/pba.gif');
expect(search.v).to.equal('1');
expect(search.pbjsv).to.equal('$prebid.version$');
expect(search.auct_id).to.equal(AUCTION_ID_ADAGIO);
expect(search.auct_id).to.equal(RTD_AUCTION_ID);
expect(search.adu_code).to.equal('/19968336/header-bid-tag-1');
expect(search.org_id).to.equal('1001');
expect(search.site).to.equal('test-com');
Expand Down Expand Up @@ -804,8 +860,8 @@ describe('adagio analytics adapter', () => {
expect(hostname).to.equal('c.4dex.io');
expect(pathname).to.equal('/pba.gif');
expect(search.v).to.equal('3');
expect(search.auct_id).to.equal(AUCTION_ID_ADAGIO);
expect(search.auct_id_c).to.equal(AUCTION_ID_CACHE_ADAGIO);
expect(search.auct_id).to.equal(RTD_AUCTION_ID);
expect(search.auct_id_c).to.equal(RTD_AUCTION_ID_CACHE);
expect(search.adu_code).to.equal('/19968336/header-bid-tag-1');
expect(search.win_bdr).to.equal('adagio');
expect(search.win_mt).to.equal('ban');
Expand All @@ -821,8 +877,8 @@ describe('adagio analytics adapter', () => {
expect(hostname).to.equal('c.4dex.io');
expect(pathname).to.equal('/pba.gif');
expect(search.v).to.equal('4');
expect(search.auct_id).to.equal(AUCTION_ID_ADAGIO);
expect(search.auct_id_c).to.equal(AUCTION_ID_CACHE_ADAGIO);
expect(search.auct_id).to.equal(RTD_AUCTION_ID);
expect(search.auct_id_c).to.equal(RTD_AUCTION_ID_CACHE);
expect(search.adu_code).to.equal('/19968336/header-bid-tag-1');
expect(search.rndr).to.equal('0');
}
Expand Down
31 changes: 25 additions & 6 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ describe('Adagio bid adapter', () => {
it('should send bid request to ENDPOINT_PB via POST', function() {
sandbox.stub(_internal, 'getDevice').returns({ a: 'a' });
sandbox.stub(_internal, 'getSite').returns({ domain: 'adagio.io', 'page': 'https://adagio.io/hb' });
// sandbox.stub(_internal, 'getPageviewId').returns('1234-567');
// sandbox.stub(utils, 'generateUUID').returns('blabla');

const bid01 = new BidRequestBuilder().withParams().build();
const bidderRequest = new BidderRequestBuilder().build();
Expand All @@ -292,7 +290,31 @@ describe('Adagio bid adapter', () => {
expect(requests[0].data).to.have.all.keys(expectedDataKeys);
});

it('should use a custom generated auctionId and remove transactionId', function() {
it('should use a custom generated auctionId from ortb2.site.ext.data.adg_rtd.uid when available', function() {
const expectedAuctionId = '373bcda7-9794-4f1c-be2c-0d223d11d579'

const bid01 = new BidRequestBuilder().withParams().build();
let ortb = {
ortb2: {
site: {
ext: {
data: {
adg_rtd: {
uid: expectedAuctionId
}
}
}
}
}
}
const bidderRequest = new BidderRequestBuilder(ortb).build();

const requests = spec.buildRequests([bid01], bidderRequest);
expect(requests[0].data.adUnits[0].auctionId).eq(expectedAuctionId);
expect(requests[0].data.adUnits[0].transactionId).to.not.exist;
});

it('should use a custom generated auctionId when ortb2.site.ext.data.adg_rtd.uid is absent and remove transactionId', function() {
const expectedAuctionId = '373bcda7-9794-4f1c-be2c-0d223d11d579'
sandbox.stub(utils, 'generateUUID').returns(expectedAuctionId);

Expand All @@ -305,17 +327,14 @@ describe('Adagio bid adapter', () => {
});

it('should enrich prebid bid requests params', function() {
const expectedAuctionId = '373bcda7-9794-4f1c-be2c-0d223d11d579'
const expectedPageviewId = '56befc26-8cf0-472d-b105-73896df8eb89';
sandbox.stub(utils, 'generateUUID').returns(expectedAuctionId);
sandbox.stub(_internal, 'getAdagioNs').returns({ pageviewId: expectedPageviewId });

const bid01 = new BidRequestBuilder().withParams().build();
const bidderRequest = new BidderRequestBuilder().build();

spec.buildRequests([bid01], bidderRequest);

expect(bid01.params.adagioAuctionId).eq(expectedAuctionId);
expect(bid01.params.pageviewId).eq(expectedPageviewId);
});

Expand Down
Loading