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