@highfivve/ad-tag 5.8.9 → 5.8.11

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.
@@ -10,6 +10,8 @@ export const createFrequencyCapping = (config, _window, now, logger) => {
10
10
  const bidderImpSchedules = new Map();
11
11
  const positionAdRequests = new Map();
12
12
  let numAdRequests = 0;
13
+ const pageImpressionStorageKey = 'h5v_pi';
14
+ let currentPageImpression = Number(_window.localStorage.getItem(pageImpressionStorageKey) ?? '0');
13
15
  const pacingIntervalConfigs = config.bidders?.filter(hasPacingInterval) ?? [];
14
16
  const bidWonConfigs = pacingIntervalConfigs.filter(config => !config.conditions.pacingInterval?.events ||
15
17
  config.conditions.pacingInterval?.events?.includes('bidWon')) ?? [];
@@ -25,6 +27,7 @@ export const createFrequencyCapping = (config, _window, now, logger) => {
25
27
  };
26
28
  _window.sessionStorage.setItem(sessionStorageKey, JSON.stringify(data));
27
29
  }
30
+ _window.localStorage.setItem(pageImpressionStorageKey, JSON.stringify(currentPageImpression));
28
31
  };
29
32
  const cap = (startTimestamp, config, intervalInMs, bid) => {
30
33
  const bidders = config.bidders;
@@ -143,6 +146,7 @@ export const createFrequencyCapping = (config, _window, now, logger) => {
143
146
  },
144
147
  afterRequestAds() {
145
148
  numAdRequests++;
149
+ currentPageImpression++;
146
150
  persist();
147
151
  },
148
152
  updateAdUnitPaths(adUnitPathVariables) {
@@ -185,8 +189,8 @@ export const createFrequencyCapping = (config, _window, now, logger) => {
185
189
  (delay && numAdRequests < delay.minRequestAds));
186
190
  });
187
191
  },
188
- getRequestAdsCount() {
189
- return numAdRequests;
192
+ getCurrentPageImpressionFromLocalStorage() {
193
+ return currentPageImpression;
190
194
  }
191
195
  };
192
196
  };
@@ -92,12 +92,12 @@ export const createGlobalAuctionContext = (window, logger, eventService, config
92
92
  interstitialChannel: () => {
93
93
  return interstitial?.interstitialChannel();
94
94
  },
95
- hasMinimumRequestAds(minRequestAds) {
95
+ hasMinimumPageImpressions(minRequestAds) {
96
96
  if (!frequencyCapping) {
97
97
  return true;
98
98
  }
99
- const currentRequestAdsCount = frequencyCapping.getRequestAdsCount();
100
- return currentRequestAdsCount >= minRequestAds;
99
+ const currentPageImpression = frequencyCapping.getCurrentPageImpressionFromLocalStorage();
100
+ return currentPageImpression >= minRequestAds;
101
101
  },
102
102
  configureStep() {
103
103
  return configureStep;
@@ -1,5 +1,5 @@
1
1
  import { tcfapi } from 'ad-tag/types/tcfapi';
2
- import { mkInitStep } from 'ad-tag/ads/adPipeline';
2
+ import { mkInitStep, mkConfigureStepOncePerRequestAdsCycle } from 'ad-tag/ads/adPipeline';
3
3
  import { AssetLoadMethod } from 'ad-tag/util/assetLoaderService';
4
4
  const requiredPurposeIds = [
5
5
  tcfapi.responses.TCPurpose.STORE_INFORMATION_ON_DEVICE,
@@ -16,15 +16,14 @@ const requiredPurposeIds = [
16
16
  ];
17
17
  export const createUtiq = () => {
18
18
  let utiqConfig = null;
19
- let loaded = false;
19
+ let scriptLoaded = false;
20
20
  const loadUtiq = (config, context) => {
21
21
  if (context.env__ === 'test') {
22
22
  return Promise.resolve();
23
23
  }
24
- if (loaded) {
24
+ if (scriptLoaded) {
25
25
  return Promise.resolve();
26
26
  }
27
- loaded = true;
28
27
  const utiqWindow = context.window__;
29
28
  utiqWindow.Utiq = utiqWindow.Utiq
30
29
  ? { ...utiqWindow.Utiq, config: { ...utiqWindow.Utiq.config, ...config.options } }
@@ -35,7 +34,7 @@ export const createUtiq = () => {
35
34
  return Promise.resolve();
36
35
  }
37
36
  const minAdRequests = config.delay?.enabled && config.delay.minAdRequests ? config.delay.minAdRequests : 0;
38
- if (!context.auction__.hasMinimumRequestAds(minAdRequests)) {
37
+ if (!context.auction__.hasMinimumPageImpressions(minAdRequests)) {
39
38
  context.logger__.info('Utiq', `not enough ad requests to load Utiq. ${minAdRequests} required.`);
40
39
  return Promise.resolve();
41
40
  }
@@ -45,7 +44,12 @@ export const createUtiq = () => {
45
44
  loadMethod: AssetLoadMethod.TAG,
46
45
  assetUrl: config.assetUrl
47
46
  })
48
- .catch(error => context.logger__.error('failed to load utiq', error));
47
+ .then(() => {
48
+ scriptLoaded = true;
49
+ })
50
+ .catch(error => {
51
+ context.logger__.error('failed to load utiq', error);
52
+ });
49
53
  };
50
54
  const hasDelayEnabled = (config) => {
51
55
  return config?.delay?.enabled ?? false;
@@ -69,7 +73,7 @@ export const createUtiq = () => {
69
73
  },
70
74
  configureSteps__() {
71
75
  return utiqConfig?.enabled && hasDelayEnabled(utiqConfig)
72
- ? [mkInitStep('utiq', ctx => loadUtiq(utiqConfig, ctx))]
76
+ ? [mkConfigureStepOncePerRequestAdsCycle('utiq', ctx => loadUtiq(utiqConfig, ctx))]
73
77
  : [];
74
78
  },
75
79
  prepareRequestAdsSteps__() {
@@ -1,3 +1,3 @@
1
1
  export const packageJson = {
2
- version: '5.8.9'
2
+ version: '5.8.11'
3
3
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highfivve/ad-tag",
3
- "version": "5.8.9",
3
+ "version": "5.8.11",
4
4
  "license": "Apache-2.0",
5
5
  "description": "An ad tag implementation called moli",
6
6
  "main": "./lib/index.js",