Skip to content

Commit

Permalink
Prebid Core: Implement transaction id on imp.ext.tid (prebid#8591)
Browse files Browse the repository at this point in the history
* add transactionId to openrtb imp ext object

* fix unit test

* address feedbacks

Co-authored-by: shahin.rahbariasl <[email protected]>
  • Loading branch information
2 people authored and jorgeluisrocha committed Sep 14, 2022
1 parent b1e51ca commit 5ccaa1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
adUnitsFilter, flatten, getHighestCpm, isArrayOfNums, isGptPubadsDefined, uniques, logInfo,
contains, logError, isArray, deepClone, deepAccess, isNumber, logWarn, logMessage, isFn,
transformAdServerTargetingObj, bind, replaceAuctionPrice, replaceClickThrough, insertElement,
inIframe, callBurl, createInvisibleIframe, generateUUID, unsupportedBidderMessage, isEmpty
inIframe, callBurl, createInvisibleIframe, generateUUID, unsupportedBidderMessage, isEmpty, mergeDeep, deepSetValue
} from './utils.js';
import { listenMessagesFromCreative } from './secureCreatives.js';
import { userSync } from './userSync.js';
Expand Down Expand Up @@ -607,6 +607,9 @@ $$PREBID_GLOBAL$$.requestBids = hook('async', function ({ bidsBackHandler, timeo

adUnit.transactionId = generateUUID();

// Populate ortb2Imp.ext.tid with transactionId. Specifying a transaction ID per item in the ortb impression array, lets multiple transaction IDs be transmitted in a single bid request.
deepSetValue(adUnit, 'ortb2Imp.ext.tid', adUnit.transactionId)

bidders.forEach(bidder => {
const adapter = bidderRegistry[bidder];
const spec = adapter && adapter.getSpec && adapter.getSpec();
Expand Down
23 changes: 23 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,29 @@ describe('Unit: Prebid Module', function () {
.and.to.match(/[a-f0-9\-]{36}/i);
});

it('should always set ortb2.ext.tid same as transactionId in adUnits', function () {
$$PREBID_GLOBAL$$.requestBids({
adUnits: [
{
code: 'test1',
mediaTypes: { banner: { sizes: [] } },
bids: []
}, {
code: 'test2',
mediaTypes: { banner: { sizes: [] } },
bids: []
}
]
});

expect(auctionArgs.adUnits[0]).to.have.property('transactionId');
expect(auctionArgs.adUnits[0]).to.have.property('ortb2Imp');
expect(auctionArgs.adUnits[0].transactionId).to.equal(auctionArgs.adUnits[0].ortb2Imp.ext.tid);
expect(auctionArgs.adUnits[1]).to.have.property('transactionId');
expect(auctionArgs.adUnits[1]).to.have.property('ortb2Imp');
expect(auctionArgs.adUnits[1].transactionId).to.equal(auctionArgs.adUnits[1].ortb2Imp.ext.tid);
});

it('should notify targeting of the latest auction for each adUnit', function () {
let latestStub = sinon.stub(targeting, 'setLatestAuctionForAdUnit');
let getAuctionStub = sinon.stub(auction, 'getAuctionId').returns(2);
Expand Down

0 comments on commit 5ccaa1a

Please sign in to comment.