@@ -458,47 +458,35 @@ function updateRpaCookie() {
458
458
return decodedRpaCookie ;
459
459
}
460
460
461
- const gamEventFunctions = {
462
- 'slotOnload' : ( auctionId , bid ) => {
463
- cache . auctions [ auctionId ] . gamHasRendered [ bid . adUnit . adUnitCode ] = true ;
464
- } ,
465
- 'slotRenderEnded' : ( auctionId , bid , event ) => {
466
- if ( event . isEmpty ) {
467
- cache . auctions [ auctionId ] . gamHasRendered [ bid . adUnit . adUnitCode ] = true ;
468
- }
469
- bid . adUnit . gam = utils . pick ( event , [
470
- // these come in as `null` from Gpt, which when stringified does not get removed
471
- // so set explicitly to undefined when not a number
472
- 'advertiserId' , advertiserId => utils . isNumber ( advertiserId ) ? advertiserId : undefined ,
473
- 'creativeId' , creativeId => utils . isNumber ( creativeId ) ? creativeId : undefined ,
474
- 'lineItemId' , lineItemId => utils . isNumber ( lineItemId ) ? lineItemId : undefined ,
475
- 'adSlot' , ( ) => event . slot . getAdUnitPath ( ) ,
476
- 'isSlotEmpty' , ( ) => event . isEmpty || undefined
477
- ] ) ;
478
- }
479
- }
480
-
481
461
function subscribeToGamSlots ( ) {
482
- [ 'slotOnload' , 'slotRenderEnded' ] . forEach ( eventName => {
483
- window . googletag . pubads ( ) . addEventListener ( eventName , event => {
484
- const isMatchingAdSlot = utils . isAdUnitCodeMatchingSlot ( event . slot ) ;
485
- // loop through auctions and adUnits and mark the info
486
- Object . keys ( cache . auctions ) . forEach ( auctionId => {
487
- ( Object . keys ( cache . auctions [ auctionId ] . bids ) || [ ] ) . forEach ( bidId => {
488
- let bid = cache . auctions [ auctionId ] . bids [ bidId ] ;
489
- // if this slot matches this bids adUnit, add the adUnit info
490
- if ( isMatchingAdSlot ( bid . adUnit . adUnitCode ) ) {
491
- // mark this adUnit as having been rendered by gam
492
- gamEventFunctions [ eventName ] ( auctionId , bid , event ) ;
493
- }
494
- } ) ;
495
- // Now if all adUnits have gam rendered, send the payload
496
- if ( rubiConf . waitForGamSlots && ! cache . auctions [ auctionId ] . sent && Object . keys ( cache . auctions [ auctionId ] . gamHasRendered ) . every ( adUnitCode => cache . auctions [ auctionId ] . gamHasRendered [ adUnitCode ] ) ) {
497
- clearTimeout ( cache . timeouts [ auctionId ] ) ;
498
- delete cache . timeouts [ auctionId ] ;
499
- sendMessage . call ( rubiconAdapter , auctionId ) ;
462
+ window . googletag . pubads ( ) . addEventListener ( 'slotRenderEnded' , event => {
463
+ const isMatchingAdSlot = utils . isAdUnitCodeMatchingSlot ( event . slot ) ;
464
+ // loop through auctions and adUnits and mark the info
465
+ Object . keys ( cache . auctions ) . forEach ( auctionId => {
466
+ ( Object . keys ( cache . auctions [ auctionId ] . bids ) || [ ] ) . forEach ( bidId => {
467
+ let bid = cache . auctions [ auctionId ] . bids [ bidId ] ;
468
+ // if this slot matches this bids adUnit, add the adUnit info
469
+ if ( isMatchingAdSlot ( bid . adUnit . adUnitCode ) ) {
470
+ // mark this adUnit as having been rendered by gam
471
+ cache . auctions [ auctionId ] . gamHasRendered [ bid . adUnit . adUnitCode ] = true ;
472
+
473
+ bid . adUnit . gam = utils . pick ( event , [
474
+ // these come in as `null` from Gpt, which when stringified does not get removed
475
+ // so set explicitly to undefined when not a number
476
+ 'advertiserId' , advertiserId => utils . isNumber ( advertiserId ) ? advertiserId : undefined ,
477
+ 'creativeId' , creativeId => utils . isNumber ( creativeId ) ? creativeId : undefined ,
478
+ 'lineItemId' , lineItemId => utils . isNumber ( lineItemId ) ? lineItemId : undefined ,
479
+ 'adSlot' , ( ) => event . slot . getAdUnitPath ( ) ,
480
+ 'isSlotEmpty' , ( ) => event . isEmpty || undefined
481
+ ] ) ;
500
482
}
501
483
} ) ;
484
+ // Now if all adUnits have gam rendered, send the payload
485
+ if ( rubiConf . waitForGamSlots && ! cache . auctions [ auctionId ] . sent && Object . keys ( cache . auctions [ auctionId ] . gamHasRendered ) . every ( adUnitCode => cache . auctions [ auctionId ] . gamHasRendered [ adUnitCode ] ) ) {
486
+ clearTimeout ( cache . timeouts [ auctionId ] ) ;
487
+ delete cache . timeouts [ auctionId ] ;
488
+ sendMessage . call ( rubiconAdapter , auctionId ) ;
489
+ }
502
490
} ) ;
503
491
} ) ;
504
492
}
@@ -576,6 +564,13 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
576
564
if ( ! cache . gpt . registered && utils . isGptPubadsDefined ( ) ) {
577
565
subscribeToGamSlots ( ) ;
578
566
cache . gpt . registered = true ;
567
+ } else if ( ! cache . gpt . registered ) {
568
+ cache . gpt . registered = true ;
569
+ let googletag = window . googletag || { } ;
570
+ googletag . cmd = googletag . cmd || [ ] ;
571
+ googletag . cmd . push ( function ( ) {
572
+ subscribeToGamSlots ( ) ;
573
+ } ) ;
579
574
}
580
575
break ;
581
576
case BID_REQUESTED :
0 commit comments