@reservamos/browser-analytics 1.1.1 → 1.1.2-alpha.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.
@@ -13395,7 +13395,7 @@ function loadNoop(_src, onload) {
13395
13395
  onload();
13396
13396
  }
13397
13397
  var mixpanel = init_as_module(loadNoop);
13398
- const version = "1.1.1";
13398
+ const version = "1.1.2-alpha.0";
13399
13399
  const MIXPANEL_DISTINCT_ID_CACHE_KEY = "mp_distinct_id";
13400
13400
  const EVENT_SOURCE_SUPER_PROPERTY = {
13401
13401
  "Event Source": "sdk"
@@ -13840,7 +13840,7 @@ async function init$1(config) {
13840
13840
  } catch (error) {
13841
13841
  console.error("Error initializing identification service:", error);
13842
13842
  }
13843
- geolocationService.init();
13843
+ await geolocationService.init();
13844
13844
  configService.setEnvironment(isSandbox ? "sandbox" : "prod");
13845
13845
  f.setConfig(configService.getCoreAPIConfig());
13846
13846
  onLoaded();
@@ -13852,7 +13852,7 @@ let currentCoordinates = null;
13852
13852
  const GEOLOCATION_PERMISSION_KEY = "geolocationPermissionTimestamp";
13853
13853
  const GEOLOCATION_CACHE_KEY = "geolocationCache";
13854
13854
  const GEOLOCATION_TRACK_EVENT = "Geolocation Requested";
13855
- const SEVEN_DAYS_IN_MS = 7 * 24 * 60 * 60 * 1e3;
13855
+ const ONE_HOUR_IN_MS = 60 * 60 * 1e3;
13856
13856
  const GEOLOCATION_REQUEST_TIMEOUT_MS = 1e4;
13857
13857
  const GEOLOCATION_OPTIONS = {
13858
13858
  enableHighAccuracy: true,
@@ -13872,6 +13872,12 @@ function safeSetItem(key, value) {
13872
13872
  } catch {
13873
13873
  }
13874
13874
  }
13875
+ function safeRemoveItem(key) {
13876
+ try {
13877
+ localStorage.removeItem(key);
13878
+ } catch {
13879
+ }
13880
+ }
13875
13881
  function toISO(timestamp) {
13876
13882
  return new Date(timestamp).toISOString();
13877
13883
  }
@@ -13914,11 +13920,19 @@ function restoreCoordinatesFromStorage() {
13914
13920
  function isPermissionTimestampValid(lastPermissionTimestamp) {
13915
13921
  if (!lastPermissionTimestamp) return false;
13916
13922
  const now = Date.now();
13917
- return now - parseInt(lastPermissionTimestamp, 10) < SEVEN_DAYS_IN_MS;
13923
+ return now - parseInt(lastPermissionTimestamp, 10) < ONE_HOUR_IN_MS;
13918
13924
  }
13919
13925
  function updatePermissionTimestamp(timestamp) {
13920
13926
  safeSetItem(GEOLOCATION_PERMISSION_KEY, timestamp.toString());
13921
13927
  }
13928
+ function repairLegacyGeolocationStorage() {
13929
+ if (!safeGetItem(GEOLOCATION_PERMISSION_KEY)) {
13930
+ return;
13931
+ }
13932
+ if (!loadCoordinatesFromStorage()) {
13933
+ safeRemoveItem(GEOLOCATION_PERMISSION_KEY);
13934
+ }
13935
+ }
13922
13936
  function getGeolocationStatus(error) {
13923
13937
  return error.code === error.PERMISSION_DENIED ? "denied" : "error";
13924
13938
  }
@@ -13933,10 +13947,9 @@ function buildGeolocationEventProperties(data) {
13933
13947
  if (data.errorCode !== void 0) {
13934
13948
  properties["Geolocation Error Code"] = data.errorCode;
13935
13949
  }
13936
- const coordinates = getCoordinates();
13937
- if (coordinates) {
13938
- properties.$latitude = coordinates.lat;
13939
- properties.$longitude = coordinates.long;
13950
+ if ((data.status === "granted" || data.status === "skipped_cache") && data.lat !== void 0 && data.long !== void 0) {
13951
+ properties.latitude = data.lat;
13952
+ properties.longitude = data.long;
13940
13953
  }
13941
13954
  return properties;
13942
13955
  }
@@ -13945,10 +13958,9 @@ function buildGeolocationProfileProperties(data) {
13945
13958
  "Geolocation Updated At": data.updatedAt,
13946
13959
  "Geolocation Status": data.status
13947
13960
  };
13948
- const coordinates = getCoordinates();
13949
- if (coordinates) {
13950
- properties.$latitude = coordinates.lat;
13951
- properties.$longitude = coordinates.long;
13961
+ if ((data.status === "granted" || data.status === "skipped_cache") && data.lat !== void 0 && data.long !== void 0) {
13962
+ properties.latitude = data.lat;
13963
+ properties.longitude = data.long;
13952
13964
  }
13953
13965
  return properties;
13954
13966
  }
@@ -13962,20 +13974,24 @@ function syncGeolocationToMixpanel(data) {
13962
13974
  mixpanelService.setPeopleProperties(profileProperties);
13963
13975
  }
13964
13976
  function init() {
13977
+ repairLegacyGeolocationStorage();
13965
13978
  restoreCoordinatesFromStorage();
13966
13979
  return new Promise((resolve) => {
13967
13980
  var _a;
13968
13981
  const lastPermissionTimestamp = safeGetItem(GEOLOCATION_PERMISSION_KEY);
13969
13982
  if (isPermissionTimestampValid(lastPermissionTimestamp)) {
13970
13983
  const cache = loadCoordinatesFromStorage();
13971
- const updatedAt2 = (cache == null ? void 0 : cache.updatedAt) ?? (lastPermissionTimestamp ? toISO(parseInt(lastPermissionTimestamp, 10)) : (/* @__PURE__ */ new Date()).toISOString());
13972
- syncGeolocationToMixpanel({
13973
- status: "skipped_cache",
13974
- updatedAt: updatedAt2,
13975
- accuracy: cache == null ? void 0 : cache.accuracy
13976
- });
13977
- resolve(currentCoordinates);
13978
- return;
13984
+ if (cache) {
13985
+ syncGeolocationToMixpanel({
13986
+ status: "skipped_cache",
13987
+ updatedAt: cache.updatedAt,
13988
+ lat: cache.lat,
13989
+ long: cache.long,
13990
+ accuracy: cache.accuracy
13991
+ });
13992
+ resolve(currentCoordinates);
13993
+ return;
13994
+ }
13979
13995
  }
13980
13996
  const now = Date.now();
13981
13997
  const updatedAt = toISO(now);
@@ -13993,13 +14009,14 @@ function init() {
13993
14009
  syncGeolocationToMixpanel({
13994
14010
  status: "granted",
13995
14011
  updatedAt,
14012
+ lat,
14013
+ long,
13996
14014
  accuracy
13997
14015
  });
13998
14016
  resolve(currentCoordinates);
13999
14017
  },
14000
14018
  (error) => {
14001
14019
  const status = getGeolocationStatus(error);
14002
- updatePermissionTimestamp(now);
14003
14020
  syncGeolocationToMixpanel({
14004
14021
  status,
14005
14022
  updatedAt,
@@ -14088,8 +14105,8 @@ async function trackEvent(eventName, eventProperties, meta = {}) {
14088
14105
  const defaultCoordinates = {};
14089
14106
  const coordinates = geolocationService.getCoordinates();
14090
14107
  if (coordinates) {
14091
- defaultCoordinates.$latitude = coordinates.lat;
14092
- defaultCoordinates.$longitude = coordinates.long;
14108
+ defaultCoordinates.latitude = coordinates.lat;
14109
+ defaultCoordinates.longitude = coordinates.long;
14093
14110
  }
14094
14111
  const defaultProperties = {
14095
14112
  "User Fingerprint": fingerprint