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.
package/dist/index.mjs CHANGED
@@ -518,6 +518,60 @@ function clearSession() {
518
518
  memorySessionTs = null;
519
519
  }
520
520
 
521
+ // src/analytics/utm.ts
522
+ var STORAGE_KEY2 = "sp_utm";
523
+ var UTM_KEYS = [
524
+ ["source", "utm_source"],
525
+ ["medium", "utm_medium"],
526
+ ["campaign", "utm_campaign"],
527
+ ["term", "utm_term"],
528
+ ["content", "utm_content"]
529
+ ];
530
+ function parseFromLocation() {
531
+ if (typeof window === "undefined" || !window.location || !window.location.search) return null;
532
+ let params;
533
+ try {
534
+ params = new URLSearchParams(window.location.search);
535
+ } catch {
536
+ return null;
537
+ }
538
+ const result = {};
539
+ let found = false;
540
+ for (const [key, queryKey] of UTM_KEYS) {
541
+ const value = params.get(queryKey);
542
+ if (value) {
543
+ result[key] = value;
544
+ found = true;
545
+ }
546
+ }
547
+ return found ? result : null;
548
+ }
549
+ function readStored() {
550
+ if (typeof sessionStorage === "undefined") return null;
551
+ try {
552
+ const raw = sessionStorage.getItem(STORAGE_KEY2);
553
+ if (!raw) return null;
554
+ const parsed = JSON.parse(raw);
555
+ return parsed && typeof parsed === "object" ? parsed : null;
556
+ } catch {
557
+ return null;
558
+ }
559
+ }
560
+ function writeStored(utm) {
561
+ if (typeof sessionStorage === "undefined") return;
562
+ try {
563
+ sessionStorage.setItem(STORAGE_KEY2, JSON.stringify(utm));
564
+ } catch {
565
+ }
566
+ }
567
+ function getSessionUtm() {
568
+ const stored = readStored();
569
+ if (stored) return stored;
570
+ const fresh = parseFromLocation();
571
+ if (fresh) writeStored(fresh);
572
+ return fresh;
573
+ }
574
+
521
575
  // src/analytics/autocapture.ts
522
576
  var DEFAULT_BLOCK_SELECTORS = [
523
577
  "[data-sp-no-capture]",
@@ -924,7 +978,9 @@ var AnalyticsManager = class {
924
978
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
925
979
  url: typeof window !== "undefined" && window.location ? window.location.href : void 0,
926
980
  referrer: typeof document !== "undefined" && typeof document.referrer === "string" ? document.referrer : void 0,
927
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
981
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
982
+ utm: getSessionUtm() || void 0,
983
+ appVersion: this.config.appVersion || void 0
928
984
  };
929
985
  }
930
986
  enqueue(event) {
@@ -1622,7 +1678,7 @@ var DEFAULT_REMOTE_CONFIG = {
1622
1678
  };
1623
1679
 
1624
1680
  // src/remote-config/manager.ts
1625
- var STORAGE_KEY2 = "sitepong_remote_config";
1681
+ var STORAGE_KEY3 = "sitepong_remote_config";
1626
1682
  var STORAGE_TS_KEY = "sitepong_remote_config_ts";
1627
1683
  var RemoteConfigManager = class {
1628
1684
  constructor(options) {
@@ -1665,7 +1721,7 @@ var RemoteConfigManager = class {
1665
1721
  const storage = this.options.storage;
1666
1722
  if (!storage) return;
1667
1723
  try {
1668
- const cached = await storage.getItem(STORAGE_KEY2);
1724
+ const cached = await storage.getItem(STORAGE_KEY3);
1669
1725
  const cachedTs = await storage.getItem(STORAGE_TS_KEY);
1670
1726
  if (cached && cachedTs) {
1671
1727
  const age = Date.now() - parseInt(cachedTs, 10);
@@ -1726,7 +1782,7 @@ var RemoteConfigManager = class {
1726
1782
  const storage = this.options.storage;
1727
1783
  if (!storage) return;
1728
1784
  try {
1729
- await storage.setItem(STORAGE_KEY2, JSON.stringify(this.config));
1785
+ await storage.setItem(STORAGE_KEY3, JSON.stringify(this.config));
1730
1786
  await storage.setItem(STORAGE_TS_KEY, String(Date.now()));
1731
1787
  } catch {
1732
1788
  this.log("Failed to cache remote config");
@@ -1982,7 +2038,7 @@ function stripTrailingSlash(url) {
1982
2038
  var superlinkClient = new SuperLinkClient();
1983
2039
 
1984
2040
  // src/superlink/parse.ts
1985
- var UTM_KEYS = [
2041
+ var UTM_KEYS2 = [
1986
2042
  ["source", "utm_source"],
1987
2043
  ["medium", "utm_medium"],
1988
2044
  ["campaign", "utm_campaign"],
@@ -1998,7 +2054,7 @@ function parseUniversalLink(url) {
1998
2054
  }
1999
2055
  const params = parsed.searchParams;
2000
2056
  const utm = {};
2001
- for (const [key, queryKey] of UTM_KEYS) {
2057
+ for (const [key, queryKey] of UTM_KEYS2) {
2002
2058
  const value = params.get(queryKey);
2003
2059
  if (value) utm[key] = value;
2004
2060
  }
@@ -2065,13 +2121,13 @@ function getMatchedDeepLink() {
2065
2121
  }
2066
2122
 
2067
2123
  // src/superlink/web.ts
2068
- var STORAGE_KEY3 = "sp_superlink";
2124
+ var STORAGE_KEY4 = "sp_superlink";
2069
2125
  var captured = null;
2070
2126
  var didCapture = false;
2071
- function readStored() {
2127
+ function readStored2() {
2072
2128
  if (typeof sessionStorage === "undefined") return null;
2073
2129
  try {
2074
- const raw = sessionStorage.getItem(STORAGE_KEY3);
2130
+ const raw = sessionStorage.getItem(STORAGE_KEY4);
2075
2131
  if (!raw) return null;
2076
2132
  const parsed = JSON.parse(raw);
2077
2133
  return parsed && typeof parsed === "object" ? parsed : null;
@@ -2079,10 +2135,10 @@ function readStored() {
2079
2135
  return null;
2080
2136
  }
2081
2137
  }
2082
- function writeStored(link) {
2138
+ function writeStored2(link) {
2083
2139
  if (typeof sessionStorage === "undefined") return;
2084
2140
  try {
2085
- sessionStorage.setItem(STORAGE_KEY3, JSON.stringify(link));
2141
+ sessionStorage.setItem(STORAGE_KEY4, JSON.stringify(link));
2086
2142
  } catch {
2087
2143
  }
2088
2144
  }
@@ -2130,7 +2186,7 @@ function extractIdentityMetadata(url) {
2130
2186
  function captureWebDeepLink() {
2131
2187
  if (didCapture) return captured;
2132
2188
  didCapture = true;
2133
- const stored = readStored();
2189
+ const stored = readStored2();
2134
2190
  if (stored) {
2135
2191
  captured = stored;
2136
2192
  return captured;
@@ -2139,7 +2195,7 @@ function captureWebDeepLink() {
2139
2195
  const link = parseUniversalLink(window.location.href);
2140
2196
  if (link && hasPayload(link)) {
2141
2197
  captured = link;
2142
- writeStored(link);
2198
+ writeStored2(link);
2143
2199
  void superlinkClient.reportEvent({
2144
2200
  type: "opened",
2145
2201
  click_id: link.click_id,