Browser SDK for lead tracking and enrichment from ChatGPT referrals
npm install @thred-apps/thred-trackA modern TypeScript SDK for browser tracking and lead enrichment from ChatGPT referrals.
- šÆ ChatGPT Detection - Automatic detection of visitors from ChatGPT
- š Browser Fingerprinting - Privacy-friendly visitor identification
- š Page View Tracking - Anonymous page view analytics
- š Form Tracking - Automatic form submission tracking
- š¼ Lead Enrichment - Capture and enrich lead data
- š Zero Dependencies - Lightweight with no external dependencies
- š¦ Multiple Formats - UMD, CommonJS, and ES modules
- š§ TypeScript Support - Full TypeScript definitions included
``bash`
npm install thred-track
`bash`
yarn add thred-track
`html`
Add the script with your browser key, and it will auto-initialize:
`html`
The SDK will automatically:
- Detect ChatGPT referrals
- Generate browser fingerprint
- Track page views
- Monitor form submissions
`typescript
import { ThredSDK } from 'thred-track';
const thred = new ThredSDK({
browserKey: 'your-browser-key',
debug: true,
autoInit: false, // Control initialization
});
// Initialize manually
await thred.init();
`
`typescript`
interface ThredOptions {
browserKey: string; // Required: Your Thred browser key
baseUrl?: string; // Optional: API base URL (default: https://api.thred.dev/v1)
debug?: boolean; // Optional: Enable debug logging (default: false)
autoInit?: boolean; // Optional: Auto-initialize on construction (default: true)
}
#### init(): Promise
Initialize the SDK manually (only needed if autoInit: false).
`typescript`
await thred.init();
#### trackPageView(): Promise
Manually track a page view event.
`typescript`
await thred.trackPageView();
#### identify(leadData: LeadData): Promise
Identify a user and enrich lead data.
`typescript`
await thred.identify({
name: 'John Doe',
email: 'john@example.com',
company: 'Acme Inc',
});
#### trackFormSubmit(formData: FormData): Promise
Manually track a form submission.
`typescript`
const form = document.getElementById('myForm');
const formData = new FormData(form);
await thred.trackFormSubmit(formData);
#### getFingerprint(): string | null
Get the current browser fingerprint (synchronous).
`typescript`
const fingerprint = thred.getFingerprint();
#### isFromChatGPT(): boolean
Check if the visitor came from ChatGPT.
`typescript`
if (thred.isFromChatGPT()) {
console.log('Visitor from ChatGPT!');
}
#### destroy(): void
Clean up the SDK instance and remove event listeners.
`typescript`
thred.destroy();
`html
`
`typescript
import { ThredSDK } from 'thred-track';
const thred = new ThredSDK({
browserKey: 'your-key',
debug: true,
});
// Track custom events
await thred.trackPageView();
// Identify users manually
document.querySelector('#signup-btn').addEventListener('click', async () => {
await thred.identify({
name: userName,
email: userEmail,
company: userCompany,
});
});
`
`typescript
import { useEffect, useState } from 'react';
import { ThredSDK } from 'thred-track';
function App() {
const [thred] = useState(() => new ThredSDK({
browserKey: process.env.REACT_APP_THRED_KEY,
debug: process.env.NODE_ENV === 'development',
}));
useEffect(() => {
return () => thred.destroy();
}, [thred]);
const handleSubmit = async (formData) => {
await thred.identify({
name: formData.name,
email: formData.email,
company: formData.company,
});
};
return
}
`
`bashInstall dependencies
npm install
$3
`
thred-track/
āāā src/
ā āāā core/ # Core SDK functionality
ā ā āāā api.ts # API client
ā ā āāā fingerprint.ts # Fingerprint management
ā ā āāā tracker.ts # Event tracking
ā āāā utils/ # Utility functions
ā ā āāā detector.ts # ChatGPT detection
ā ā āāā logger.ts # Logging utility
ā āāā types/ # TypeScript definitions
ā ā āāā index.ts
ā āāā __tests__/ # Test files
ā āāā index.ts # Main entry point
āāā examples/ # Usage examples
āāā dist/ # Build output
āāā thred-track.js # Original implementation (reference)
āāā package.json
`$3
The SDK builds to multiple formats:
- UMD (
dist/thred-track.umd.js) - For script tags
- CommonJS (dist/index.js) - For Node.js
- ES Module (dist/index.esm.js) - For bundlers
- TypeScript (dist/index.d.ts) - Type definitions$3
Run the test suite:
`bash
npm testWatch mode
npm run test:watch
`$3
Serve examples locally:
`bash
npm run serve
`Then open http://localhost:8080/basic.html?utm_source=chatgpt
Configuration
The SDK fetches configuration from your Thred API:
`json
{
"enabled": true,
"formId": "form",
"emailId": "email",
"nameId": "name",
"companyId": "company"
}
`Privacy & Security
- Only tracks visitors from ChatGPT (opt-in by source)
- Uses browser fingerprinting (no cookies required)
- All tracking controlled by API configuration
- No PII collected without explicit user submission
- Compliant with privacy regulations (GDPR, CCPA)
Browser Support
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)
- Opera (latest)
Requires ES2015+ support.
API Endpoints
- Config:
GET /v1/config?browserKey={key}
- Page View: POST /v1/events/page-view?browserKey={key}
- Enrich: POST /v1/customers/enrich?browserKey={key}TypeScript
Full TypeScript support with exported types:
`typescript
import type {
ThredOptions,
ThredConfig,
LeadData,
PageViewPayload,
EnrichPayload,
} from 'thred-track';
``MIT
Contributions are welcome! Please open an issue or submit a pull request.
For questions or issues, please open a GitHub issue or contact support@thred.dev.