@highfivve/ad-tag 5.8.27 → 5.8.28

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.
package/lib/ads/moli.js CHANGED
@@ -7,6 +7,7 @@ import { getAbTestValues, getActiveEnvironmentOverride, setEnvironmentOverrideIn
7
7
  import { packageJson } from '../gen/packageJson';
8
8
  import * as adUnitPath from './adUnitPath';
9
9
  import { extractTopPrivateDomainFromHostname } from '../util/extractTopPrivateDomainFromHostname';
10
+ import { detectGeoFromBrowser } from '../util/detectGeoFromTimezone';
10
11
  import { createLabelConfigService } from './labelConfigService';
11
12
  import { allowRefreshAdSlot, allowRequestAds } from './spa';
12
13
  import { QueryParameters } from 'ad-tag/util/queryParameters';
@@ -238,6 +239,7 @@ export const createMoliTag = (window) => {
238
239
  case 'configured': {
239
240
  setABtestTargeting();
240
241
  addDomainLabel(state.config.domain);
242
+ addGeoLabels(state.config.targeting?.geo);
241
243
  const modules = state.modules;
242
244
  getLogger(state.runtimeConfig, window).debug('MoliGlobal', 'configure modules', state.config.modules ?? {});
243
245
  const labelService = createLabelConfigService(state.config?.labelSizeConfig || [], state.runtimeConfig.labels, window);
@@ -379,6 +381,7 @@ export const createMoliTag = (window) => {
379
381
  }
380
382
  setABtestTargeting();
381
383
  addDomainLabel(state.config.domain);
384
+ addGeoLabels(state.config.targeting?.geo);
382
385
  const { modules } = state;
383
386
  const afterRequestAds = state.nextRuntimeConfig.hooks.afterRequestAds;
384
387
  const beforeRequestAds = state.nextRuntimeConfig.hooks.beforeRequestAds;
@@ -601,6 +604,15 @@ export const createMoliTag = (window) => {
601
604
  addLabel(domain);
602
605
  }
603
606
  }
607
+ function addGeoLabels(geoFromConfig) {
608
+ const { country, continent } = geoFromConfig ?? detectGeoFromBrowser();
609
+ if (country) {
610
+ addLabel(country);
611
+ }
612
+ if (continent) {
613
+ addLabel(continent);
614
+ }
615
+ }
604
616
  function setAudience(audience) {
605
617
  switch (state.state) {
606
618
  case 'configurable':
@@ -1,3 +1,3 @@
1
1
  export const packageJson = {
2
- version: '5.8.27'
2
+ version: '5.8.28'
3
3
  };
@@ -0,0 +1,76 @@
1
+ const TIMEZONE_TO_COUNTRY = {
2
+ 'Europe/London': 'GB',
3
+ 'Europe/Berlin': 'DE',
4
+ 'Europe/Paris': 'FR',
5
+ 'Europe/Rome': 'IT',
6
+ 'Europe/Madrid': 'ES',
7
+ 'Atlantic/Canary': 'ES',
8
+ 'Europe/Amsterdam': 'NL',
9
+ 'Europe/Brussels': 'BE',
10
+ 'Europe/Vienna': 'AT',
11
+ 'Europe/Zurich': 'CH',
12
+ 'Europe/Stockholm': 'SE',
13
+ 'Europe/Oslo': 'NO',
14
+ 'Europe/Copenhagen': 'DK',
15
+ 'Europe/Helsinki': 'FI',
16
+ 'Europe/Warsaw': 'PL',
17
+ 'Europe/Lisbon': 'PT',
18
+ 'Atlantic/Madeira': 'PT',
19
+ 'Atlantic/Azores': 'PT',
20
+ 'Europe/Bucharest': 'RO',
21
+ 'America/New_York': 'US',
22
+ 'America/Chicago': 'US',
23
+ 'America/Denver': 'US',
24
+ 'America/Los_Angeles': 'US',
25
+ 'America/Phoenix': 'US',
26
+ 'America/Anchorage': 'US',
27
+ 'America/Adak': 'US',
28
+ 'America/Juneau': 'US',
29
+ 'America/Nome': 'US',
30
+ 'America/Sitka': 'US',
31
+ 'America/Yakutat': 'US',
32
+ 'America/Indiana/Indianapolis': 'US',
33
+ 'America/Indiana/Knox': 'US',
34
+ 'America/Indiana/Marengo': 'US',
35
+ 'America/Indiana/Petersburg': 'US',
36
+ 'America/Indiana/Tell_City': 'US',
37
+ 'America/Indiana/Vevay': 'US',
38
+ 'America/Indiana/Vincennes': 'US',
39
+ 'America/Indiana/Winamac': 'US',
40
+ 'America/Kentucky/Louisville': 'US',
41
+ 'America/Kentucky/Monticello': 'US',
42
+ 'America/North_Dakota/Beulah': 'US',
43
+ 'America/North_Dakota/Center': 'US',
44
+ 'America/North_Dakota/New_Salem': 'US',
45
+ 'America/Detroit': 'US',
46
+ 'America/Menominee': 'US',
47
+ 'Pacific/Honolulu': 'US',
48
+ 'America/Mexico_City': 'MX',
49
+ 'America/Monterrey': 'MX',
50
+ 'America/Mazatlan': 'MX',
51
+ 'America/Chihuahua': 'MX',
52
+ 'America/Cancun': 'MX',
53
+ 'America/Merida': 'MX',
54
+ 'America/Tijuana': 'MX',
55
+ 'America/Hermosillo': 'MX',
56
+ 'America/Matamoros': 'MX',
57
+ 'America/Ojinaga': 'MX',
58
+ 'America/Bahia_Banderas': 'MX'
59
+ };
60
+ const continentFromTimezone = (timezone) => {
61
+ const prefix = timezone.split('/')[0];
62
+ return prefix !== timezone ? prefix.toLowerCase() : undefined;
63
+ };
64
+ export const detectGeoFromTimezone = (timezone) => {
65
+ const country = TIMEZONE_TO_COUNTRY[timezone];
66
+ return { country, continent: continentFromTimezone(timezone) };
67
+ };
68
+ export const detectGeoFromBrowser = () => {
69
+ try {
70
+ const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
71
+ return detectGeoFromTimezone(timezone);
72
+ }
73
+ catch {
74
+ return { country: undefined, continent: undefined };
75
+ }
76
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highfivve/ad-tag",
3
- "version": "5.8.27",
3
+ "version": "5.8.28",
4
4
  "license": "Apache-2.0",
5
5
  "description": "An ad tag implementation called moli",
6
6
  "main": "./lib/index.js",