@thred-apps/thred-track 1.0.3

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,18 @@
1
+ Proprietary License
2
+
3
+ Copyright (c) 2026 Thred. All Rights Reserved.
4
+
5
+ This software and associated documentation files (the "Software") are the
6
+ proprietary property of Thred.
7
+
8
+ NOTICE: All information contained herein is, and remains the property of
9
+ Thred and its suppliers, if any. The intellectual and technical concepts
10
+ contained herein are proprietary to Thred and its suppliers and may be
11
+ covered by U.S. and Foreign Patents, patents in process, and are protected
12
+ by trade secret or copyright law.
13
+
14
+ Dissemination of this information or reproduction of this material is
15
+ strictly forbidden unless prior written permission is obtained from Thred.
16
+
17
+ Unauthorized copying, modification, distribution, or use of this software,
18
+ via any medium, is strictly prohibited.
package/README.md ADDED
@@ -0,0 +1,349 @@
1
+ # Thred SDK
2
+
3
+ A modern TypeScript SDK for browser tracking and lead enrichment from ChatGPT referrals.
4
+
5
+ ## Features
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
15
+
16
+ ## Installation
17
+
18
+ ### NPM
19
+
20
+ ```bash
21
+ npm install thred-track
22
+ ```
23
+
24
+ ### Yarn
25
+
26
+ ```bash
27
+ yarn add thred-track
28
+ ```
29
+
30
+ ### CDN (Script Tag)
31
+
32
+ ```html
33
+ <script src="https://unpkg.com/thred-track/dist/thred-track.umd.js?browserKey=YOUR_KEY"></script>
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ### Auto-Initialize (Script Tag)
39
+
40
+ Add the script with your browser key, and it will auto-initialize:
41
+
42
+ ```html
43
+ <script src="./dist/thred-track.umd.js?browserKey=751fe47a-d4f5-496a-ba9c-fb298c281e8a"></script>
44
+ ```
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)
53
+
54
+ ```typescript
55
+ import { ThredSDK } from 'thred-track';
56
+
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();
65
+ ```
66
+
67
+ ## API Reference
68
+
69
+ ### Constructor Options
70
+
71
+ ```typescript
72
+ interface ThredOptions {
73
+ browserKey: string; // Required: Your Thred browser key
74
+ baseUrl?: string; // Optional: API base URL (default: https://api.thred.dev/v1)
75
+ debug?: boolean; // Optional: Enable debug logging (default: false)
76
+ autoInit?: boolean; // Optional: Auto-initialize on construction (default: true)
77
+ }
78
+ ```
79
+
80
+ ### Methods
81
+
82
+ #### `init(): Promise<void>`
83
+
84
+ Initialize the SDK manually (only needed if `autoInit: false`).
85
+
86
+ ```typescript
87
+ await thred.init();
88
+ ```
89
+
90
+ #### `trackPageView(): Promise<void>`
91
+
92
+ Manually track a page view event.
93
+
94
+ ```typescript
95
+ await thred.trackPageView();
96
+ ```
97
+
98
+ #### `identify(leadData: LeadData): Promise<void>`
99
+
100
+ Identify a user and enrich lead data.
101
+
102
+ ```typescript
103
+ await thred.identify({
104
+ name: 'John Doe',
105
+ email: 'john@example.com',
106
+ company: 'Acme Inc',
107
+ });
108
+ ```
109
+
110
+ #### `trackFormSubmit(formData: FormData): Promise<void>`
111
+
112
+ Manually track a form submission.
113
+
114
+ ```typescript
115
+ const form = document.getElementById('myForm');
116
+ const formData = new FormData(form);
117
+ await thred.trackFormSubmit(formData);
118
+ ```
119
+
120
+ #### `getFingerprint(): string | null`
121
+
122
+ Get the current browser fingerprint (synchronous).
123
+
124
+ ```typescript
125
+ const fingerprint = thred.getFingerprint();
126
+ ```
127
+
128
+ #### `isFromChatGPT(): boolean`
129
+
130
+ Check if the visitor came from ChatGPT.
131
+
132
+ ```typescript
133
+ if (thred.isFromChatGPT()) {
134
+ console.log('Visitor from ChatGPT!');
135
+ }
136
+ ```
137
+
138
+ #### `destroy(): void`
139
+
140
+ Clean up the SDK instance and remove event listeners.
141
+
142
+ ```typescript
143
+ thred.destroy();
144
+ ```
145
+
146
+ ## Usage Examples
147
+
148
+ ### Basic Form Tracking
149
+
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>
157
+
158
+ <script src="./dist/thred-track.umd.js?browserKey=YOUR_KEY"></script>
159
+ ```
160
+
161
+ ### Programmatic Tracking
162
+
163
+ ```typescript
164
+ import { ThredSDK } from 'thred-track';
165
+
166
+ const thred = new ThredSDK({
167
+ browserKey: 'your-key',
168
+ debug: true,
169
+ });
170
+
171
+ // Track custom events
172
+ await thred.trackPageView();
173
+
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
+ });
181
+ });
182
+ ```
183
+
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
+ }));
195
+
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
+ };
207
+
208
+ return <YourApp onSubmit={handleSubmit} />;
209
+ }
210
+ ```
211
+
212
+ ## Development
213
+
214
+ ### Setup
215
+
216
+ ```bash
217
+ # Install dependencies
218
+ npm install
219
+
220
+ # Build the SDK
221
+ npm run build
222
+
223
+ # Run in watch mode
224
+ npm run dev
225
+
226
+ # Run tests
227
+ npm test
228
+
229
+ # Lint code
230
+ npm run lint
231
+
232
+ # Format code
233
+ npm run format
234
+ ```
235
+
236
+ ### Project Structure
237
+
238
+ ```
239
+ thred-track/
240
+ ├── 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
249
+ │ │ └── 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)
255
+ └── package.json
256
+ ```
257
+
258
+ ### Building
259
+
260
+ The SDK builds to multiple formats:
261
+
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
266
+
267
+ ### Testing
268
+
269
+ Run the test suite:
270
+
271
+ ```bash
272
+ npm test
273
+
274
+ # Watch mode
275
+ npm run test:watch
276
+ ```
277
+
278
+ ### Local Testing
279
+
280
+ Serve examples locally:
281
+
282
+ ```bash
283
+ npm run serve
284
+ ```
285
+
286
+ Then open http://localhost:8080/basic.html?utm_source=chatgpt
287
+
288
+ ## Configuration
289
+
290
+ The SDK fetches configuration from your Thred API:
291
+
292
+ ```json
293
+ {
294
+ "enabled": true,
295
+ "formId": "form",
296
+ "emailId": "email",
297
+ "nameId": "name",
298
+ "companyId": "company"
299
+ }
300
+ ```
301
+
302
+ ## Privacy & Security
303
+
304
+ - Only tracks visitors from ChatGPT (opt-in by source)
305
+ - Uses browser fingerprinting (no cookies required)
306
+ - All tracking controlled by API configuration
307
+ - No PII collected without explicit user submission
308
+ - Compliant with privacy regulations (GDPR, CCPA)
309
+
310
+ ## Browser Support
311
+
312
+ - Chrome/Edge (latest)
313
+ - Firefox (latest)
314
+ - Safari (latest)
315
+ - Opera (latest)
316
+
317
+ Requires ES2015+ support.
318
+
319
+ ## API Endpoints
320
+
321
+ - **Config**: `GET /v1/config?browserKey={key}`
322
+ - **Page View**: `POST /v1/events/page-view?browserKey={key}`
323
+ - **Enrich**: `POST /v1/customers/enrich?browserKey={key}`
324
+
325
+ ## TypeScript
326
+
327
+ Full TypeScript support with exported types:
328
+
329
+ ```typescript
330
+ import type {
331
+ ThredOptions,
332
+ ThredConfig,
333
+ LeadData,
334
+ PageViewPayload,
335
+ EnrichPayload,
336
+ } from 'thred-track';
337
+ ```
338
+
339
+ ## License
340
+
341
+ MIT
342
+
343
+ ## Contributing
344
+
345
+ Contributions are welcome! Please open an issue or submit a pull request.
346
+
347
+ ## Support
348
+
349
+ For questions or issues, please open a GitHub issue or contact support@thred.dev.
@@ -0,0 +1,21 @@
1
+ import type { ThredConfig, PageViewPayload, EnrichPayload } from '../types';
2
+ import { Logger } from '../utils/logger';
3
+ export declare class ThredAPI {
4
+ private baseUrl;
5
+ private browserKey;
6
+ private logger;
7
+ constructor(baseUrl: string, browserKey: string, logger: Logger);
8
+ /**
9
+ * Fetch configuration from API
10
+ */
11
+ fetchConfig(): Promise<ThredConfig | null>;
12
+ /**
13
+ * Send page view event
14
+ */
15
+ trackPageView(payload: PageViewPayload): Promise<void>;
16
+ /**
17
+ * Send lead enrichment data
18
+ */
19
+ enrichLead(payload: EnrichPayload): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/core/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,aAAa,EACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAM/D;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IA0BhD;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB5D;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBxD"}
@@ -0,0 +1,21 @@
1
+ import { Logger } from '../utils/logger';
2
+ export declare class FingerprintManager {
3
+ private fingerprint;
4
+ private logger;
5
+ private promise;
6
+ constructor(logger: Logger);
7
+ /**
8
+ * Get or generate fingerprint
9
+ */
10
+ getFingerprint(): Promise<string | null>;
11
+ private generateFingerprint;
12
+ /**
13
+ * Get cached fingerprint (synchronous)
14
+ */
15
+ getCachedFingerprint(): string | null;
16
+ /**
17
+ * Clear fingerprint cache
18
+ */
19
+ clear(): void;
20
+ }
21
+ //# sourceMappingURL=fingerprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../../src/core/fingerprint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAOzC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAuC;gBAE1C,MAAM,EAAE,MAAM;IAI1B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;YA2BhC,mBAAmB;IAyBjC;;OAEG;IACH,oBAAoB,IAAI,MAAM,GAAG,IAAI;IAIrC;;OAEG;IACH,KAAK;CAON"}
@@ -0,0 +1,37 @@
1
+ import type { LeadData } from '../types';
2
+ import { Logger } from '../utils/logger';
3
+ import { ThredAPI } from './api';
4
+ import { FingerprintManager } from './fingerprint';
5
+ export declare class Tracker {
6
+ private api;
7
+ private fingerprint;
8
+ private logger;
9
+ private config;
10
+ private formObserver;
11
+ constructor(api: ThredAPI, fingerprint: FingerprintManager, logger: Logger);
12
+ /**
13
+ * Initialize tracker with config
14
+ */
15
+ init(): Promise<void>;
16
+ /**
17
+ * Track page view event
18
+ */
19
+ trackPageView(): Promise<void>;
20
+ /**
21
+ * Track form submission and enrich lead
22
+ */
23
+ trackFormSubmit(formData: FormData): Promise<void>;
24
+ /**
25
+ * Identify user and enrich lead data
26
+ */
27
+ identify(leadData: LeadData): Promise<void>;
28
+ /**
29
+ * Setup automatic form tracking
30
+ */
31
+ private setupFormTracking;
32
+ /**
33
+ * Cleanup tracker
34
+ */
35
+ destroy(): void;
36
+ }
37
+ //# sourceMappingURL=tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/core/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,qBAAa,OAAO;IAClB,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,YAAY,CAAiC;gBAGnD,GAAG,EAAE,QAAQ,EACb,WAAW,EAAE,kBAAkB,EAC/B,MAAM,EAAE,MAAM;IAOhB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAe3B;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBpC;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BxD;;OAEG;IACG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAcjD;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA4FzB;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Thred SDK - Browser tracking and lead enrichment
3
+ */
4
+ import type { ThredOptions, ThredSDK as IThredSDK, LeadData } from './types';
5
+ export * from './types';
6
+ export declare class ThredSDK implements IThredSDK {
7
+ private options;
8
+ private logger;
9
+ private fingerprint;
10
+ private api;
11
+ private tracker;
12
+ private initialized;
13
+ constructor(options: ThredOptions);
14
+ /**
15
+ * Initialize the SDK
16
+ */
17
+ init(): Promise<void>;
18
+ /**
19
+ * Check if visitor is from ChatGPT
20
+ */
21
+ isFromChatGPT(): boolean;
22
+ /**
23
+ * Track page view
24
+ */
25
+ trackPageView(): Promise<void>;
26
+ /**
27
+ * Track form submission
28
+ */
29
+ trackFormSubmit(formData: FormData): Promise<void>;
30
+ /**
31
+ * Identify user with lead data
32
+ */
33
+ identify(leadData: LeadData): Promise<void>;
34
+ /**
35
+ * Get current fingerprint
36
+ */
37
+ getFingerprint(): string | null;
38
+ /**
39
+ * Destroy SDK instance and cleanup
40
+ */
41
+ destroy(): void;
42
+ }
43
+ export default ThredSDK;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,IAAI,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAO7E,cAAc,SAAS,CAAC;AAIxB,qBAAa,QAAS,YAAW,SAAS;IACxC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,EAAE,YAAY;IAsBjC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAwB3B;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD;;OAEG;IACG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD;;OAEG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB;AAaD,eAAe,QAAQ,CAAC"}