@temps-sdk/react-analytics 0.0.1-beta.31 → 0.0.1-beta.32

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 +1 @@
1
- {"version":3,"file":"useSessionRecording.d.ts","sourceRoot":"","sources":["../src/useSessionRecording.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,UAAU,4BAA4B;IACpC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAID,UAAU,6BAA6B;IACrC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,cAAsB,EACtB,iBAAwB,EACzB,EAAE,6BAA6B,2CA8D/B;AAED,wBAAgB,mBAAmB,IAAI,4BAA4B,CAMlE;AAGD,wBAAgB,0BAA0B,CAAC,cAAc,UAAQ;;;;;EAyChE"}
1
+ {"version":3,"file":"useSessionRecording.d.ts","sourceRoot":"","sources":["../src/useSessionRecording.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,UAAU,4BAA4B;IACpC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAID,UAAU,6BAA6B;IACrC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,cAAsB,EACtB,iBAAwB,EACzB,EAAE,6BAA6B,2CA0E/B;AAED,wBAAgB,mBAAmB,IAAI,4BAA4B,CAMlE;AAGD,wBAAgB,0BAA0B,CAAC,cAAc,UAAQ;;;;;EAyChE"}
@@ -24,20 +24,35 @@ export function SessionRecordingProvider({ children, defaultEnabled = false, per
24
24
  const enableRecording = useCallback(() => {
25
25
  setIsRecordingEnabled(true);
26
26
  if (persistPreference && typeof localStorage !== "undefined") {
27
- localStorage.setItem("temps_session_recording_enabled", "true");
27
+ try {
28
+ localStorage.setItem("temps_session_recording_enabled", "true");
29
+ }
30
+ catch (error) {
31
+ // Silently fail if localStorage is not available
32
+ }
28
33
  }
29
34
  }, [persistPreference]);
30
35
  const disableRecording = useCallback(() => {
31
36
  setIsRecordingEnabled(false);
32
37
  if (persistPreference && typeof localStorage !== "undefined") {
33
- localStorage.setItem("temps_session_recording_enabled", "false");
38
+ try {
39
+ localStorage.setItem("temps_session_recording_enabled", "false");
40
+ }
41
+ catch (error) {
42
+ // Silently fail if localStorage is not available
43
+ }
34
44
  }
35
45
  }, [persistPreference]);
36
46
  const toggleRecording = useCallback(() => {
37
47
  setIsRecordingEnabled(prev => {
38
48
  const newValue = !prev;
39
49
  if (persistPreference && typeof localStorage !== "undefined") {
40
- localStorage.setItem("temps_session_recording_enabled", String(newValue));
50
+ try {
51
+ localStorage.setItem("temps_session_recording_enabled", String(newValue));
52
+ }
53
+ catch (error) {
54
+ // Silently fail if localStorage is not available
55
+ }
41
56
  }
42
57
  return newValue;
43
58
  });
package/dist/utils.d.ts CHANGED
@@ -2,6 +2,8 @@ import type { JsonValue } from "./types";
2
2
  export declare function getRequestId(): string | undefined;
3
3
  export declare function isLocalhostLike(): boolean;
4
4
  export declare function isTestEnvironment(): boolean;
5
+ export declare function extractUtmParams(): Record<string, string>;
6
+ export declare function extractBrowserContext(): Record<string, unknown>;
5
7
  export declare function sendAnalytics(endpoint: string, data: Record<string, JsonValue>, method: "POST" | "PUT" | "PATCH" | undefined, basePath: string): Promise<void>;
6
8
  export declare function sendAnalyticsReliable(endpoint: string, data: Record<string, JsonValue>, basePath: string): boolean;
7
9
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,YAAY,IAAI,MAAM,GAAG,SAAS,CAcjD;AAED,wBAAgB,eAAe,IAAI,OAAO,CASzC;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAY3C;AAED,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/B,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,YAAS,EACzC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/B,QAAQ,EAAE,MAAM,GACf,OAAO,CAqCT"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,YAAY,IAAI,MAAM,GAAG,SAAS,CAcjD;AAED,wBAAgB,eAAe,IAAI,OAAO,CASzC;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAY3C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBzD;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwB/D;AAED,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/B,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,YAAS,EACzC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAyBf;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/B,QAAQ,EAAE,MAAM,GACf,OAAO,CA0CT"}
package/dist/utils.js CHANGED
@@ -41,10 +41,51 @@ export function isTestEnvironment() {
41
41
  const allowTemps = Boolean(window.__temps);
42
42
  return (isPhantom || isNightmare || isWebdriver || isCypress) && !allowTemps;
43
43
  }
44
+ export function extractUtmParams() {
45
+ if (typeof window === "undefined")
46
+ return {};
47
+ const params = new URLSearchParams(window.location.search);
48
+ const utmParams = {};
49
+ const utmKeys = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
50
+ for (const key of utmKeys) {
51
+ const value = params.get(key);
52
+ if (value) {
53
+ utmParams[key] = value;
54
+ }
55
+ }
56
+ return utmParams;
57
+ }
58
+ export function extractBrowserContext() {
59
+ if (typeof window === "undefined")
60
+ return {};
61
+ try {
62
+ const nav = window.navigator || {};
63
+ const screen = window.screen || {};
64
+ const context = {
65
+ language: nav.language || undefined,
66
+ screen_width: screen.width || undefined,
67
+ screen_height: screen.height || undefined,
68
+ viewport_width: window.innerWidth || undefined,
69
+ viewport_height: window.innerHeight || undefined,
70
+ };
71
+ // Only add referrer if it exists
72
+ if (typeof document !== "undefined" && document.referrer) {
73
+ context.referrer = document.referrer;
74
+ }
75
+ return context;
76
+ }
77
+ catch {
78
+ return {};
79
+ }
80
+ }
44
81
  export async function sendAnalytics(endpoint, data, method = "POST", basePath) {
45
82
  try {
83
+ const utmParams = extractUtmParams();
84
+ const browserContext = extractBrowserContext();
46
85
  const enrichedData = {
86
+ ...browserContext,
47
87
  ...data,
88
+ ...utmParams,
48
89
  request_id: getRequestId(),
49
90
  session_id: typeof localStorage !== "undefined"
50
91
  ? localStorage.getItem("session_id") || undefined
@@ -63,8 +104,12 @@ export async function sendAnalytics(endpoint, data, method = "POST", basePath) {
63
104
  }
64
105
  export function sendAnalyticsReliable(endpoint, data, basePath) {
65
106
  try {
107
+ const utmParams = extractUtmParams();
108
+ const browserContext = extractBrowserContext();
66
109
  const enrichedData = {
110
+ ...browserContext,
67
111
  ...data,
112
+ ...utmParams,
68
113
  request_id: getRequestId(),
69
114
  session_id: typeof localStorage !== "undefined"
70
115
  ? localStorage.getItem("session_id") || undefined
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temps-sdk/react-analytics",
3
- "version": "0.0.1-beta.31",
3
+ "version": "0.0.1-beta.32",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",