fimo-react-router 2.8.0-staging.1 → 2.8.0-staging.2

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.
@@ -4,6 +4,6 @@ type DisplayRoute = {
4
4
  };
5
5
  export declare function Pageview({ routes }: {
6
6
  routes: DisplayRoute[];
7
- }): null;
7
+ }): import("react/jsx-runtime").JSX.Element;
8
8
  export {};
9
9
  //# sourceMappingURL=Pageview.d.ts.map
package/dist/Pageview.js CHANGED
@@ -1,54 +1,9 @@
1
- import { useEffect, useRef } from 'react';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Analytics } from 'fimo-analytics/react-router';
2
3
  import { useLocation } from 'react-router';
3
- const VISITOR_ID_STORAGE_KEY = 'fimo.analytics.visitor-id';
4
- const SESSION_ID_STORAGE_KEY = 'fimo.analytics.session-id';
5
4
  const viteEnv = import.meta.env;
6
5
  const API_BASE_URL = viteEnv?.VITE_API_URL?.replace(/\/$/, '');
7
6
  const ENABLE_ANALYTICS = (viteEnv?.VITE_ENABLE_ANALYTICS ?? '').toLowerCase() === 'true';
8
- function isPreviewContext() {
9
- if (typeof window === 'undefined') {
10
- return false;
11
- }
12
- const search = new URLSearchParams(window.location.search);
13
- return search.has('bl_preview_token');
14
- }
15
- function createId() {
16
- if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
17
- return crypto.randomUUID();
18
- }
19
- return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
20
- }
21
- function readOrCreateStoredId(storage, key) {
22
- const existing = storage.getItem(key);
23
- if (existing && existing.length > 0) {
24
- return existing;
25
- }
26
- const generated = createId();
27
- storage.setItem(key, generated);
28
- return generated;
29
- }
30
- function getVisitorId() {
31
- if (typeof window === 'undefined') {
32
- return createId();
33
- }
34
- try {
35
- return readOrCreateStoredId(window.localStorage, VISITOR_ID_STORAGE_KEY);
36
- }
37
- catch {
38
- return createId();
39
- }
40
- }
41
- function getSessionId() {
42
- if (typeof window === 'undefined') {
43
- return createId();
44
- }
45
- try {
46
- return readOrCreateStoredId(window.sessionStorage, SESSION_ID_STORAGE_KEY);
47
- }
48
- catch {
49
- return createId();
50
- }
51
- }
52
7
  function normalizePath(path) {
53
8
  const trimmed = path.trim();
54
9
  if (!trimmed) {
@@ -75,44 +30,7 @@ function findRouteName(pathname, routes) {
75
30
  }
76
31
  return null;
77
32
  }
78
- function sendPageview(path, pageName) {
79
- if (typeof window === 'undefined' || !API_BASE_URL || !ENABLE_ANALYTICS || isPreviewContext()) {
80
- return;
81
- }
82
- const payload = new URLSearchParams({
83
- p: path || '/',
84
- n: pageName,
85
- v: getVisitorId(),
86
- s: getSessionId(),
87
- });
88
- if (document.referrer) {
89
- payload.set('r', document.referrer);
90
- }
91
- if (navigator.userAgent) {
92
- payload.set('u', navigator.userAgent);
93
- }
94
- void fetch(`${API_BASE_URL}/e/p`, {
95
- method: 'POST',
96
- body: payload,
97
- keepalive: true,
98
- mode: 'cors',
99
- credentials: 'omit',
100
- }).catch(() => {
101
- // best-effort analytics
102
- });
103
- }
104
33
  export function Pageview({ routes }) {
105
- const location = useLocation();
106
- const lastTrackedPath = useRef(null);
107
- useEffect(() => {
108
- const currentPath = `${location.pathname}${location.search}`;
109
- const routeName = findRouteName(location.pathname, routes);
110
- const currentPageName = routeName ?? normalizePath(location.pathname);
111
- if (currentPath === lastTrackedPath.current) {
112
- return;
113
- }
114
- lastTrackedPath.current = currentPath;
115
- sendPageview(currentPath, currentPageName);
116
- }, [location.pathname, location.search, routes]);
117
- return null;
34
+ const { pathname } = useLocation();
35
+ return (_jsx(Analytics, { endpoint: API_BASE_URL ? `${API_BASE_URL}/e/p` : '', enabled: Boolean(API_BASE_URL) && ENABLE_ANALYTICS, pageName: findRouteName(pathname, routes) ?? normalizePath(pathname) }));
118
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fimo-react-router",
3
- "version": "2.8.0-staging.1",
3
+ "version": "2.8.0-staging.2",
4
4
  "description": "Fimo runtime, routing and build integration for React Router projects. Pairs with the fimo package at the same version.",
5
5
  "files": [
6
6
  "dist/",
@@ -39,17 +39,18 @@
39
39
  "test:watch": "vitest"
40
40
  },
41
41
  "dependencies": {
42
+ "fimo-analytics": "2.8.0-staging.2",
42
43
  "react-error-boundary": "^6.0.0"
43
44
  },
44
45
  "devDependencies": {
45
- "@fimo/tsconfig": "2.8.0-staging.1",
46
+ "@fimo/tsconfig": "2.8.0-staging.2",
46
47
  "@tanstack/react-query": "^5.80.6",
47
48
  "@types/node": "22.18.6",
48
49
  "@types/react": "19.2.14",
49
50
  "@types/react-dom": "19.2.3",
50
- "fimo": "2.8.0-staging.1",
51
- "fimo-react": "2.8.0-staging.1",
52
- "fimo-vite": "2.8.0-staging.1",
51
+ "fimo": "2.8.0-staging.2",
52
+ "fimo-react": "2.8.0-staging.2",
53
+ "fimo-vite": "2.8.0-staging.2",
53
54
  "react": "19.2.4",
54
55
  "react-dom": "19.2.4",
55
56
  "react-router": "7.18.2",
@@ -59,7 +60,7 @@
59
60
  },
60
61
  "peerDependencies": {
61
62
  "@tanstack/react-query": "^5.80.6",
62
- "fimo": "2.8.0-staging.1",
63
+ "fimo": "2.8.0-staging.2",
63
64
  "fimo-react": ">=2.0.1",
64
65
  "fimo-vite": ">=2.0.1",
65
66
  "react": "^18.2.0 || ^19.0.0",