@highfivve/ad-tag 5.11.5 → 5.11.7

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.
@@ -1,9 +1,9 @@
1
1
  import { AdVisibilityService } from './adVisibilityService';
2
2
  import { UserActivityService } from './userActivityService';
3
3
  import { mkConfigureStep } from '../../adPipeline';
4
- import { isNotNull } from 'ad-tag/util/arrayUtils';
5
4
  import { isAdvertiserIncluded } from 'ad-tag/ads/isAdvertiserIncluded';
6
5
  import { formatKey } from 'ad-tag/ads/keyValues';
6
+ import { resolveAdUnitPath } from 'ad-tag/ads/adUnitPath';
7
7
  import { asViewabilityOverrideEntryList, resolveViewabilityOverride } from './viewabilityOverride';
8
8
  export const createAdReload = () => {
9
9
  const name = 'moli-ad-reload';
@@ -59,14 +59,28 @@ export const createAdReload = () => {
59
59
  };
60
60
  const reloadAdSlot = (config, ctx) => (googleTagSlot) => {
61
61
  const slotId = googleTagSlot.getSlotElementId();
62
- const moliSlot = ctx.config__.slots.find(moliSlot => moliSlot.domId === slotId);
62
+ const slotAdUnitPath = googleTagSlot.getAdUnitPath();
63
+ const moliSlot = ctx.config__.slots.find(candidate => {
64
+ if (candidate.domId === slotId) {
65
+ return true;
66
+ }
67
+ if (!slotAdUnitPath) {
68
+ return false;
69
+ }
70
+ try {
71
+ return (resolveAdUnitPath(candidate.adUnitPath, ctx.adUnitPathVariables__) === slotAdUnitPath);
72
+ }
73
+ catch (e) {
74
+ return false;
75
+ }
76
+ });
63
77
  if (moliSlot && moliSlot.behaviour.loaded !== 'infinite') {
64
78
  ctx.logger__.debug('AdReload', 'fired slot reload', moliSlot.domId);
65
79
  const sizesOverride = maybeOptimizeSlotForCls(config, moliSlot, googleTagSlot, ctx.logger__, ctx.window__);
66
80
  googleTagSlot.setTargeting(reloadKeyValue, 'true');
67
81
  const getBucketAndLoadingBehaviour = () => {
68
82
  const [liveFormat] = googleTagSlot.getTargeting(formatKey);
69
- const matchedOverride = resolveViewabilityOverride(asViewabilityOverrideEntryList(config.viewabilityOverrides?.[slotId]), liveFormat);
83
+ const matchedOverride = resolveViewabilityOverride(asViewabilityOverrideEntryList(config.viewabilityOverrides?.[moliSlot.domId]), liveFormat);
70
84
  if (matchedOverride?.refreshBucket === true) {
71
85
  const loaded = moliSlot.behaviour.loaded;
72
86
  const bucket = moliSlot.behaviour.bucket;
@@ -85,18 +99,21 @@ export const createAdReload = () => {
85
99
  }
86
100
  else {
87
101
  ctx.window__.moli
88
- .refreshAdSlot(slotId, {
102
+ .refreshAdSlot(moliSlot.domId, {
89
103
  loaded: moliSlot.behaviour.loaded,
90
104
  ...(sizesOverride && { sizesOverride: sizesOverride })
91
105
  })
92
- .catch(error => ctx.logger__.error('AdReload', `refreshing ${slotId} failed`, error));
106
+ .catch(error => ctx.logger__.error('AdReload', `refreshing ${moliSlot.domId} failed`, error));
93
107
  }
94
108
  }
95
109
  };
96
110
  const setupSlotRenderListener = (config, slotsToMonitor, reloadAdSlotCallback, window, logger) => window.googletag.pubads().addEventListener('slotRenderEnded', renderEndedEvent => {
97
111
  const { slot: googleTagSlot, campaignId, advertiserId, companyIds, yieldGroupIds, isEmpty: slotIsEmpty } = renderEndedEvent;
98
112
  const slotDomId = googleTagSlot.getSlotElementId();
99
- const slotIsMonitored = slotsToMonitor.indexOf(slotDomId) > -1;
113
+ const slotAdUnitPath = googleTagSlot.getAdUnitPath();
114
+ const monitoredSlot = slotsToMonitor.find(monitored => monitored.domId === slotDomId ||
115
+ (!!slotAdUnitPath && monitored.adUnitPath === slotAdUnitPath));
116
+ const slotIsMonitored = !!monitoredSlot;
100
117
  const orderIdNotExcluded = !campaignId || config.excludeOrderIds.indexOf(campaignId) === -1;
101
118
  const orderIdIncluded = !!campaignId && config.includeOrderIds.indexOf(campaignId) > -1;
102
119
  const advertiserIdIncluded = isAdvertiserIncluded(renderEndedEvent, config.includeAdvertiserIds);
@@ -117,7 +134,7 @@ export const createAdReload = () => {
117
134
  }
118
135
  const slotAlreadyTracked = !!adVisibilityService?.isSlotTracked(slotDomId);
119
136
  if (trackingSlotAllowed) {
120
- const bidderCode = globalAuctionContext?.getLastWinningBidderOfAdUnit(slotDomId);
137
+ const bidderCode = monitoredSlot && globalAuctionContext?.getLastWinningBidderOfAdUnit(monitoredSlot.domId);
121
138
  adVisibilityService.trackSlot(googleTagSlot, reloadAdSlotCallback, advertiserId, companyIds, bidderCode);
122
139
  }
123
140
  else if (slotAlreadyTracked) {
@@ -144,9 +161,19 @@ export const createAdReload = () => {
144
161
  ? [
145
162
  mkConfigureStep(name, context => {
146
163
  const slotsToMonitor = context.config__.slots
147
- .filter(slot => config.excludeAdSlotDomIds.indexOf(slot.domId) === -1)
148
- .map(slot => slot.domId)
149
- .filter(isNotNull);
164
+ .filter(slot => !!slot.domId && config.excludeAdSlotDomIds.indexOf(slot.domId) === -1)
165
+ .map(slot => {
166
+ try {
167
+ return {
168
+ domId: slot.domId,
169
+ adUnitPath: resolveAdUnitPath(slot.adUnitPath, context.adUnitPathVariables__)
170
+ };
171
+ }
172
+ catch (e) {
173
+ context.logger__.error('AdReload', `failed to resolve adUnitPath '${slot.adUnitPath}' for domId ${slot.domId}, monitoring by domId only`, e);
174
+ return { domId: slot.domId, adUnitPath: '' };
175
+ }
176
+ });
150
177
  const reloadAdSlotCallback = reloadAdSlot(config, context);
151
178
  context.logger__.debug('AdReload', 'monitoring slots', slotsToMonitor);
152
179
  initialize(context, config, slotsToMonitor, reloadAdSlotCallback);
@@ -1,3 +1,3 @@
1
1
  export const packageJson = {
2
- version: '5.11.5'
2
+ version: '5.11.7'
3
3
  };
@@ -60,16 +60,16 @@ function getSourceLabelStyle(source) {
60
60
  export function getDefaultLogger() {
61
61
  return {
62
62
  debug(source, message, ...optionalParams) {
63
- console.debug(`%c[DEBUG]%c${source}%c${message}`, getLogStageLabelStyle('debug'), getSourceLabelStyle(source), '', ...optionalParams);
63
+ console.debug(`%c[DEBUG] %c${source} %c${message}`, getLogStageLabelStyle('debug'), getSourceLabelStyle(source), '', ...optionalParams);
64
64
  },
65
65
  info(source, message, ...optionalParams) {
66
- console.info(`%c[INFO]%c${source}%c${message}`, getLogStageLabelStyle('info'), getSourceLabelStyle(source), '', ...optionalParams);
66
+ console.info(`%c[INFO] %c${source} %c${message}`, getLogStageLabelStyle('info'), getSourceLabelStyle(source), '', ...optionalParams);
67
67
  },
68
68
  warn(source, message, ...optionalParams) {
69
- console.warn(`%c[WARN]%c${source}%c${message}`, getLogStageLabelStyle('warn'), getSourceLabelStyle(source), '', ...optionalParams);
69
+ console.warn(`%c[WARN] %c${source} %c${message}`, getLogStageLabelStyle('warn'), getSourceLabelStyle(source), '', ...optionalParams);
70
70
  },
71
71
  error(source, message, ...optionalParams) {
72
- console.error(`%c[ERROR]%c${source}%c${message}`, getLogStageLabelStyle('error'), getSourceLabelStyle(source), '', ...optionalParams);
72
+ console.error(`%c[ERROR] %c${source} %c${message}`, getLogStageLabelStyle('error'), getSourceLabelStyle(source), '', ...optionalParams);
73
73
  }
74
74
  };
75
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highfivve/ad-tag",
3
- "version": "5.11.5",
3
+ "version": "5.11.7",
4
4
  "license": "Apache-2.0",
5
5
  "description": "An ad tag implementation called moli",
6
6
  "main": "./lib/index.js",