@highfivve/ad-tag 5.8.21 → 5.8.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ export const createTrackWinningBidder = () => {
2
+ const lastWinningBidderByAdUnit = new Map();
3
+ const onBidWon = (winningBid) => {
4
+ lastWinningBidderByAdUnit.set(winningBid.adUnitCode, winningBid.bidderCode);
5
+ };
6
+ const getLastWinningBidderOnAdUnit = (slotId) => {
7
+ return lastWinningBidderByAdUnit.get(slotId);
8
+ };
9
+ return {
10
+ onBidWon,
11
+ getLastWinningBidderOnAdUnit
12
+ };
13
+ };
@@ -4,7 +4,11 @@ import { createFrequencyCapping } from './auctions/frequencyCapping';
4
4
  import { createPreviousBidCpms } from './auctions/previousBidCpms';
5
5
  import { mkConfigureStep } from './adPipeline';
6
6
  import { createInterstitialContext } from 'ad-tag/ads/auctions/interstitialContext';
7
+ import { createTrackWinningBidder } from 'ad-tag/ads/auctions/trackWinningBidder';
7
8
  export const createGlobalAuctionContext = (window, logger, eventService, config = {}) => {
9
+ const trackWinningBidder = config.trackWinningBidder?.enabled
10
+ ? createTrackWinningBidder()
11
+ : undefined;
8
12
  const biddersDisabling = config.biddersDisabling?.enabled
9
13
  ? createBiddersDisabling(config.biddersDisabling, window)
10
14
  : undefined;
@@ -44,14 +48,19 @@ export const createGlobalAuctionContext = (window, logger, eventService, config
44
48
  });
45
49
  });
46
50
  }
47
- if (config.frequencyCap?.enabled) {
51
+ if (config.frequencyCap?.enabled || config.trackWinningBidder?.enabled) {
48
52
  window.pbjs.que.push(() => {
49
53
  window.pbjs.onEvent('bidWon', bid => {
50
54
  if (config.frequencyCap) {
51
55
  frequencyCapping?.onBidWon(bid);
52
56
  }
57
+ if (config.trackWinningBidder) {
58
+ trackWinningBidder?.onBidWon(bid);
59
+ }
53
60
  });
54
61
  });
62
+ }
63
+ if (config.frequencyCap?.enabled) {
55
64
  eventService.addEventListener('beforeRequestAds', () => {
56
65
  frequencyCapping?.beforeRequestAds();
57
66
  });
@@ -86,6 +95,9 @@ export const createGlobalAuctionContext = (window, logger, eventService, config
86
95
  getLastBidCpmsOfAdUnit(slotId) {
87
96
  return previousBidCpms?.getLastBidCpms(slotId) ?? [];
88
97
  },
98
+ getLastWinningBidderOfAdUnit(slotId) {
99
+ return trackWinningBidder?.getLastWinningBidderOnAdUnit(slotId);
100
+ },
89
101
  isBidderDisabled(domId, bidder) {
90
102
  return biddersDisabling?.isBidderDisabled(domId, bidder) ?? false;
91
103
  },
@@ -61,7 +61,7 @@ export class AdVisibilityService {
61
61
  this.setUpdateTimer(true);
62
62
  this.logger?.debug('AdVisibilityService', 'initialized');
63
63
  }
64
- trackSlot(slot, refreshCallback, advertiserId, companyIds) {
64
+ trackSlot(slot, refreshCallback, advertiserId, companyIds, lastWinningBidderCode) {
65
65
  const slotDomId = slot.getSlotElementId();
66
66
  const domElement = this.observedDomElementForSlot(slot);
67
67
  if (domElement) {
@@ -81,7 +81,8 @@ export class AdVisibilityService {
81
81
  ? this.window.performance.now()
82
82
  : undefined,
83
83
  durationVisibleSum: 0,
84
- refreshCallback: refreshCallback
84
+ refreshCallback: refreshCallback,
85
+ lastWinningBidderCode
85
86
  });
86
87
  if (this.intersectionObserver &&
87
88
  (domElement.targetOverride || this.useIntersectionObserver)) {
@@ -110,7 +111,7 @@ export class AdVisibilityService {
110
111
  });
111
112
  Array.from(this.visibilityRecords.values())
112
113
  .filter(record => {
113
- const interval = this.refreshIntervalOverrides[record.slot.getSlotElementId()] || this.refreshInterval;
114
+ const interval = this.resolveRefreshInterval(record);
114
115
  return record.durationVisibleSum > interval;
115
116
  })
116
117
  .forEach(record => {
@@ -120,6 +121,16 @@ export class AdVisibilityService {
120
121
  record.refreshCallback(record.slot);
121
122
  });
122
123
  }
124
+ resolveRefreshInterval(record) {
125
+ const override = this.refreshIntervalOverrides[record.slot.getSlotElementId()];
126
+ if (typeof override === 'number') {
127
+ return override;
128
+ }
129
+ const bidderOverride = record.lastWinningBidderCode && override?.bidders
130
+ ? override.bidders[record.lastWinningBidderCode]
131
+ : undefined;
132
+ return bidderOverride ?? override?.default ?? this.refreshInterval;
133
+ }
123
134
  handleObservedAdVisibilityChanged(entries) {
124
135
  entries.forEach(entry => {
125
136
  const visibilityRecord = this.visibilityRecordForEntry(entry);
@@ -10,6 +10,7 @@ export const createAdReload = () => {
10
10
  let initialized = false;
11
11
  let moduleConfig = null;
12
12
  let adVisibilityService;
13
+ let globalAuctionContext;
13
14
  const config__ = () => moduleConfig;
14
15
  const isInitialized = () => initialized;
15
16
  const configure__ = (mConfig) => {
@@ -113,7 +114,8 @@ export const createAdReload = () => {
113
114
  }
114
115
  const slotAlreadyTracked = !!adVisibilityService?.isSlotTracked(slotDomId);
115
116
  if (trackingSlotAllowed) {
116
- adVisibilityService.trackSlot(googleTagSlot, reloadAdSlotCallback, advertiserId, companyIds);
117
+ const bidderCode = globalAuctionContext?.getLastWinningBidderOfAdUnit(slotDomId);
118
+ adVisibilityService.trackSlot(googleTagSlot, reloadAdSlotCallback, advertiserId, companyIds, bidderCode);
117
119
  }
118
120
  else if (slotAlreadyTracked) {
119
121
  adVisibilityService.removeSlotTracking(googleTagSlot);
@@ -128,6 +130,7 @@ export const createAdReload = () => {
128
130
  return;
129
131
  }
130
132
  context.logger__.debug('AdReload', 'initialize moli ad reload module');
133
+ globalAuctionContext = context.auction__;
131
134
  setupAdVisibilityService(config, context.window__, context.logger__);
132
135
  setupSlotRenderListener(config, slotsToMonitor, reloadAdSlotCallback, context.window__, context.logger__);
133
136
  initialized = true;
@@ -49,7 +49,7 @@ export const MoliAnalytics = () => {
49
49
  };
50
50
  const configValid = (config, logger) => {
51
51
  if (!config) {
52
- logger.error('moli-analytics: not configured');
52
+ logger.debug('moli-analytics: not configured');
53
53
  return false;
54
54
  }
55
55
  if (!config.publisher) {
@@ -72,7 +72,8 @@ export const MoliAnalytics = () => {
72
72
  };
73
73
  const initMoliAnalytics = async (adPipelineContext) => {
74
74
  if (!configValid(config, adPipelineContext.logger__)) {
75
- return Promise.reject('failed to initialize moli analytics: invalid configuration');
75
+ adPipelineContext.logger__.error('failed to initialize moli analytics: invalid or no configuration');
76
+ return Promise.resolve();
76
77
  }
77
78
  eventContext = {
78
79
  publisher: config.publisher,
@@ -1,3 +1,3 @@
1
1
  export const packageJson = {
2
- version: '5.8.21'
2
+ version: '5.8.23'
3
3
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highfivve/ad-tag",
3
- "version": "5.8.21",
3
+ "version": "5.8.23",
4
4
  "license": "Apache-2.0",
5
5
  "description": "An ad tag implementation called moli",
6
6
  "main": "./lib/index.js",