@thred-apps/thred-track 1.1.5 → 1.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.
Files changed (2) hide show
  1. package/README.md +113 -161
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,14 +4,14 @@ A modern TypeScript SDK for browser tracking and lead enrichment from ChatGPT re
4
4
 
5
5
  ## Features
6
6
 
7
- - 🎯 **ChatGPT Detection** - Automatic detection of visitors from ChatGPT
8
- - 🔒 **Browser Fingerprinting** - Privacy-friendly visitor identification
9
- - 📊 **Page View Tracking** - Anonymous page view analytics
10
- - 📝 **Form Tracking** - Automatic form submission tracking
11
- - 💼 **Lead Enrichment** - Capture and enrich lead data
12
- - 🚀 **Zero Dependencies** - Lightweight with no external dependencies
13
- - 📦 **Multiple Formats** - UMD, CommonJS, and ES modules
14
- - 🔧 **TypeScript Support** - Full TypeScript definitions included
7
+ - **ChatGPT Detection** - Automatic detection of visitors from ChatGPT
8
+ - **Browser Fingerprinting** - Privacy-friendly visitor identification
9
+ - **Page View Tracking** - Automatic page view analytics
10
+ - **Form Tracking** - Automatic form submission tracking
11
+ - **Lead Enrichment** - Capture and enrich lead data
12
+ - **Zero Dependencies** - Lightweight with no external dependencies
13
+ - **Multiple Formats** - UMD, CommonJS, and ES modules
14
+ - **TypeScript Support** - Full TypeScript definitions included
15
15
 
16
16
  ## Installation
17
17
 
@@ -30,183 +30,155 @@ yarn add thred-track
30
30
  ### CDN (Script Tag)
31
31
 
32
32
  ```html
33
- <script src="https://unpkg.com/thred-track/dist/thred-track.umd.js?browserKey=YOUR_KEY"></script>
33
+ <script src="https://cdn.thred.dev/thred-track.js?browserKey=YOUR_KEY"></script>
34
34
  ```
35
35
 
36
36
  ## Quick Start
37
37
 
38
- ### Auto-Initialize (Script Tag)
38
+ ### Script Tag
39
39
 
40
- Add the script with your browser key, and it will auto-initialize:
40
+ Drop the script onto your page with your browser key. That's it everything is automatic:
41
41
 
42
42
  ```html
43
- <script src="./dist/thred-track.umd.js?browserKey=751fe47a-d4f5-496a-ba9c-fb298c281e8a"></script>
43
+ <script src="https://cdn.thred.dev/thred-track.js?browserKey=YOUR_KEY"></script>
44
44
  ```
45
45
 
46
- The SDK will automatically:
47
- - Detect ChatGPT referrals
48
- - Generate browser fingerprint
49
- - Track page views
50
- - Monitor form submissions
51
-
52
- ### Manual Initialization (Module)
46
+ ### Module Import
53
47
 
54
48
  ```typescript
55
49
  import { ThredSDK } from 'thred-track';
56
50
 
57
- const thred = new ThredSDK({
58
- browserKey: 'your-browser-key',
59
- debug: true,
60
- autoInit: false, // Control initialization
61
- });
62
-
63
- // Initialize manually
64
- await thred.init();
51
+ new ThredSDK({ browserKey: 'YOUR_KEY' });
65
52
  ```
66
53
 
67
- ## API Reference
54
+ No additional setup required. The SDK automatically:
68
55
 
69
- ### Constructor Options
56
+ 1. Detects ChatGPT referrals via UTM parameters
57
+ 2. Generates a browser fingerprint
58
+ 3. Tracks page views for ChatGPT visitors
59
+ 4. Monitors and captures form submissions based on your API config
60
+
61
+ ## What Happens on Initialization
62
+
63
+ When the SDK initializes, it follows the same flow as the original script:
64
+
65
+ 1. **Fetches config** from the Thred API using your `browserKey`
66
+ 2. **Checks eligibility** — tracking only runs if the config says `enabled: true` and the visitor has a ChatGPT session or arrived via ChatGPT UTM
67
+ 3. **Tracks the page view** automatically for ChatGPT visitors
68
+ 4. **Sets up form tracking** — either injecting fingerprints into hosted form links, or attaching submit listeners to your form (based on config `type`)
69
+
70
+ All of this happens without any manual method calls.
71
+
72
+ ## Constructor Options
70
73
 
71
74
  ```typescript
72
75
  interface ThredOptions {
73
76
  browserKey: string; // Required: Your Thred browser key
74
- baseUrl?: string; // Optional: API base URL (default: https://api.thred.dev/v1)
75
77
  debug?: boolean; // Optional: Enable debug logging (default: false)
76
78
  autoInit?: boolean; // Optional: Auto-initialize on construction (default: true)
77
79
  }
78
80
  ```
79
81
 
80
- ### Methods
82
+ ## Usage Examples
81
83
 
82
- #### `init(): Promise<void>`
84
+ ### Basic HTML Page
83
85
 
84
- Initialize the SDK manually (only needed if `autoInit: false`).
86
+ ```html
87
+ <form id="form">
88
+ <input type="text" name="name" required>
89
+ <input type="email" name="email" required>
90
+ <input type="text" name="company">
91
+ <button type="submit">Submit</button>
92
+ </form>
85
93
 
86
- ```typescript
87
- await thred.init();
94
+ <script src="https://unpkg.com/thred-track/dist/thred-track.umd.js?browserKey=YOUR_KEY"></script>
88
95
  ```
89
96
 
90
- #### `trackPageView(): Promise<void>`
97
+ The SDK automatically picks up the form and tracks submissions — no extra JavaScript needed.
91
98
 
92
- Manually track a page view event.
99
+ ### React
93
100
 
94
101
  ```typescript
95
- await thred.trackPageView();
96
- ```
102
+ import { useEffect, useRef } from 'react';
103
+ import { ThredSDK } from 'thred-track';
97
104
 
98
- #### `identify(leadData: LeadData): Promise<void>`
105
+ function App() {
106
+ const thredRef = useRef<ThredSDK | null>(null);
99
107
 
100
- Identify a user and enrich lead data.
108
+ useEffect(() => {
109
+ thredRef.current = new ThredSDK({
110
+ browserKey: process.env.REACT_APP_THRED_KEY!,
111
+ debug: process.env.NODE_ENV === 'development',
112
+ });
101
113
 
102
- ```typescript
103
- await thred.identify({
104
- name: 'John Doe',
105
- email: 'john@example.com',
106
- company: 'Acme Inc',
107
- });
108
- ```
114
+ return () => thredRef.current?.destroy();
115
+ }, []);
109
116
 
110
- #### `trackFormSubmit(formData: FormData): Promise<void>`
117
+ return <YourApp />;
118
+ }
119
+ ```
111
120
 
112
- Manually track a form submission.
121
+ ### Next.js
113
122
 
114
123
  ```typescript
115
- const form = document.getElementById('myForm');
116
- const formData = new FormData(form);
117
- await thred.trackFormSubmit(formData);
118
- ```
119
-
120
- #### `getFingerprint(): string | null`
124
+ 'use client';
121
125
 
122
- Get the current browser fingerprint (synchronous).
126
+ import { useEffect, useRef } from 'react';
127
+ import { ThredSDK } from 'thred-track';
123
128
 
124
- ```typescript
125
- const fingerprint = thred.getFingerprint();
126
- ```
129
+ export function ThredProvider({ children }: { children: React.ReactNode }) {
130
+ const thredRef = useRef<ThredSDK | null>(null);
127
131
 
128
- #### `isFromChatGPT(): boolean`
132
+ useEffect(() => {
133
+ thredRef.current = new ThredSDK({
134
+ browserKey: process.env.NEXT_PUBLIC_THRED_KEY!,
135
+ });
129
136
 
130
- Check if the visitor came from ChatGPT.
137
+ return () => thredRef.current?.destroy();
138
+ }, []);
131
139
 
132
- ```typescript
133
- if (thred.isFromChatGPT()) {
134
- console.log('Visitor from ChatGPT!');
140
+ return <>{children}</>;
135
141
  }
136
142
  ```
137
143
 
138
- #### `destroy(): void`
144
+ ### Delayed Initialization
139
145
 
140
- Clean up the SDK instance and remove event listeners.
146
+ If you need to control when tracking starts (e.g., after user consent):
141
147
 
142
148
  ```typescript
143
- thred.destroy();
144
- ```
145
-
146
- ## Usage Examples
147
-
148
- ### Basic Form Tracking
149
+ import { ThredSDK } from 'thred-track';
149
150
 
150
- ```html
151
- <form id="form">
152
- <input type="text" name="name" required>
153
- <input type="email" name="email" required>
154
- <input type="text" name="company">
155
- <button type="submit">Submit</button>
156
- </form>
151
+ const thred = new ThredSDK({
152
+ browserKey: 'YOUR_KEY',
153
+ autoInit: false,
154
+ });
157
155
 
158
- <script src="./dist/thred-track.umd.js?browserKey=YOUR_KEY"></script>
156
+ // Later, when ready:
157
+ await thred.init();
159
158
  ```
160
159
 
161
- ### Programmatic Tracking
160
+ ## Advanced API
162
161
 
163
- ```typescript
164
- import { ThredSDK } from 'thred-track';
162
+ These methods are available for advanced use cases but are **not required** for typical usage — the SDK handles everything automatically.
165
163
 
166
- const thred = new ThredSDK({
167
- browserKey: 'your-key',
168
- debug: true,
169
- });
164
+ #### `identify(leadData: LeadData): Promise<void>`
170
165
 
171
- // Track custom events
172
- await thred.trackPageView();
166
+ Manually identify a user outside of automatic form tracking (e.g., after OAuth or a custom flow):
173
167
 
174
- // Identify users manually
175
- document.querySelector('#signup-btn').addEventListener('click', async () => {
176
- await thred.identify({
177
- name: userName,
178
- email: userEmail,
179
- company: userCompany,
180
- });
168
+ ```typescript
169
+ await thred.identify({
170
+ name: 'John Doe',
171
+ email: 'john@example.com',
172
+ company: 'Acme Inc',
181
173
  });
182
174
  ```
183
175
 
184
- ### React Integration
185
-
186
- ```typescript
187
- import { useEffect, useState } from 'react';
188
- import { ThredSDK } from 'thred-track';
189
-
190
- function App() {
191
- const [thred] = useState(() => new ThredSDK({
192
- browserKey: process.env.REACT_APP_THRED_KEY,
193
- debug: process.env.NODE_ENV === 'development',
194
- }));
176
+ #### `destroy(): void`
195
177
 
196
- useEffect(() => {
197
- return () => thred.destroy();
198
- }, [thred]);
199
-
200
- const handleSubmit = async (formData) => {
201
- await thred.identify({
202
- name: formData.name,
203
- email: formData.email,
204
- company: formData.company,
205
- });
206
- };
178
+ Clean up the SDK instance and remove event listeners. Use this when unmounting in SPAs:
207
179
 
208
- return <YourApp onSubmit={handleSubmit} />;
209
- }
180
+ ```typescript
181
+ thred.destroy();
210
182
  ```
211
183
 
212
184
  ## Development
@@ -214,22 +186,11 @@ function App() {
214
186
  ### Setup
215
187
 
216
188
  ```bash
217
- # Install dependencies
218
189
  npm install
219
-
220
- # Build the SDK
221
190
  npm run build
222
-
223
- # Run in watch mode
224
- npm run dev
225
-
226
- # Run tests
191
+ npm run dev # Watch mode
227
192
  npm test
228
-
229
- # Lint code
230
193
  npm run lint
231
-
232
- # Format code
233
194
  npm run format
234
195
  ```
235
196
 
@@ -238,20 +199,18 @@ npm run format
238
199
  ```
239
200
  thred-track/
240
201
  ├── src/
241
- │ ├── core/ # Core SDK functionality
242
- │ │ ├── api.ts # API client
243
- │ │ ├── fingerprint.ts # Fingerprint management
244
- │ │ └── tracker.ts # Event tracking
245
- │ ├── utils/ # Utility functions
246
- │ │ ├── detector.ts # ChatGPT detection
247
- │ │ └── logger.ts # Logging utility
248
- │ ├── types/ # TypeScript definitions
202
+ │ ├── core/ # Core SDK functionality
203
+ │ │ ├── api.ts # API client
204
+ │ │ ├── fingerprint.ts # Fingerprint management
205
+ │ │ └── tracker.ts # Event tracking
206
+ │ ├── utils/ # Utility functions
207
+ │ │ ├── detector.ts # ChatGPT detection
208
+ │ │ └── logger.ts # Logging utility
209
+ │ ├── types/ # TypeScript definitions
249
210
  │ │ └── index.ts
250
- │ ├── __tests__/ # Test files
251
- │ └── index.ts # Main entry point
252
- ├── examples/ # Usage examples
253
- ├── dist/ # Build output
254
- ├── thred-track.js # Original implementation (reference)
211
+ │ ├── __tests__/ # Test files
212
+ │ └── index.ts # Main entry point
213
+ ├── dist/ # Build output
255
214
  └── package.json
256
215
  ```
257
216
 
@@ -259,26 +218,20 @@ thred-track/
259
218
 
260
219
  The SDK builds to multiple formats:
261
220
 
262
- - **UMD** (`dist/thred-track.umd.js`) - For script tags
263
- - **CommonJS** (`dist/index.js`) - For Node.js
264
- - **ES Module** (`dist/index.esm.js`) - For bundlers
265
- - **TypeScript** (`dist/index.d.ts`) - Type definitions
221
+ - **UMD** (`dist/thred-track.umd.js`) For script tags
222
+ - **CommonJS** (`dist/index.js`) For Node.js / bundlers
223
+ - **ES Module** (`dist/index.esm.js`) For modern bundlers
224
+ - **TypeScript** (`dist/index.d.ts`) Type definitions
266
225
 
267
226
  ### Testing
268
227
 
269
- Run the test suite:
270
-
271
228
  ```bash
272
229
  npm test
273
-
274
- # Watch mode
275
230
  npm run test:watch
276
231
  ```
277
232
 
278
233
  ### Local Testing
279
234
 
280
- Serve examples locally:
281
-
282
235
  ```bash
283
236
  npm run serve
284
237
  ```
@@ -287,11 +240,12 @@ Then open http://localhost:8080/basic.html?utm_source=chatgpt
287
240
 
288
241
  ## Configuration
289
242
 
290
- The SDK fetches configuration from your Thred API:
243
+ The SDK fetches configuration from your Thred API automatically on init:
291
244
 
292
245
  ```json
293
246
  {
294
247
  "enabled": true,
248
+ "type": "custom",
295
249
  "formId": "form",
296
250
  "emailId": "email",
297
251
  "nameId": "name",
@@ -300,6 +254,8 @@ The SDK fetches configuration from your Thred API:
300
254
  }
301
255
  ```
302
256
 
257
+ This config controls which form to track, which fields to extract, and whether the visitor has an existing ChatGPT session.
258
+
303
259
  ## Privacy & Security
304
260
 
305
261
  - Only tracks visitors from ChatGPT (opt-in by source)
@@ -341,10 +297,6 @@ import type {
341
297
 
342
298
  MIT
343
299
 
344
- ## Contributing
345
-
346
- Contributions are welcome! Please open an issue or submit a pull request.
347
-
348
300
  ## Support
349
301
 
350
302
  For questions or issues, please open a GitHub issue or contact support@thred.dev.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thred-apps/thred-track",
3
- "version": "1.1.5",
3
+ "version": "1.2.1",
4
4
  "description": "Browser SDK for lead tracking and enrichment from ChatGPT referrals",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",