@loamly/tracker 1.9.0 → 2.0.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.
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Loamly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+
package/README.md CHANGED
@@ -1,82 +1,181 @@
1
1
  # @loamly/tracker
2
2
 
3
- **Open-source AI traffic detection for websites.**
3
+ **See every AI bot that visits your website — and what they tell users about you.**
4
4
 
5
- > See what AI tells your customers and track when they click.
5
+ ChatGPT, Claude, Perplexity, Gemini know when they crawl your pages or refer traffic.
6
6
 
7
- [![npm version](https://img.shields.io/npm/v/@loamly/tracker.svg)](https://www.npmjs.com/package/@loamly/tracker)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![npm](https://img.shields.io/npm/v/@loamly/tracker)](https://www.npmjs.com/package/@loamly/tracker)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
9
 
10
- Part of the [Loamly](https://github.com/loamly/loamly) open-source project.
10
+ ## Why This Exists
11
11
 
12
- ---
12
+ **75-85% of AI-referred traffic is invisible** to traditional analytics. Users copy-paste from ChatGPT or type URLs from Perplexity — no referrer, no UTM, no attribution.
13
13
 
14
- ## The Problem
14
+ This tracker uses multiple detection methods to identify AI-influenced visits:
15
15
 
16
- When users copy URLs from ChatGPT, Claude, or Perplexity:
16
+ | Method | Accuracy | What It Detects |
17
+ |--------|----------|-----------------|
18
+ | Navigation Timing API | 85% | Paste vs click (instant navigation = copy-paste) |
19
+ | Focus/Blur Sequence | 80% | Paste pattern (focus → immediate navigation) |
20
+ | Behavioral ML | 78% | Mouse patterns, scroll velocity, dwell time |
21
+ | Agentic Browser Detection | 92% | CDP automation, Perplexity Comet DOM |
22
+ | AI Referrer/UTM | 100% | Direct referrals from AI platforms |
17
23
 
18
- - No referrer header
19
- - ❌ No UTM parameters
20
- - ❌ Analytics shows "Direct Traffic"
21
-
22
- ## The Solution
23
-
24
- Loamly detects AI-referred traffic with **75-85% accuracy** using:
25
-
26
- - 🔍 Referrer detection
27
- - ⏱️ Navigation Timing API (paste vs click)
28
- - 🧠 Behavioral signals
29
- - 📋 Zero-party surveys
24
+ Combined with [@loamly/edge](../edge/) for server-side detection, you get **75-85% total accuracy**.
30
25
 
31
26
  ## Quick Start
32
27
 
33
- ### Script Tag
28
+ ### Option 1: CDN (Recommended)
34
29
 
35
30
  ```html
36
- <script
37
- src="https://unpkg.com/@loamly/tracker"
38
- data-api-key="your-api-key"
39
- ></script>
31
+ <script src="https://cdn.jsdelivr.net/npm/@loamly/tracker@2/dist/loamly.iife.min.global.js"></script>
32
+ <script>
33
+ Loamly.init({ apiKey: 'your-api-key' });
34
+ </script>
40
35
  ```
41
36
 
42
- ### NPM
37
+ ### Option 2: npm
43
38
 
44
39
  ```bash
45
40
  npm install @loamly/tracker
46
41
  ```
47
42
 
48
43
  ```typescript
49
- import loamly from '@loamly/tracker'
44
+ import { loamly } from '@loamly/tracker';
45
+
46
+ loamly.init({ apiKey: 'your-api-key' });
47
+ ```
48
+
49
+ ## Features
50
+
51
+ ### 🔍 Multi-Signal AI Detection
52
+
53
+ ```typescript
54
+ // Check current detection results
55
+ const ai = loamly.getAIDetection();
56
+ console.log(ai);
57
+ // { isAI: true, platform: 'chatgpt', confidence: 0.85, method: 'behavioral' }
58
+
59
+ const timing = loamly.getNavigationTiming();
60
+ console.log(timing);
61
+ // { nav_type: 'likely_paste', confidence: 0.92, signals: ['instant_fetch_start'] }
62
+
63
+ const behavioral = loamly.getBehavioralML();
64
+ console.log(behavioral);
65
+ // { classification: 'ai_influenced', humanProbability: 0.23, aiProbability: 0.77 }
66
+ ```
67
+
68
+ ### 📊 Advanced Behavioral Tracking
69
+
70
+ - **Scroll Depth**: 30% chunk reporting (30%, 60%, 90%, 100%)
71
+ - **Time Spent**: Active vs idle time, engagement detection
72
+ - **Form Tracking**: HubSpot, Typeform, JotForm, native forms
73
+ - **SPA Support**: Automatic History API detection
74
+
75
+ ### 🤖 Agentic Browser Detection
76
+
77
+ Detects AI agents that browse on behalf of users:
78
+
79
+ ```typescript
80
+ const agentic = loamly.getAgentic();
81
+ console.log(agentic);
82
+ // {
83
+ // cometDOMDetected: true, // Perplexity Comet overlay
84
+ // cdpDetected: false, // Chrome DevTools Protocol
85
+ // mousePatterns: { teleportingClicks: 0 },
86
+ // agenticProbability: 0.85
87
+ // }
88
+ ```
89
+
90
+ ### ⚡ Production Infrastructure
91
+
92
+ - **Event Queue**: Batching, retry with exponential backoff, localStorage persistence
93
+ - **Ping Service**: 30-second heartbeat for active sessions
94
+ - **Beacon Fallback**: Reliable event delivery on page unload
95
+ - **Offline Support**: Events queued when offline, synced when back
96
+
97
+ ## API Reference
98
+
99
+ ### `init(config)`
100
+
101
+ Initialize the tracker with configuration.
102
+
103
+ ```typescript
104
+ loamly.init({
105
+ apiKey: 'your-api-key', // Required
106
+ apiHost: 'https://app.loamly.ai', // Optional: custom host
107
+ debug: true, // Optional: enable console logging
108
+ disableAutoPageview: false, // Optional: disable auto pageview
109
+ disableBehavioral: false, // Optional: disable behavioral tracking
110
+ });
111
+ ```
112
+
113
+ ### `track(eventName, options?)`
114
+
115
+ Track a custom event.
116
+
117
+ ```typescript
118
+ loamly.track('button_click', {
119
+ properties: { buttonId: 'cta-hero' },
120
+ });
121
+ ```
122
+
123
+ ### `conversion(eventName, revenue, currency?)`
124
+
125
+ Track a conversion with revenue.
50
126
 
51
- loamly.init({ apiKey: 'your-api-key' })
52
- loamly.track('signup_started')
53
- loamly.conversion('purchase', 99.99)
127
+ ```typescript
128
+ loamly.conversion('purchase', 99.99, 'USD');
54
129
  ```
55
130
 
56
- ## API
131
+ ### `identify(userId, traits?)`
57
132
 
58
- | Method | Description |
59
- |--------|-------------|
60
- | `init(config)` | Initialize the tracker |
61
- | `pageview(url?)` | Track page view |
62
- | `track(event, options?)` | Track custom event |
63
- | `conversion(event, revenue, currency?)` | Track conversion |
64
- | `identify(userId, traits?)` | Identify user |
65
- | `getAIDetection()` | Get AI detection result |
66
- | `getNavigationTiming()` | Get paste vs click analysis |
133
+ Identify a user for cross-session tracking.
134
+
135
+ ```typescript
136
+ loamly.identify('user-123', {
137
+ email: 'user@example.com',
138
+ plan: 'pro',
139
+ });
140
+ ```
141
+
142
+ ### `pageview(url?)`
143
+
144
+ Manually track a pageview (useful for SPAs).
145
+
146
+ ```typescript
147
+ loamly.pageview('/dashboard');
148
+ ```
67
149
 
68
150
  ## Privacy
69
151
 
70
- - 🍪 Cookie-free
71
- - 📍 No IP tracking
72
- - 🔒 GDPR compliant
152
+ - **Cookie-free**: Uses localStorage for visitor/session ID
153
+ - **GDPR-friendly**: No personal data stored by default
154
+ - **Opt-out support**: Can be disabled via config
155
+ - **Open source**: Audit the code yourself
73
156
 
74
- ## Documentation
157
+ ## Combine with Edge Detection
75
158
 
76
- See [loamly.ai/docs](https://loamly.ai/docs) for full documentation.
159
+ For 100% accurate detection of ChatGPT Agent Mode and other signed bots, combine with [@loamly/edge](../edge/):
160
+
161
+ ```
162
+ ┌─────────────────────────────────────────────┐
163
+ │ @loamly/edge │
164
+ │ Cloudflare Worker (server-side) │
165
+ │ → 100% for signed bots (RFC 9421) │
166
+ │ → 95% for all AI crawlers │
167
+ └─────────────────────────────────────────────┘
168
+
169
+ ┌─────────────────────────────────────────────┐
170
+ │ @loamly/tracker │
171
+ │ Browser tracker (client-side) │
172
+ │ → Paste detection, behavioral ML │
173
+ │ → Agentic browser detection │
174
+ └─────────────────────────────────────────────┘
175
+
176
+ 75-85% total detection accuracy
177
+ ```
77
178
 
78
179
  ## License
79
180
 
80
181
  MIT © [Loamly](https://loamly.ai)
81
-
82
-