sitepong 0.2.0 → 0.2.1

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.
@@ -1,3 +1,3 @@
1
1
  export { addBreadcrumb, captureServerException, captureServerMessage, clearBreadcrumbs, getBreadcrumbs, getServerConfig, initServer } from '../server/index.mjs';
2
- export { C as CaptureContext, E as ErrorEvent, L as LogLevel, S as SitePongConfig } from '../types-Cms9VXx9.mjs';
3
- import '../types-BEqbz0tw.mjs';
2
+ export { C as CaptureContext, E as ErrorEvent, L as LogLevel, S as SitePongConfig } from '../types-CphqOTfm.mjs';
3
+ import '../types-DPINdOQW.mjs';
@@ -1,3 +1,3 @@
1
1
  export { addBreadcrumb, captureServerException, captureServerMessage, clearBreadcrumbs, getBreadcrumbs, getServerConfig, initServer } from '../server/index.js';
2
- export { C as CaptureContext, E as ErrorEvent, L as LogLevel, S as SitePongConfig } from '../types-DQSv7JAE.js';
3
- import '../types-BEqbz0tw.js';
2
+ export { C as CaptureContext, E as ErrorEvent, L as LogLevel, S as SitePongConfig } from '../types-BTA43eyz.js';
3
+ import '../types-DPINdOQW.js';
@@ -610,6 +610,60 @@ function clearSession() {
610
610
  memorySessionTs = null;
611
611
  }
612
612
 
613
+ // src/analytics/utm.ts
614
+ var STORAGE_KEY2 = "sp_utm";
615
+ var UTM_KEYS = [
616
+ ["source", "utm_source"],
617
+ ["medium", "utm_medium"],
618
+ ["campaign", "utm_campaign"],
619
+ ["term", "utm_term"],
620
+ ["content", "utm_content"]
621
+ ];
622
+ function parseFromLocation() {
623
+ if (typeof window === "undefined" || !window.location || !window.location.search) return null;
624
+ let params;
625
+ try {
626
+ params = new URLSearchParams(window.location.search);
627
+ } catch {
628
+ return null;
629
+ }
630
+ const result = {};
631
+ let found = false;
632
+ for (const [key, queryKey] of UTM_KEYS) {
633
+ const value = params.get(queryKey);
634
+ if (value) {
635
+ result[key] = value;
636
+ found = true;
637
+ }
638
+ }
639
+ return found ? result : null;
640
+ }
641
+ function readStored() {
642
+ if (typeof sessionStorage === "undefined") return null;
643
+ try {
644
+ const raw = sessionStorage.getItem(STORAGE_KEY2);
645
+ if (!raw) return null;
646
+ const parsed = JSON.parse(raw);
647
+ return parsed && typeof parsed === "object" ? parsed : null;
648
+ } catch {
649
+ return null;
650
+ }
651
+ }
652
+ function writeStored(utm) {
653
+ if (typeof sessionStorage === "undefined") return;
654
+ try {
655
+ sessionStorage.setItem(STORAGE_KEY2, JSON.stringify(utm));
656
+ } catch {
657
+ }
658
+ }
659
+ function getSessionUtm() {
660
+ const stored = readStored();
661
+ if (stored) return stored;
662
+ const fresh = parseFromLocation();
663
+ if (fresh) writeStored(fresh);
664
+ return fresh;
665
+ }
666
+
613
667
  // src/analytics/autocapture.ts
614
668
  var DEFAULT_BLOCK_SELECTORS = [
615
669
  "[data-sp-no-capture]",
@@ -1016,7 +1070,9 @@ var AnalyticsManager = class {
1016
1070
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1017
1071
  url: typeof window !== "undefined" && window.location ? window.location.href : void 0,
1018
1072
  referrer: typeof document !== "undefined" && typeof document.referrer === "string" ? document.referrer : void 0,
1019
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
1073
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
1074
+ utm: getSessionUtm() || void 0,
1075
+ appVersion: this.config.appVersion || void 0
1020
1076
  };
1021
1077
  }
1022
1078
  enqueue(event) {
@@ -1714,7 +1770,7 @@ var DEFAULT_REMOTE_CONFIG = {
1714
1770
  };
1715
1771
 
1716
1772
  // src/remote-config/manager.ts
1717
- var STORAGE_KEY2 = "sitepong_remote_config";
1773
+ var STORAGE_KEY3 = "sitepong_remote_config";
1718
1774
  var STORAGE_TS_KEY = "sitepong_remote_config_ts";
1719
1775
  var RemoteConfigManager = class {
1720
1776
  constructor(options) {
@@ -1757,7 +1813,7 @@ var RemoteConfigManager = class {
1757
1813
  const storage = this.options.storage;
1758
1814
  if (!storage) return;
1759
1815
  try {
1760
- const cached = await storage.getItem(STORAGE_KEY2);
1816
+ const cached = await storage.getItem(STORAGE_KEY3);
1761
1817
  const cachedTs = await storage.getItem(STORAGE_TS_KEY);
1762
1818
  if (cached && cachedTs) {
1763
1819
  const age = Date.now() - parseInt(cachedTs, 10);
@@ -1818,7 +1874,7 @@ var RemoteConfigManager = class {
1818
1874
  const storage = this.options.storage;
1819
1875
  if (!storage) return;
1820
1876
  try {
1821
- await storage.setItem(STORAGE_KEY2, JSON.stringify(this.config));
1877
+ await storage.setItem(STORAGE_KEY3, JSON.stringify(this.config));
1822
1878
  await storage.setItem(STORAGE_TS_KEY, String(Date.now()));
1823
1879
  } catch {
1824
1880
  this.log("Failed to cache remote config");
@@ -1930,7 +1986,7 @@ function stripTrailingSlash(url) {
1930
1986
  var superlinkClient = new SuperLinkClient();
1931
1987
 
1932
1988
  // src/superlink/parse.ts
1933
- var UTM_KEYS = [
1989
+ var UTM_KEYS2 = [
1934
1990
  ["source", "utm_source"],
1935
1991
  ["medium", "utm_medium"],
1936
1992
  ["campaign", "utm_campaign"],
@@ -1946,7 +2002,7 @@ function parseUniversalLink(url) {
1946
2002
  }
1947
2003
  const params = parsed.searchParams;
1948
2004
  const utm = {};
1949
- for (const [key, queryKey] of UTM_KEYS) {
2005
+ for (const [key, queryKey] of UTM_KEYS2) {
1950
2006
  const value = params.get(queryKey);
1951
2007
  if (value) utm[key] = value;
1952
2008
  }