@athena-tracker/tracker 1.0.0
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/README.md +317 -0
- package/dist/events/capture-react-native.d.ts +77 -0
- package/dist/events/capture-react-native.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +2860 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2872 -0
- package/dist/index.js.map +1 -0
- package/dist/inference/auto-detect.d.ts +21 -0
- package/dist/inference/auto-detect.d.ts.map +1 -0
- package/dist/inference/on-device.d.ts +36 -0
- package/dist/inference/on-device.d.ts.map +1 -0
- package/dist/inference/server.d.ts +30 -0
- package/dist/inference/server.d.ts.map +1 -0
- package/dist/react-native/ForcedReloadWrapper.d.ts +26 -0
- package/dist/react-native/ForcedReloadWrapper.d.ts.map +1 -0
- package/dist/tracker.d.ts +82 -0
- package/dist/tracker.d.ts.map +1 -0
- package/dist/types/index.d.ts +96 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
# @athena/tracker
|
|
2
|
+
|
|
3
|
+
> Behavioral analytics tracker with edge AI for React Native and Web
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ 90+ behavioral event types auto-captured
|
|
8
|
+
- ✅ On-device ML inference (<10ms latency)
|
|
9
|
+
- ✅ Server-side fallback for OTA apps
|
|
10
|
+
- ✅ Works on Web, iOS, Android
|
|
11
|
+
- ✅ Zero configuration required
|
|
12
|
+
- ✅ TypeScript support
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @athena/tracker
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### For React Native with On-Device Inference
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @athena/tracker onnxruntime-react-native
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### For OTA Updates (Server-Side Inference)
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @athena/tracker
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
(No `onnxruntime-react-native` required - will automatically fall back to server-side inference)
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### React Native
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import AthenaTracker from '@athena/tracker';
|
|
40
|
+
|
|
41
|
+
// Initialize tracker
|
|
42
|
+
AthenaTracker.init({
|
|
43
|
+
appToken: 'at_live_xxxxx',
|
|
44
|
+
inferenceMode: 'auto', // Auto-detects environment
|
|
45
|
+
webhook: {
|
|
46
|
+
url: 'https://your-backend.com/webhooks/athena',
|
|
47
|
+
enabled: true
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Web
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<script src="https://tracker.pascal.cx/v1/tracker.min.js"></script>
|
|
56
|
+
<script>
|
|
57
|
+
const tracker = new PascalTracker({
|
|
58
|
+
projectId: 'your-app-token',
|
|
59
|
+
edgeAI: {
|
|
60
|
+
enabled: true,
|
|
61
|
+
modelPath: 'https://tracker.pascal.cx/models/base_model_int8.onnx'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
</script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
### AthenaConfig
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
interface AthenaConfig {
|
|
73
|
+
appToken: string; // Required: App token from ATHENA provisioning
|
|
74
|
+
apiUrl?: string; // Optional: API base URL (default: https://tracker.pascal.cx)
|
|
75
|
+
inferenceMode?: 'auto' | 'on-device' | 'server'; // Optional: Inference mode
|
|
76
|
+
modelPath?: string; // Optional: ONNX model path (for on-device)
|
|
77
|
+
serverInferenceUrl?: string; // Optional: Server inference endpoint
|
|
78
|
+
webhook?: WebhookConfig; // Optional: Webhook configuration
|
|
79
|
+
batching?: BatchingConfig; // Optional: Event batching
|
|
80
|
+
debug?: boolean; // Optional: Debug mode
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Inference Modes
|
|
85
|
+
|
|
86
|
+
#### Auto Mode (Recommended)
|
|
87
|
+
|
|
88
|
+
Automatically detects whether `onnxruntime-react-native` is available:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
AthenaTracker.init({
|
|
92
|
+
appToken: 'at_live_xxxxx',
|
|
93
|
+
inferenceMode: 'auto' // Default
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### On-Device Mode (Forced)
|
|
98
|
+
|
|
99
|
+
Force on-device inference (requires `onnxruntime-react-native`):
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
AthenaTracker.init({
|
|
103
|
+
appToken: 'at_live_xxxxx',
|
|
104
|
+
inferenceMode: 'on-device',
|
|
105
|
+
modelPath: '/path/to/model.onnx'
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### Server Mode (Forced)
|
|
110
|
+
|
|
111
|
+
Force server-side inference:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
AthenaTracker.init({
|
|
115
|
+
appToken: 'at_live_xxxxx',
|
|
116
|
+
inferenceMode: 'server',
|
|
117
|
+
serverInferenceUrl: 'https://api.pascal.cx/v1/predict'
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Webhook Integration
|
|
122
|
+
|
|
123
|
+
Receive real-time predictions via webhooks:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
AthenaTracker.init({
|
|
127
|
+
appToken: 'at_live_xxxxx',
|
|
128
|
+
webhook: {
|
|
129
|
+
url: 'https://your-backend.com/webhooks/athena',
|
|
130
|
+
enabled: true,
|
|
131
|
+
retry: {
|
|
132
|
+
maxAttempts: 3,
|
|
133
|
+
backoffMs: 1000
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Webhook Payload
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"user_id": "user_abc",
|
|
144
|
+
"session_id": "sess_123",
|
|
145
|
+
"predicted_class": "engaged_explorer",
|
|
146
|
+
"confidence": 0.85,
|
|
147
|
+
"archetype": "on_track",
|
|
148
|
+
"purchase_intent": 0.72,
|
|
149
|
+
"cart_abandonment_risk": 0.15,
|
|
150
|
+
"recommended_action": "Show 10% discount offer",
|
|
151
|
+
"urgency": "high",
|
|
152
|
+
"trigger_reason": "High-value cart ($249), 80% scroll depth, 45s time-on-page",
|
|
153
|
+
"timestamp": "2026-02-24T12:34:56Z"
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## User Archetypes
|
|
158
|
+
|
|
159
|
+
| Archetype | Description | Similarity Score |
|
|
160
|
+
|-----------|-------------|------------------|
|
|
161
|
+
| **fast_mover** | High purchase intent, quick decision-maker | >85% |
|
|
162
|
+
| **on_track** | Steady browsing, likely to convert | 60-85% |
|
|
163
|
+
| **slow_adopter** | Needs guidance, price-sensitive | 40-60% |
|
|
164
|
+
| **at_risk** | Low engagement, high abandonment risk | <40% |
|
|
165
|
+
| **different_path** | Unconventional browsing pattern | Unique |
|
|
166
|
+
|
|
167
|
+
## API Reference
|
|
168
|
+
|
|
169
|
+
### AthenaTracker
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
class AthenaTracker {
|
|
173
|
+
static init(config: AthenaConfig): Promise<void>
|
|
174
|
+
static identify(userId: string, traits?: Record<string, any>): void
|
|
175
|
+
static track(eventType: string, properties?: Record<string, any>): void
|
|
176
|
+
static getInferenceMode(): 'on-device' | 'server' | null
|
|
177
|
+
static getSessionId(): string | null
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Methods
|
|
182
|
+
|
|
183
|
+
#### `init(config)`
|
|
184
|
+
|
|
185
|
+
Initialize the tracker with configuration.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
await AthenaTracker.init({
|
|
189
|
+
appToken: 'at_live_xxxxx'
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### `identify(userId, traits?)`
|
|
194
|
+
|
|
195
|
+
Identify a user.
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
AthenaTracker.identify('user_123', {
|
|
199
|
+
email: 'user@example.com',
|
|
200
|
+
name: 'John Doe'
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### `track(eventType, properties?)`
|
|
205
|
+
|
|
206
|
+
Track a custom event.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
AthenaTracker.track('button_click', {
|
|
210
|
+
button_id: 'checkout',
|
|
211
|
+
page: '/cart'
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## React Native Components
|
|
216
|
+
|
|
217
|
+
### AthenaOTAWrapper
|
|
218
|
+
|
|
219
|
+
For apps using Expo OTA updates, wrap your app with `AthenaOTAWrapper`:
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
import { AthenaOTAWrapper } from '@athena/tracker';
|
|
223
|
+
|
|
224
|
+
export default function App() {
|
|
225
|
+
return (
|
|
226
|
+
<AthenaOTAWrapper
|
|
227
|
+
loadingMessage="Loading..."
|
|
228
|
+
updateMessage="Updating..."
|
|
229
|
+
>
|
|
230
|
+
<YourApp />
|
|
231
|
+
</AthenaOTAWrapper>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**What it does:**
|
|
237
|
+
- Checks for OTA updates on app launch
|
|
238
|
+
- Fetches and applies updates automatically
|
|
239
|
+
- Forces immediate reload (<2 seconds)
|
|
240
|
+
- Displays loading spinner during update
|
|
241
|
+
|
|
242
|
+
**Props:**
|
|
243
|
+
- `loadingMessage` (string, optional): Message during initial load (default: "Loading...")
|
|
244
|
+
- `updateMessage` (string, optional): Message during update (default: "Updating...")
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
### ReactNativeEventCapture
|
|
249
|
+
|
|
250
|
+
Advanced event capture for custom use cases:
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
import { ReactNativeEventCapture } from '@athena/tracker';
|
|
254
|
+
|
|
255
|
+
const capture = new ReactNativeEventCapture({
|
|
256
|
+
captureTouch: true,
|
|
257
|
+
captureNavigation: true,
|
|
258
|
+
captureLifecycle: true,
|
|
259
|
+
captureNetworkErrors: true,
|
|
260
|
+
batchSize: 10,
|
|
261
|
+
batchIntervalMs: 10000
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Start capturing
|
|
265
|
+
capture.start();
|
|
266
|
+
|
|
267
|
+
// Track screen view manually
|
|
268
|
+
capture.trackScreenView('ProductDetails', { productId: '123' });
|
|
269
|
+
|
|
270
|
+
// Track custom event
|
|
271
|
+
capture.track('AddToCart', { productId: '123', price: 49.99 });
|
|
272
|
+
|
|
273
|
+
// Stop capturing
|
|
274
|
+
capture.stop();
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Configuration:**
|
|
278
|
+
- `captureTouch` (boolean): Capture touch events (Tap, Swipe, LongPress)
|
|
279
|
+
- `captureNavigation` (boolean): Capture screen navigation
|
|
280
|
+
- `captureLifecycle` (boolean): Capture app lifecycle (Open, Background, Foreground)
|
|
281
|
+
- `captureNetworkErrors` (boolean): Capture failed network requests
|
|
282
|
+
- `batchSize` (number): Events per batch (default: 10)
|
|
283
|
+
- `batchIntervalMs` (number): Batch interval in milliseconds (default: 10000)
|
|
284
|
+
|
|
285
|
+
**Captured Events:**
|
|
286
|
+
- `AppOpen`, `AppForeground`, `AppBackground`, `AppInactive`
|
|
287
|
+
- `Tap`, `Swipe`, `LongPress`
|
|
288
|
+
- `ScreenView`
|
|
289
|
+
- `NetworkError`
|
|
290
|
+
|
|
291
|
+
## Performance
|
|
292
|
+
|
|
293
|
+
- **Bundle size**: ~10MB (includes ONNX model for on-device mode)
|
|
294
|
+
- **On-device inference latency**: <10ms P95
|
|
295
|
+
- **Server-side inference latency**: <100ms P95
|
|
296
|
+
- **Memory overhead**: <50MB
|
|
297
|
+
- **Battery impact**: Negligible (<1%)
|
|
298
|
+
|
|
299
|
+
## Browser Support
|
|
300
|
+
|
|
301
|
+
- Chrome/Edge 90+
|
|
302
|
+
- Safari 14+
|
|
303
|
+
- Firefox 88+
|
|
304
|
+
- React Native 0.70+
|
|
305
|
+
|
|
306
|
+
## License
|
|
307
|
+
|
|
308
|
+
MIT
|
|
309
|
+
|
|
310
|
+
## Documentation
|
|
311
|
+
|
|
312
|
+
Full documentation: https://docs.athena.ai/tracker
|
|
313
|
+
|
|
314
|
+
## Support
|
|
315
|
+
|
|
316
|
+
- Issues: https://github.com/RubaiyatF/Pascal/issues
|
|
317
|
+
- Email: support@pascal.cx
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native Event Capture
|
|
3
|
+
*
|
|
4
|
+
* Captures behavioral events from React Native apps
|
|
5
|
+
* - Touch events (Tap, Swipe, LongPress)
|
|
6
|
+
* - Navigation events (Screen changes)
|
|
7
|
+
* - App lifecycle events (Open, Background, Foreground, Close)
|
|
8
|
+
* - Form interactions
|
|
9
|
+
* - Network errors
|
|
10
|
+
*/
|
|
11
|
+
import { Event } from '../types';
|
|
12
|
+
export interface CaptureConfig {
|
|
13
|
+
captureTouch?: boolean;
|
|
14
|
+
captureNavigation?: boolean;
|
|
15
|
+
captureLifecycle?: boolean;
|
|
16
|
+
captureNetworkErrors?: boolean;
|
|
17
|
+
batchSize?: number;
|
|
18
|
+
batchIntervalMs?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class ReactNativeEventCapture {
|
|
21
|
+
private events;
|
|
22
|
+
private config;
|
|
23
|
+
private appStateSubscription;
|
|
24
|
+
private panResponder;
|
|
25
|
+
private batchTimer;
|
|
26
|
+
private currentScreen;
|
|
27
|
+
private sessionStartTime;
|
|
28
|
+
constructor(config?: CaptureConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Start capturing events
|
|
31
|
+
*/
|
|
32
|
+
start(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Stop capturing events
|
|
35
|
+
*/
|
|
36
|
+
stop(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Setup app lifecycle tracking (Open, Background, Foreground, Close)
|
|
39
|
+
*/
|
|
40
|
+
private setupLifecycleTracking;
|
|
41
|
+
/**
|
|
42
|
+
* Setup touch event tracking
|
|
43
|
+
*/
|
|
44
|
+
private setupTouchTracking;
|
|
45
|
+
/**
|
|
46
|
+
* Setup network error tracking
|
|
47
|
+
*/
|
|
48
|
+
private setupNetworkErrorTracking;
|
|
49
|
+
/**
|
|
50
|
+
* Manually track screen navigation
|
|
51
|
+
* Should be called by navigation library (React Navigation, etc.)
|
|
52
|
+
*/
|
|
53
|
+
trackScreenView(screenName: string, params?: Record<string, any>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Manually track custom event
|
|
56
|
+
*/
|
|
57
|
+
track(eventType: string, properties?: Record<string, any>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Capture an event and add to batch
|
|
60
|
+
*/
|
|
61
|
+
private captureEvent;
|
|
62
|
+
/**
|
|
63
|
+
* Flush accumulated events (to be sent to server)
|
|
64
|
+
*/
|
|
65
|
+
private flushEvents;
|
|
66
|
+
/**
|
|
67
|
+
* Callback for batch events (set by tracker)
|
|
68
|
+
*/
|
|
69
|
+
onEventBatch?: (events: Event[]) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Get PanResponder for manual integration
|
|
72
|
+
* Usage: <View {...capture.getPanResponderProps()}>
|
|
73
|
+
*/
|
|
74
|
+
getPanResponderProps(): any;
|
|
75
|
+
}
|
|
76
|
+
export default ReactNativeEventCapture;
|
|
77
|
+
//# sourceMappingURL=capture-react-native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture-react-native.d.ts","sourceRoot":"","sources":["../../src/events/capture-react-native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,uBAAuB;IAClC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,oBAAoB,CAAa;IACzC,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,gBAAgB,CAAsB;gBAElC,MAAM,GAAE,aAAkB;IAWtC;;OAEG;IACH,KAAK,IAAI,IAAI;IA+Bb;;OAEG;IACH,IAAI,IAAI,IAAI;IAeZ;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA+B9B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiE1B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA2CjC;;;OAGG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAcvE;;OAEG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAWhE;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB;;OAEG;IACH,OAAO,CAAC,WAAW;IAUnB;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC;IAEzC;;;OAGG;IACH,oBAAoB,IAAI,GAAG;CAG5B;AAED,eAAe,uBAAuB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athena/tracker
|
|
3
|
+
*
|
|
4
|
+
* Behavioral analytics tracker with edge AI
|
|
5
|
+
*/
|
|
6
|
+
export { AthenaTracker as default } from './tracker';
|
|
7
|
+
export { AthenaTracker } from './tracker';
|
|
8
|
+
export * from './types';
|
|
9
|
+
export { detectInferenceMode, getPlatform, isReactNative, isBrowser } from './inference/auto-detect';
|
|
10
|
+
export { AthenaOTAWrapper } from './react-native/ForcedReloadWrapper';
|
|
11
|
+
export { ReactNativeEventCapture } from './events/capture-react-native';
|
|
12
|
+
export declare const VERSION = "1.0.0";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1C,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGrG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAGxE,eAAO,MAAM,OAAO,UAAU,CAAC"}
|