@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 +23 -0
- package/README.md +146 -47
- package/dist/index.cjs +1244 -357
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +78 -65
- package/dist/index.d.ts +78 -65
- package/dist/index.mjs +1244 -357
- package/dist/index.mjs.map +1 -1
- package/dist/loamly.iife.global.js +1291 -140
- package/dist/loamly.iife.global.js.map +1 -1
- package/dist/loamly.iife.min.global.js +16 -1
- package/dist/loamly.iife.min.global.js.map +1 -1
- package/package.json +10 -12
- package/src/behavioral/form-tracker.ts +325 -0
- package/src/behavioral/index.ts +9 -0
- package/src/behavioral/scroll-tracker.ts +163 -0
- package/src/behavioral/time-tracker.ts +174 -0
- package/src/browser.ts +127 -36
- package/src/config.ts +1 -1
- package/src/core.ts +278 -156
- package/src/infrastructure/event-queue.ts +225 -0
- package/src/infrastructure/index.ts +8 -0
- package/src/infrastructure/ping.ts +149 -0
- package/src/spa/index.ts +7 -0
- package/src/spa/router.ts +147 -0
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
|
-
**
|
|
3
|
+
**See every AI bot that visits your website — and what they tell users about you.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
ChatGPT, Claude, Perplexity, Gemini — know when they crawl your pages or refer traffic.
|
|
6
6
|
|
|
7
|
-
[](https://www.npmjs.com/package/@loamly/tracker)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
9
|
|
|
10
|
-
|
|
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
|
-
|
|
14
|
+
This tracker uses multiple detection methods to identify AI-influenced visits:
|
|
15
15
|
|
|
16
|
-
|
|
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
|
-
-
|
|
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
|
-
###
|
|
28
|
+
### Option 1: CDN (Recommended)
|
|
34
29
|
|
|
35
30
|
```html
|
|
36
|
-
<script
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
52
|
-
loamly.
|
|
53
|
-
loamly.conversion('purchase', 99.99)
|
|
127
|
+
```typescript
|
|
128
|
+
loamly.conversion('purchase', 99.99, 'USD');
|
|
54
129
|
```
|
|
55
130
|
|
|
56
|
-
|
|
131
|
+
### `identify(userId, traits?)`
|
|
57
132
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
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
|
-
##
|
|
157
|
+
## Combine with Edge Detection
|
|
75
158
|
|
|
76
|
-
|
|
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
|
-
|