@@ -13,8 +13,6 @@ const COOKIE_NAME = 'rpaSession';
1313const LAST_SEEN_EXPIRE_TIME = 1800000 ; // 30 mins
1414const END_EXPIRE_TIME = 21600000 ; // 6 hours
1515
16- const MODULE_INITIALIZED_TIME = utils . getPerformanceNow ( ) ;
17-
1816const pbsErrorMap = {
1917 1 : 'timeout-error' ,
2018 2 : 'input-error' ,
@@ -154,7 +152,7 @@ function sendMessage(auctionId, bidWonId, trigger) {
154152 'videoAdFormat' , ( ) => bid . videoAdFormat ,
155153 'mediaTypes'
156154 ] ) , {
157- adserverTargeting : stringProperties ( cache . targeting [ bid . adUnit . adUnitCode ] || { } ) ,
155+ adserverTargeting : ! utils . isEmpty ( cache . targeting [ bid . adUnit . adUnitCode ] ) ? stringProperties ( cache . targeting [ bid . adUnit . adUnitCode ] ) : undefined ,
158156 bidwonStatus : 'success' , // hard-coded for now
159157 accountId,
160158 siteId : bid . siteId ,
@@ -165,8 +163,12 @@ function sendMessage(auctionId, bidWonId, trigger) {
165163 let auctionCache = cache . auctions [ auctionId ] ;
166164 let referrer = config . getConfig ( 'pageUrl' ) || ( auctionCache && auctionCache . referrer ) ;
167165 let message = {
166+ timestamps : {
167+ prebidLoaded : rubiconAdapter . MODULE_INITIALIZED_TIME ,
168+ auctionEnded : auctionCache . endTs ,
169+ eventTime : Date . now ( )
170+ } ,
168171 trigger,
169- eventTimeMillis : Date . now ( ) ,
170172 integration : rubiConf . int_type || DEFAULT_INTEGRATION ,
171173 version : '$prebid.version$' ,
172174 referrerUri : referrer ,
@@ -190,8 +192,8 @@ function sendMessage(auctionId, bidWonId, trigger) {
190192 'transactionId' ,
191193 'mediaTypes' ,
192194 'dimensions' ,
193- 'adserverTargeting' , ( ) => stringProperties ( cache . targeting [ bid . adUnit . adUnitCode ] || { } ) ,
194- 'gam' ,
195+ 'adserverTargeting' , ( ) => ! utils . isEmpty ( cache . targeting [ bid . adUnit . adUnitCode ] ) ? stringProperties ( cache . targeting [ bid . adUnit . adUnitCode ] ) : undefined ,
196+ 'gam' , gam => ! utils . isEmpty ( gam ) ? gam : undefined ,
195197 'pbAdSlot' ,
196198 'pattern'
197199 ] ) ;
@@ -305,12 +307,8 @@ function sendMessage(auctionId, bidWonId, trigger) {
305307 message . bidsWon = bidsWon ;
306308 }
307309
308- message . timeAfterLoad = Math . round ( utils . getPerformanceNow ( ) - MODULE_INITIALIZED_TIME ) ;
309- message . timeAfterAuctionEnd = Math . round ( utils . getPerformanceNow ( ) - auctionCache . endTs ) ;
310310 auctionCache . sent = true ;
311311 } else if ( bidWonId && auctionCache && auctionCache . bids [ bidWonId ] ) {
312- message . timeAfterLoad = Math . round ( utils . getPerformanceNow ( ) - MODULE_INITIALIZED_TIME ) ;
313- message . timeAfterAuctionEnd = Math . round ( utils . getPerformanceNow ( ) - auctionCache . endTs ) ;
314312 message . bidsWon = [
315313 formatBidWon ( auctionCache . bids [ bidWonId ] )
316314 ] ;
@@ -326,6 +324,10 @@ function sendMessage(auctionId, bidWonId, trigger) {
326324 ) ;
327325}
328326
327+ function adUnitIsOnlyInstream ( adUnit ) {
328+ return adUnit . mediaTypes && Object . keys ( adUnit . mediaTypes ) . length === 1 && utils . deepAccess ( adUnit , 'mediaTypes.video.context' ) === 'instream' ;
329+ }
330+
329331function getBidPrice ( bid ) {
330332 // get the cpm from bidResponse
331333 let cpm ;
@@ -516,6 +518,7 @@ function subscribeToGamSlots() {
516518
517519let baseAdapter = adapter ( { analyticsType : 'endpoint' } ) ;
518520let rubiconAdapter = Object . assign ( { } , baseAdapter , {
521+ MODULE_INITIALIZED_TIME : Date . now ( ) ,
519522 referrerHostname : '' ,
520523 enableAnalytics ( config = { } ) {
521524 let error = false ;
@@ -601,7 +604,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
601604 // mark adUnits we expect bidWon events for
602605 cache . auctions [ args . auctionId ] . bidsWon [ bid . adUnitCode ] = false ;
603606
604- if ( rubiConf . waitForGamSlots && ( ! bid . mediaTypes . hasOwnProperty ( 'video' ) || Object . keys ( bid . mediaTypes ) . length !== 1 ) ) {
607+ if ( rubiConf . waitForGamSlots && ! adUnitIsOnlyInstream ( bid ) ) {
605608 cache . auctions [ args . auctionId ] . gamHasRendered [ bid . adUnitCode ] = false ;
606609 }
607610
@@ -771,11 +774,18 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
771774 break ;
772775 case AUCTION_END :
773776 // see how long it takes for the payload to come fire
774- cache . auctions [ args . auctionId ] . endTs = utils . getPerformanceNow ( ) ;
775- // start timer to send batched payload just in case we don't hear any BID_WON events
776- cache . timeouts [ args . auctionId ] = setTimeout ( ( ) => {
777- sendMessage . call ( this , args . auctionId , undefined , 'auctionEnd' ) ;
778- } , rubiConf . analyticsBatchTimeout || SEND_TIMEOUT ) ;
777+ cache . auctions [ args . auctionId ] . endTs = Date . now ( ) ;
778+
779+ const isOnlyInstreamAuction = args . adUnits && args . adUnits . every ( adUnit => adUnitIsOnlyInstream ( adUnit ) ) ;
780+ // If only instream, do not wait around, just send payload
781+ if ( isOnlyInstreamAuction ) {
782+ sendMessage . call ( this , args . auctionId , undefined , 'instreamAuction' ) ;
783+ } else {
784+ // start timer to send batched payload just in case we don't hear any BID_WON events
785+ cache . timeouts [ args . auctionId ] = setTimeout ( ( ) => {
786+ sendMessage . call ( this , args . auctionId , undefined , 'auctionEnd' ) ;
787+ } , rubiConf . analyticsBatchTimeout || SEND_TIMEOUT ) ;
788+ }
779789 break ;
780790 case BID_TIMEOUT :
781791 args . forEach ( badBid => {
0 commit comments