@mcp-fe/react-event-tracker 0.0.14 → 0.0.16

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/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity granting the License.
13
+
14
+ "Legal Entity" shall mean the union of the acting entity and all
15
+ other entities that control, are controlled by, or are under common
16
+ control with that entity. For the purposes of this definition,
17
+ "control" means (i) the power, direct or indirect, to cause the
18
+ direction or management of such entity, whether by contract or
19
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity
23
+ exercising permissions granted by this License.
24
+
25
+ "Source" shall mean the preferred form for making modifications,
26
+ including but not limited to software source code, documentation
27
+ source, and configuration files.
28
+
29
+ "Object" shall mean any form resulting from mechanical
30
+ transformation or translation of a Source form, including but
31
+ not limited to compiled object code, generated documentation,
32
+ and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or
35
+ Object form, made available under the License, as indicated by a
36
+ copyright notice that is included in or attached to the work
37
+ (which shall not include communications that are solely about
38
+ and bear an appropriate legal notice).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based upon (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and derivative works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control
57
+ systems, and issue tracking systems that are managed by, or on behalf
58
+ of, the Licensor for the purpose of discussing and improving the Work,
59
+ but excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to use, reproduce, modify, merge, publish,
70
+ distribute, sublicense, and/or sell copies of the Work, and to
71
+ permit persons to whom the Work is furnished to do so, subject to
72
+ the following conditions:
73
+
74
+ The above copyright notice and this permission notice shall be
75
+ included in all copies or substantial portions of the Work.
76
+
77
+ 3. Grant of Patent License. Subject to the terms and conditions of
78
+ this License, each Contributor hereby grants to You a perpetual,
79
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
80
+ (except as stated in this section) patent license to make, have made,
81
+ use, offer to sell, sell, import, and otherwise transfer the Work,
82
+ where such license applies only to those patent claims licensable
83
+ by such Contributor that are necessarily infringed by their
84
+ Contribution(s) alone or by combination of their Contribution(s)
85
+ with the Work to which such Contribution(s) was submitted. If You
86
+ institute patent litigation against any entity (including a
87
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
88
+ or a Contribution incorporated within the Work constitutes direct
89
+ or contributory patent infringement, then any patent licenses
90
+ granted to You under this License for that Work shall terminate
91
+ as of the date such litigation is filed.
92
+
93
+ 4. Redistribution. You may reproduce and distribute copies of the
94
+ Work or Derivative Works thereof in any medium, with or without
95
+ modifications, and in Source or Object form, provided that You
96
+ meet the following conditions:
97
+
98
+ (a) You must give any other recipients of the Work or
99
+ Derivative Works a copy of this License; and
100
+
101
+ (b) You must cause any modified files to carry prominent notices
102
+ stating that You changed the files; and
103
+
104
+ (c) You must retain, in the Source form of any Derivative Works
105
+ that You distribute, all copyright, patent, trademark, and
106
+ attribution notices from the Source form of the Work,
107
+ excluding those notices that do not pertain to any part of
108
+ the Derivative Works; and
109
+
110
+ (d) If the Work includes a "NOTICE" text file as part of its
111
+ distribution, then any Derivative Works that You distribute must
112
+ include a readable copy of the attribution notices contained
113
+ within such NOTICE file, excluding those notices that do not
114
+ pertain to any part of the Derivative Works, in at least one
115
+ of the following places: within a NOTICE text file distributed
116
+ as part of the Derivative Works; within the Source form or
117
+ documentation, if provided along with the Derivative Works; or,
118
+ within a display generated by the Derivative Works, if and
119
+ wherever such third-party notices normally appear. The contents
120
+ of the NOTICE file are for informational purposes only and
121
+ do not modify the License. You may add Your own attribution
122
+ notices within Derivative Works that You distribute, alongside
123
+ or as an addendum to the NOTICE text from the Work, provided
124
+ that such additional attribution notices cannot be construed
125
+ as modifying the License.
126
+
127
+ You may add Your own copyright notice to Your modifications and
128
+ may provide additional or different license terms and conditions
129
+ for use, reproduction, or distribution of Your modifications, or
130
+ for any such Derivative Works as a whole, provided Your use,
131
+ reproduction, and distribution of the Work otherwise complies with
132
+ the conditions stated in this License.
133
+
134
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
135
+ any Contribution intentionally submitted for inclusion in the Work
136
+ by You to the Licensor shall be under the terms and conditions of
137
+ this License, without any additional terms or conditions.
138
+ Notwithstanding the above, nothing herein shall supersede or modify
139
+ the terms of any separate license agreement you may have executed
140
+ with Licensor regarding such Contributions.
141
+
142
+ 6. Trademarks. This License does not grant permission to use the trade
143
+ names, trademarks, service marks, or product names of the Licensor,
144
+ except as required for reasonable and customary use in describing the
145
+ origin of the Work and reproducing the content of the NOTICE file.
146
+
147
+ 7. Disclaimer of Warranty. Unless required by applicable law or
148
+ agreed to in writing, Licensor provides the Work (and each
149
+ Contributor provides its Contributions) on an "AS IS" BASIS,
150
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
151
+ implied, including, without limitation, any warranties or conditions
152
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
153
+ PARTICULAR PURPOSE. You are solely responsible for determining the
154
+ appropriateness of using or redistributing the Work and assume any
155
+ risks associated with Your exercise of permissions under this License.
156
+
157
+ 8. Limitation of Liability. In no event and under no legal theory,
158
+ whether in tort (including negligence), contract, or otherwise,
159
+ unless required by applicable law (such as deliberate and grossly
160
+ negligent acts) or agreed to in writing, shall any Contributor be
161
+ liable to You for damages, including any direct, indirect, special,
162
+ incidental, or consequential damages of any character arising as a
163
+ result of this License or out of the use or inability to use the
164
+ Work (including but not limited to damages for loss of goodwill,
165
+ work stoppage, computer failure or malfunction, or any and all
166
+ other commercial damages or losses), even if such Contributor
167
+ has been advised of the possibility of such damages.
168
+
169
+ 9. Accepting Warranty or Support. You may choose to offer, and to
170
+ charge a fee for, warranty, support, indemnity or other liability
171
+ obligations and/or rights consistent with this License. However, in
172
+ accepting such obligations, You may act only on Your own behalf and on
173
+ Your sole responsibility, not on behalf of any other Contributor, and
174
+ only if You agree to indemnify, defend, and hold each Contributor
175
+ harmless for any liability incurred by, or claims asserted against,
176
+ such Contributor by reason of your accepting any such warranty or support.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same page as the copyright notice for easier identification within
189
+ third-party archives.
190
+
191
+ Copyright 2026 [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md CHANGED
@@ -1,7 +1,300 @@
1
- # react-event-tracker
1
+ # @mcp-fe/react-event-tracker
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ React integration for the MCP-FE (Model Context Protocol - Frontend Edge) ecosystem. This library provides React hooks that automatically track user interactions and navigation events, making them available to AI agents through the MCP protocol.
4
4
 
5
- ## Running unit tests
5
+ ## Overview
6
+
7
+ `@mcp-fe/react-event-tracker` is a React-specific integration layer that simplifies the process of tracking user interactions in React applications. It works in conjunction with [`@mcp-fe/mcp-worker`](../mcp-worker/README.md) to provide a complete MCP-FE solution for React apps.
8
+
9
+ ### Key Features
10
+
11
+ - **Automatic Navigation Tracking**: Tracks route changes in React Router and TanStack Router applications
12
+ - **User Interaction Tracking**: Automatically tracks clicks, input changes, and other user interactions
13
+ - **Zero Configuration**: Works out-of-the-box with minimal setup
14
+ - **Authentication Support**: Built-in support for setting authentication tokens
15
+ - **Framework Agnostic Core**: Built on top of [`@mcp-fe/event-tracker`](../event-tracker/README.md)
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @mcp-fe/react-event-tracker @mcp-fe/mcp-worker
21
+ # or
22
+ pnpm add @mcp-fe/react-event-tracker @mcp-fe/mcp-worker
23
+ # or
24
+ yarn add @mcp-fe/react-event-tracker @mcp-fe/mcp-worker
25
+ ```
26
+
27
+ ### Peer Dependencies
28
+
29
+ This package requires the following peer dependencies:
30
+
31
+ - React >=19.0.0
32
+ - React DOM >=19.0.0
33
+ - React Router DOM >=6.0.0 (for React Router integration)
34
+ - TanStack Router >=1.0.0 (for TanStack Router integration)
35
+
36
+ ## Setup
37
+
38
+ Before using the React hooks, you need to:
39
+
40
+ 1. **Copy worker files** to your public directory from `@mcp-fe/mcp-worker`
41
+ 2. **Set up the MCP proxy server** (see [`@mcp-fe/mcp-worker` documentation](../mcp-worker/README.md))
42
+
43
+ ## Usage
44
+
45
+ ### React Router Integration
46
+
47
+ For applications using React Router, use the `useReactRouterEventTracker` hook:
48
+
49
+ ```typescript
50
+ import React, { useEffect } from 'react';
51
+ import { BrowserRouter, Routes, Route } from 'react-router-dom';
52
+ import { useReactRouterEventTracker } from '@mcp-fe/react-event-tracker';
53
+
54
+ function App() {
55
+ const { setAuthToken } = useReactRouterEventTracker({
56
+ backendWsUrl: 'ws://localhost:3001'
57
+ });
58
+
59
+ // Set authentication token when available
60
+ useEffect(() => {
61
+ const token = localStorage.getItem('authToken');
62
+ if (token) {
63
+ setAuthToken(token);
64
+ }
65
+ }, [setAuthToken]);
66
+
67
+ return (
68
+ <BrowserRouter>
69
+ <Routes>
70
+ <Route path="/" element={<HomePage />} />
71
+ <Route path="/about" element={<AboutPage />} />
72
+ {/* Your other routes */}
73
+ </Routes>
74
+ </BrowserRouter>
75
+ );
76
+ }
77
+
78
+ function HomePage() {
79
+ return (
80
+ <div>
81
+ <h1>Welcome!</h1>
82
+ <button onClick={() => alert('Clicked!')}>
83
+ Click me (this click will be tracked)
84
+ </button>
85
+ <input
86
+ placeholder="Type here (input changes will be tracked)"
87
+ onChange={(e) => console.log(e.target.value)}
88
+ />
89
+ </div>
90
+ );
91
+ }
92
+ ```
93
+
94
+ ### TanStack Router Integration
95
+
96
+ For applications using TanStack Router, use the `useTanstackRouterEventTracker` hook:
97
+
98
+ ```typescript
99
+ import React, { useEffect } from 'react';
100
+ import { useTanstackRouterEventTracker } from '@mcp-fe/react-event-tracker';
101
+
102
+ function App() {
103
+ const { setAuthToken } = useTanstackRouterEventTracker({
104
+ backendWsUrl: 'ws://localhost:3001'
105
+ });
106
+
107
+ useEffect(() => {
108
+ const token = localStorage.getItem('authToken');
109
+ if (token) {
110
+ setAuthToken(token);
111
+ }
112
+ }, [setAuthToken]);
113
+
114
+ return (
115
+ <div>
116
+ {/* Your TanStack Router setup */}
117
+ <h1>My TanStack Router App</h1>
118
+ {/* Components and interactions will be automatically tracked */}
119
+ </div>
120
+ );
121
+ }
122
+ ```
123
+
124
+ ## Configuration Options
125
+
126
+ Both hooks accept optional configuration parameters:
127
+
128
+ ```typescript
129
+ interface WorkerClientInitOptions {
130
+ backendWsUrl?: string; // WebSocket URL of your MCP proxy server
131
+ workerPath?: string; // Custom path to worker files
132
+ fallbackToServiceWorker?: boolean; // Enable ServiceWorker fallback
133
+ }
134
+ ```
135
+
136
+ ### Example with custom configuration:
137
+
138
+ ```typescript
139
+ const { setAuthToken } = useReactRouterEventTracker({
140
+ backendWsUrl: 'wss://my-mcp-server.com/ws',
141
+ workerPath: '/workers',
142
+ fallbackToServiceWorker: true
143
+ });
144
+ ```
145
+
146
+ ## What Gets Tracked
147
+
148
+ The React event tracker automatically captures:
149
+
150
+ ### Navigation Events
151
+ - Route changes (from previous route to current route)
152
+ - Page loads and refreshes
153
+
154
+ ### User Interactions
155
+ - **Clicks**: Element tag, ID, class, text content (first 100 chars)
156
+ - **Input Changes**: Input/textarea changes (debounced by 1 second)
157
+ - **Form Interactions**: Button clicks, link clicks
158
+
159
+ ### Event Data Structure
160
+
161
+ Each tracked event includes:
162
+
163
+ ```typescript
164
+ interface UserEventData {
165
+ type: 'navigation' | 'click' | 'input' | 'custom';
166
+ path?: string; // Current page path
167
+ from?: string; // Previous route (navigation only)
168
+ to?: string; // Current route (navigation only)
169
+ element?: string; // Element tag name
170
+ elementId?: string; // Element ID attribute
171
+ elementClass?: string; // Element class attribute
172
+ elementText?: string; // Element text content
173
+ metadata?: Record<string, unknown>; // Additional data
174
+ timestamp: number; // Event timestamp
175
+ }
176
+ ```
177
+
178
+ ## Authentication
179
+
180
+ To associate tracked events with specific users, set an authentication token:
181
+
182
+ ```typescript
183
+ const { setAuthToken } = useReactRouterEventTracker();
184
+
185
+ // When user logs in
186
+ const handleLogin = async (credentials) => {
187
+ const response = await login(credentials);
188
+ const token = response.token;
189
+
190
+ // Store token for your app
191
+ localStorage.setItem('authToken', token);
192
+
193
+ // Set token for MCP tracking
194
+ setAuthToken(token);
195
+ };
196
+
197
+ // When user logs out
198
+ const handleLogout = () => {
199
+ localStorage.removeItem('authToken');
200
+ setAuthToken(''); // Clear the token
201
+ };
202
+ ```
203
+
204
+ ## Integration with MCP Agents
205
+
206
+ Once events are being tracked, AI agents can query them through the MCP protocol:
207
+
208
+ ```json
209
+ {
210
+ "jsonrpc": "2.0",
211
+ "method": "tools/call",
212
+ "params": {
213
+ "name": "get_user_events",
214
+ "arguments": {
215
+ "type": "click",
216
+ "limit": 10
217
+ }
218
+ }
219
+ }
220
+ ```
221
+
222
+ This enables AI agents to:
223
+ - Debug user interface issues
224
+ - Provide context-aware customer support
225
+ - Analyze user behavior patterns
226
+ - Guide users through complex workflows
227
+
228
+ ## Advanced Usage
229
+
230
+ ### Custom Event Tracking
231
+
232
+ You can also track custom events alongside the automatic tracking:
233
+
234
+ ```typescript
235
+ import { trackEvent } from '@mcp-fe/event-tracker';
236
+
237
+ // Track a custom business event
238
+ await trackEvent({
239
+ type: 'custom',
240
+ metadata: {
241
+ eventName: 'purchase_completed',
242
+ orderId: '12345',
243
+ amount: 99.99
244
+ }
245
+ });
246
+ ```
247
+
248
+ ### Connection Status Monitoring
249
+
250
+ Monitor the connection status to the MCP proxy server:
251
+
252
+ ```typescript
253
+ import { getConnectionStatus, onConnectionStatus } from '@mcp-fe/event-tracker';
254
+
255
+ // Check current status
256
+ const isConnected = await getConnectionStatus();
257
+
258
+ // Listen for status changes
259
+ onConnectionStatus((connected) => {
260
+ console.log('MCP connection:', connected ? 'Connected' : 'Disconnected');
261
+ });
262
+ ```
263
+
264
+ ## Requirements
265
+
266
+ - **MCP Worker**: This package requires [`@mcp-fe/mcp-worker`](../mcp-worker/README.md) to be properly set up
267
+ - **MCP Proxy Server**: You need a running MCP proxy server to collect the events
268
+ - **Public Worker Files**: Worker files must be accessible from your web server's public directory
269
+
270
+ ## Troubleshooting
271
+
272
+ ### Events Not Being Tracked
273
+
274
+ 1. **Check worker initialization**: Ensure `@mcp-fe/mcp-worker` files are in your public directory
275
+ 2. **Verify proxy connection**: Check that your MCP proxy server is running and accessible
276
+ 3. **Check browser console**: Look for initialization errors or connection issues
277
+
278
+ ### Navigation Not Tracked
279
+
280
+ 1. **Router integration**: Ensure you're using the correct hook for your router (React Router vs TanStack Router)
281
+ 2. **Hook placement**: Make sure the hook is called within the router context
282
+
283
+ ### Authentication Issues
284
+
285
+ 1. **Token format**: Ensure your authentication token is in the expected format
286
+ 2. **Timing**: Set the auth token after both the tracker and your authentication system are initialized
287
+
288
+ ## Examples
289
+
290
+ Check out the example application in the `apps/mcp-fe` directory for a complete working implementation.
291
+
292
+ ## Related Packages
293
+
294
+ - [`@mcp-fe/mcp-worker`](../mcp-worker/README.md): Core MCP worker implementation
295
+ - [`@mcp-fe/event-tracker`](../event-tracker/README.md): Framework-agnostic event tracking library
296
+
297
+ ## License
298
+
299
+ Licensed under the Apache License, Version 2.0. See the [LICENSE](../../LICENSE) file for details.
6
300
 
7
- Run `nx test react-event-tracker` to execute the unit tests via [Vitest](https://vitest.dev/).
package/index.d.ts CHANGED
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2026 MCP-FE Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  export * from './hooks/useTanstackRouterEventTracker';
2
17
  export * from './hooks/useReactRouterEventTracker';
3
18
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../libs/react-event-tracker/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../libs/react-event-tracker/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "name": "@mcp-fe/react-event-tracker",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
+ "license": "Apache-2.0",
5
+ "homepage": "https://mcp-fe.ai",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/mcp-fe/mcp-fe.git",
9
+ "directory": "libs/react-event-tracker"
10
+ },
4
11
  "main": "./index.js",
5
12
  "types": "./index.d.ts",
6
13
  "exports": {
@@ -11,7 +18,7 @@
11
18
  }
12
19
  },
13
20
  "dependencies": {
14
- "@mcp-fe/event-tracker": "0.0.14"
21
+ "@mcp-fe/event-tracker": "0.0.16"
15
22
  },
16
23
  "peerDependencies": {
17
24
  "react": ">=19.0.0",