@highfivve/ad-tag 5.8.33 → 5.9.0

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,8 @@
1
+ export const resolveModuleConfig = (base, isLabelConditionMet) => {
2
+ const { overrides = [], ...defaultConfig } = base;
3
+ const matchedOverrideIndex = overrides.findIndex(isLabelConditionMet);
4
+ const match = overrides[matchedOverrideIndex];
5
+ return match
6
+ ? { config: match.config, matchedOverrideIndex, matchedCondition: match }
7
+ : { config: defaultConfig, matchedOverrideIndex: -1 };
8
+ };
@@ -16,6 +16,32 @@ export const createSkin = () => {
16
16
  let skinModuleConfig = null;
17
17
  let bidsBackHandler = [];
18
18
  const config__ = () => skinModuleConfig;
19
+ const getSkinBids = (config, bidResponses) => {
20
+ const skinBidResponse = bidResponses[config.skinAdSlotDomId];
21
+ const isSkinBid = (bid) => {
22
+ const oneFilterApplied = config.formatFilter.some(filter => {
23
+ switch (filter.bidder) {
24
+ case '*':
25
+ return true;
26
+ case 'gumgum':
27
+ return (bid.bidder === prebidjs.GumGum &&
28
+ (filter.auid === undefined ||
29
+ (typeof bid.ad !== 'string' && bid.ad.auid === filter.auid)));
30
+ default:
31
+ return bid.bidder === filter.bidder;
32
+ }
33
+ });
34
+ return bid.cpm > 0 && oneFilterApplied;
35
+ };
36
+ return skinBidResponse
37
+ ?
38
+ skinBidResponse.bids.filter(isSkinBid).sort((bid1, bid2) => bid2.cpm - bid1.cpm)
39
+ : [];
40
+ };
41
+ const getHighestSkinBidCpm = (config, bidResponses) => {
42
+ const skinBids = getSkinBids(config, bidResponses);
43
+ return skinBids.length > 0 ? skinBids[0].cpm : null;
44
+ };
19
45
  const getConfigEffect = (config, bidResponses, log) => {
20
46
  const skinBidResponse = bidResponses[config.skinAdSlotDomId];
21
47
  const isSkinBid = (bid) => {
@@ -54,12 +80,29 @@ export const createSkin = () => {
54
80
  }
55
81
  return skinBids.length > 0 ? "BlockOtherSlots" : "NoBlocking";
56
82
  };
57
- const selectConfig = (skinModuleConfig, bidResponses, log) => skinModuleConfig.configs
58
- .map(config => ({
59
- skinConfig: config,
60
- configEffect: getConfigEffect(config, bidResponses, log)
61
- }))
62
- .find(({ configEffect }) => configEffect !== "NoBlocking");
83
+ const selectConfig = (skinModuleConfig, bidResponses, log) => {
84
+ const configEvaluations = skinModuleConfig.configs.map(config => ({
85
+ skinConfig: config,
86
+ configEffect: getConfigEffect(config, bidResponses, log),
87
+ highestSkinCpm: getHighestSkinBidCpm(config, bidResponses)
88
+ }));
89
+ const matchingConfigs = configEvaluations.filter(({ configEffect }) => configEffect !== "NoBlocking");
90
+ const compareWithOtherSkinsConfigs = matchingConfigs.filter(({ skinConfig }) => skinConfig.compareWithOtherSkins);
91
+ if (compareWithOtherSkinsConfigs.length > 1) {
92
+ return compareWithOtherSkinsConfigs.reduce((selectedConfig, currentConfig) => {
93
+ if (selectedConfig.highestSkinCpm === null ||
94
+ (currentConfig.highestSkinCpm !== null &&
95
+ currentConfig.highestSkinCpm > selectedConfig.highestSkinCpm)) {
96
+ return currentConfig;
97
+ }
98
+ return selectedConfig;
99
+ });
100
+ }
101
+ const fallbackConfig = matchingConfigs[0];
102
+ return fallbackConfig
103
+ ? { skinConfig: fallbackConfig.skinConfig, configEffect: fallbackConfig.configEffect }
104
+ : undefined;
105
+ };
63
106
  const destroyAdSlot = (slotDefinitions, gWindow) => (adSlotDomId) => {
64
107
  const adSlots = slotDefinitions
65
108
  .map(slot => slot.adSlot)
package/lib/ads/moli.js CHANGED
@@ -9,6 +9,7 @@ import * as adUnitPath from './adUnitPath';
9
9
  import { extractTopPrivateDomainFromHostname } from '../util/extractTopPrivateDomainFromHostname';
10
10
  import { detectGeoFromBrowser } from '../util/detectGeoFromTimezone';
11
11
  import { createLabelConfigService } from './labelConfigService';
12
+ import { resolveModuleConfig } from './moduleConfigOverrides';
12
13
  import { allowRefreshAdSlot, allowRequestAds } from './spa';
13
14
  import { QueryParameters } from 'ad-tag/util/queryParameters';
14
15
  import { BrowserStorageKeys } from 'ad-tag/util/browserStorageKeys';
@@ -244,21 +245,31 @@ export const createMoliTag = (window) => {
244
245
  getLogger(state.runtimeConfig, window).debug('MoliGlobal', 'configure modules', state.config.modules ?? {});
245
246
  const labelService = createLabelConfigService(state.config?.labelSizeConfig || [], state.runtimeConfig.labels, window);
246
247
  modules
247
- .filter(module => {
248
+ .map(module => {
248
249
  const moduleName = module.name;
249
- const moduleConfig = state.config?.modules?.[moduleName];
250
- if (moduleConfig?.labelCondition) {
251
- const areLabelConditionsMet = labelService.isLabelConditionMet(moduleConfig.labelCondition);
252
- if (!areLabelConditionsMet) {
253
- getLogger(state.runtimeConfig, window).debug('MoliGlobal', `skipping configuration of ${module.moduleType} module ${moduleName} due to label condition not met.`);
254
- return false;
255
- }
250
+ const base = state.config?.modules?.[moduleName];
251
+ if (!base) {
252
+ return null;
253
+ }
254
+ const { config: effectiveConfig, matchedOverrideIndex, matchedCondition } = resolveModuleConfig(base, labelService.isLabelConditionMet);
255
+ if (matchedOverrideIndex >= 0) {
256
+ getLogger(state.runtimeConfig, window).debug('MoliGlobal', `module ${moduleName}: applying config override #${matchedOverrideIndex}`, matchedCondition);
256
257
  }
257
- return true;
258
+ if (effectiveConfig.labelCondition &&
259
+ !labelService.isLabelConditionMet(effectiveConfig.labelCondition)) {
260
+ getLogger(state.runtimeConfig, window).debug('MoliGlobal', `skipping configuration of ${module.moduleType} module ${moduleName} due to label condition not met.`);
261
+ return null;
262
+ }
263
+ const resolvedModulesConfig = {
264
+ ...state.config?.modules,
265
+ [moduleName]: effectiveConfig
266
+ };
267
+ return { module, resolvedModulesConfig };
258
268
  })
259
- .forEach(module => {
269
+ .filter((entry) => entry !== null)
270
+ .forEach(({ module, resolvedModulesConfig }) => {
260
271
  try {
261
- module.configure__(state.config?.modules ?? {});
272
+ module.configure__(resolvedModulesConfig);
262
273
  getLogger(state.runtimeConfig, window).debug('MoliGlobal', `configure ${module.moduleType} module ${module.name}`, module.config__());
263
274
  state.runtimeConfig.adPipelineConfig.initSteps.push(...module.initSteps__());
264
275
  state.runtimeConfig.adPipelineConfig.configureSteps.push(...module.configureSteps__());
@@ -1,3 +1,3 @@
1
1
  export const packageJson = {
2
- version: '5.8.33'
2
+ version: '5.9.0'
3
3
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highfivve/ad-tag",
3
- "version": "5.8.33",
3
+ "version": "5.9.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "An ad tag implementation called moli",
6
6
  "main": "./lib/index.js",