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.
@@ -622,6 +622,60 @@ function clearSession() {
622
622
  memorySessionTs = null;
623
623
  }
624
624
 
625
+ // src/analytics/utm.ts
626
+ var STORAGE_KEY2 = "sp_utm";
627
+ var UTM_KEYS = [
628
+ ["source", "utm_source"],
629
+ ["medium", "utm_medium"],
630
+ ["campaign", "utm_campaign"],
631
+ ["term", "utm_term"],
632
+ ["content", "utm_content"]
633
+ ];
634
+ function parseFromLocation() {
635
+ if (typeof window === "undefined" || !window.location || !window.location.search) return null;
636
+ let params;
637
+ try {
638
+ params = new URLSearchParams(window.location.search);
639
+ } catch {
640
+ return null;
641
+ }
642
+ const result = {};
643
+ let found = false;
644
+ for (const [key, queryKey] of UTM_KEYS) {
645
+ const value = params.get(queryKey);
646
+ if (value) {
647
+ result[key] = value;
648
+ found = true;
649
+ }
650
+ }
651
+ return found ? result : null;
652
+ }
653
+ function readStored() {
654
+ if (typeof sessionStorage === "undefined") return null;
655
+ try {
656
+ const raw = sessionStorage.getItem(STORAGE_KEY2);
657
+ if (!raw) return null;
658
+ const parsed = JSON.parse(raw);
659
+ return parsed && typeof parsed === "object" ? parsed : null;
660
+ } catch {
661
+ return null;
662
+ }
663
+ }
664
+ function writeStored(utm) {
665
+ if (typeof sessionStorage === "undefined") return;
666
+ try {
667
+ sessionStorage.setItem(STORAGE_KEY2, JSON.stringify(utm));
668
+ } catch {
669
+ }
670
+ }
671
+ function getSessionUtm() {
672
+ const stored = readStored();
673
+ if (stored) return stored;
674
+ const fresh = parseFromLocation();
675
+ if (fresh) writeStored(fresh);
676
+ return fresh;
677
+ }
678
+
625
679
  // src/analytics/autocapture.ts
626
680
  var DEFAULT_BLOCK_SELECTORS = [
627
681
  "[data-sp-no-capture]",
@@ -1028,7 +1082,9 @@ var AnalyticsManager = class {
1028
1082
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1029
1083
  url: typeof window !== "undefined" && window.location ? window.location.href : void 0,
1030
1084
  referrer: typeof document !== "undefined" && typeof document.referrer === "string" ? document.referrer : void 0,
1031
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
1085
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
1086
+ utm: getSessionUtm() || void 0,
1087
+ appVersion: this.config.appVersion || void 0
1032
1088
  };
1033
1089
  }
1034
1090
  enqueue(event) {
@@ -1726,7 +1782,7 @@ var DEFAULT_REMOTE_CONFIG = {
1726
1782
  };
1727
1783
 
1728
1784
  // src/remote-config/manager.ts
1729
- var STORAGE_KEY2 = "sitepong_remote_config";
1785
+ var STORAGE_KEY3 = "sitepong_remote_config";
1730
1786
  var STORAGE_TS_KEY = "sitepong_remote_config_ts";
1731
1787
  var RemoteConfigManager = class {
1732
1788
  constructor(options) {
@@ -1769,7 +1825,7 @@ var RemoteConfigManager = class {
1769
1825
  const storage = this.options.storage;
1770
1826
  if (!storage) return;
1771
1827
  try {
1772
- const cached = await storage.getItem(STORAGE_KEY2);
1828
+ const cached = await storage.getItem(STORAGE_KEY3);
1773
1829
  const cachedTs = await storage.getItem(STORAGE_TS_KEY);
1774
1830
  if (cached && cachedTs) {
1775
1831
  const age = Date.now() - parseInt(cachedTs, 10);
@@ -1830,7 +1886,7 @@ var RemoteConfigManager = class {
1830
1886
  const storage = this.options.storage;
1831
1887
  if (!storage) return;
1832
1888
  try {
1833
- await storage.setItem(STORAGE_KEY2, JSON.stringify(this.config));
1889
+ await storage.setItem(STORAGE_KEY3, JSON.stringify(this.config));
1834
1890
  await storage.setItem(STORAGE_TS_KEY, String(Date.now()));
1835
1891
  } catch {
1836
1892
  this.log("Failed to cache remote config");
@@ -2585,7 +2641,7 @@ function stripTrailingSlash(url) {
2585
2641
  var superlinkClient = new SuperLinkClient();
2586
2642
 
2587
2643
  // src/superlink/parse.ts
2588
- var UTM_KEYS = [
2644
+ var UTM_KEYS2 = [
2589
2645
  ["source", "utm_source"],
2590
2646
  ["medium", "utm_medium"],
2591
2647
  ["campaign", "utm_campaign"],
@@ -2601,7 +2657,7 @@ function parseUniversalLink(url) {
2601
2657
  }
2602
2658
  const params = parsed.searchParams;
2603
2659
  const utm = {};
2604
- for (const [key, queryKey] of UTM_KEYS) {
2660
+ for (const [key, queryKey] of UTM_KEYS2) {
2605
2661
  const value = params.get(queryKey);
2606
2662
  if (value) utm[key] = value;
2607
2663
  }
@@ -2668,13 +2724,13 @@ function getMatchedDeepLink() {
2668
2724
  }
2669
2725
 
2670
2726
  // src/superlink/web.ts
2671
- var STORAGE_KEY3 = "sp_superlink";
2727
+ var STORAGE_KEY4 = "sp_superlink";
2672
2728
  var captured = null;
2673
2729
  var didCapture = false;
2674
- function readStored() {
2730
+ function readStored2() {
2675
2731
  if (typeof sessionStorage === "undefined") return null;
2676
2732
  try {
2677
- const raw = sessionStorage.getItem(STORAGE_KEY3);
2733
+ const raw = sessionStorage.getItem(STORAGE_KEY4);
2678
2734
  if (!raw) return null;
2679
2735
  const parsed = JSON.parse(raw);
2680
2736
  return parsed && typeof parsed === "object" ? parsed : null;
@@ -2682,10 +2738,10 @@ function readStored() {
2682
2738
  return null;
2683
2739
  }
2684
2740
  }
2685
- function writeStored(link) {
2741
+ function writeStored2(link) {
2686
2742
  if (typeof sessionStorage === "undefined") return;
2687
2743
  try {
2688
- sessionStorage.setItem(STORAGE_KEY3, JSON.stringify(link));
2744
+ sessionStorage.setItem(STORAGE_KEY4, JSON.stringify(link));
2689
2745
  } catch {
2690
2746
  }
2691
2747
  }
@@ -2733,7 +2789,7 @@ function extractIdentityMetadata(url) {
2733
2789
  function captureWebDeepLink() {
2734
2790
  if (didCapture) return captured;
2735
2791
  didCapture = true;
2736
- const stored = readStored();
2792
+ const stored = readStored2();
2737
2793
  if (stored) {
2738
2794
  captured = stored;
2739
2795
  return captured;
@@ -2742,7 +2798,7 @@ function captureWebDeepLink() {
2742
2798
  const link = parseUniversalLink(window.location.href);
2743
2799
  if (link && hasPayload(link)) {
2744
2800
  captured = link;
2745
- writeStored(link);
2801
+ writeStored2(link);
2746
2802
  void superlinkClient.reportEvent({
2747
2803
  type: "opened",
2748
2804
  click_id: link.click_id,
@@ -5651,11 +5707,11 @@ function getNotificationsPermission() {
5651
5707
  return Notification.permission === "granted";
5652
5708
  }
5653
5709
  function getDeviceAge() {
5654
- const STORAGE_KEY4 = "sitepong_device_age";
5710
+ const STORAGE_KEY5 = "sitepong_device_age";
5655
5711
  const result = { visitCount: 1 };
5656
5712
  if (typeof localStorage === "undefined") return result;
5657
5713
  try {
5658
- const stored = localStorage.getItem(STORAGE_KEY4);
5714
+ const stored = localStorage.getItem(STORAGE_KEY5);
5659
5715
  if (stored) {
5660
5716
  const parsed = JSON.parse(stored);
5661
5717
  result.firstSeen = parsed.firstSeen;
@@ -5663,7 +5719,7 @@ function getDeviceAge() {
5663
5719
  } else {
5664
5720
  result.firstSeen = (/* @__PURE__ */ new Date()).toISOString();
5665
5721
  }
5666
- localStorage.setItem(STORAGE_KEY4, JSON.stringify({
5722
+ localStorage.setItem(STORAGE_KEY5, JSON.stringify({
5667
5723
  firstSeen: result.firstSeen,
5668
5724
  visitCount: result.visitCount
5669
5725
  }));