user-analytics-tracker 1.2.0 → 1.7.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/CHANGELOG.md +35 -0
- package/README.md +65 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
# [1.7.0](https://github.com/switch-org/analytics-tracker/compare/v1.6.0...v1.7.0) (2025-11-24)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* updated build ([4778be5](https://github.com/switch-org/analytics-tracker/commit/4778be5c9f41a034593c02a97c70076c480dd1ed))
|
|
7
|
+
|
|
8
|
+
# [1.6.0](https://github.com/switch-org/analytics-tracker/compare/v1.5.0...v1.6.0) (2025-11-24)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* update permissions ([553d9be](https://github.com/switch-org/analytics-tracker/commit/553d9be405d7609e2cb9853ff16535cf4b1b9e66))
|
|
14
|
+
|
|
15
|
+
# [1.5.0](https://github.com/switch-org/analytics-tracker/compare/v1.4.0...v1.5.0) (2025-11-24)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* updated ([a5d770b](https://github.com/switch-org/analytics-tracker/commit/a5d770b97719707c458601f955a98655c1baa27f))
|
|
21
|
+
|
|
22
|
+
# [1.4.0](https://github.com/switch-org/analytics-tracker/compare/v1.3.1...v1.4.0) (2025-11-24)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* updated doc ([9d606f4](https://github.com/switch-org/analytics-tracker/commit/9d606f4a735dcc7b0aeda30615328b5bda54c4bc))
|
|
28
|
+
|
|
29
|
+
## [1.3.1](https://github.com/switch-org/analytics-tracker/compare/v1.3.0...v1.3.1) (2025-11-24)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Bug Fixes
|
|
33
|
+
|
|
34
|
+
* updated names ([c56f903](https://github.com/switch-org/analytics-tracker/commit/c56f903b9360f2dc2492e5114667dc240cca9e0c))
|
|
35
|
+
|
|
1
36
|
# [1.3.0](https://github.com/switch-org/analytics-tracker/compare/v1.2.0...v1.3.0) (2025-11-24)
|
|
2
37
|
|
|
3
38
|
|
package/README.md
CHANGED
|
@@ -13,13 +13,15 @@ A comprehensive, lightweight analytics tracking library for React applications.
|
|
|
13
13
|
- 🔍 **Device Detection**: Automatically detects device type, OS, browser, model, brand, and hardware specs using User-Agent Client Hints
|
|
14
14
|
- 🌐 **Network Detection**: Identifies WiFi, Cellular, Hotspot, Ethernet connections with quality metrics
|
|
15
15
|
- 📍 **Location Tracking**:
|
|
16
|
-
- **
|
|
17
|
-
- GPS location
|
|
16
|
+
- **IP-based location** - Requires user consent (privacy-compliant)
|
|
17
|
+
- **GPS location** - Requires explicit user consent and browser permission
|
|
18
18
|
- Includes public IP address, country, city, region, timezone
|
|
19
19
|
- Automatic fallback from GPS to IP when GPS unavailable
|
|
20
|
+
- Consent management utilities included
|
|
20
21
|
- 🎯 **Attribution Tracking**: UTM parameters, referrer tracking, first/last touch attribution
|
|
21
22
|
- 📊 **IP Geolocation**: Client-side and server-side IP-based location detection utilities
|
|
22
|
-
- 🔒 **Privacy-First**:
|
|
23
|
+
- 🔒 **Privacy-First**: User consent required for location tracking (GPS & IP), consent management utilities
|
|
24
|
+
- 🎯 **Custom Event Tracking**: Firebase/Google Analytics-style event tracking with automatic context collection
|
|
23
25
|
- ⚡ **Lightweight**: Zero runtime dependencies (except React)
|
|
24
26
|
- 📦 **TypeScript**: Fully typed with comprehensive type definitions
|
|
25
27
|
- 🎨 **Framework Agnostic Core**: Core detectors work without React
|
|
@@ -169,7 +171,14 @@ function App() {
|
|
|
169
171
|
import { useAnalytics } from 'user-analytics-tracker';
|
|
170
172
|
|
|
171
173
|
function MyApp() {
|
|
172
|
-
const {
|
|
174
|
+
const {
|
|
175
|
+
sessionId,
|
|
176
|
+
networkInfo,
|
|
177
|
+
deviceInfo,
|
|
178
|
+
location,
|
|
179
|
+
trackEvent,
|
|
180
|
+
trackPageView
|
|
181
|
+
} = useAnalytics({
|
|
173
182
|
autoSend: true,
|
|
174
183
|
config: {
|
|
175
184
|
// Use your own backend server (full URL)
|
|
@@ -179,11 +188,24 @@ function MyApp() {
|
|
|
179
188
|
},
|
|
180
189
|
});
|
|
181
190
|
|
|
191
|
+
// Track page view on mount
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
trackPageView();
|
|
194
|
+
}, [trackPageView]);
|
|
195
|
+
|
|
196
|
+
const handleButtonClick = async () => {
|
|
197
|
+
// Track custom event (Firebase/GA-style)
|
|
198
|
+
await trackEvent('button_click', {
|
|
199
|
+
button_name: 'signup',
|
|
200
|
+
button_location: 'header'
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
|
|
182
204
|
return (
|
|
183
205
|
<div>
|
|
184
206
|
<p>Device: {deviceInfo?.deviceBrand} {deviceInfo?.deviceModel}</p>
|
|
185
207
|
<p>Network: {networkInfo?.type}</p>
|
|
186
|
-
<button onClick={
|
|
208
|
+
<button onClick={handleButtonClick}>
|
|
187
209
|
Track Click
|
|
188
210
|
</button>
|
|
189
211
|
</div>
|
|
@@ -264,6 +286,8 @@ interface UseAnalyticsReturn {
|
|
|
264
286
|
pageVisits: number;
|
|
265
287
|
interactions: number;
|
|
266
288
|
logEvent: (customData?: Record<string, any>) => Promise<void>;
|
|
289
|
+
trackEvent: (eventName: string, parameters?: Record<string, any>) => Promise<void>;
|
|
290
|
+
trackPageView: (pageName?: string, parameters?: Record<string, any>) => Promise<void>;
|
|
267
291
|
incrementInteraction: () => void;
|
|
268
292
|
refresh: () => Promise<{
|
|
269
293
|
net: NetworkInfo;
|
|
@@ -527,12 +551,46 @@ class MyAnalyticsService extends AnalyticsService {
|
|
|
527
551
|
}
|
|
528
552
|
```
|
|
529
553
|
|
|
530
|
-
###
|
|
554
|
+
### Custom Event Tracking (Firebase/GA-style)
|
|
555
|
+
|
|
556
|
+
Track custom events with automatic context collection:
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
const { trackEvent, trackPageView } = useAnalytics();
|
|
560
|
+
|
|
561
|
+
// Track button click
|
|
562
|
+
await trackEvent('button_click', {
|
|
563
|
+
button_name: 'signup',
|
|
564
|
+
button_location: 'header',
|
|
565
|
+
button_color: 'blue'
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
// Track purchase
|
|
569
|
+
await trackEvent('purchase', {
|
|
570
|
+
transaction_id: 'T12345',
|
|
571
|
+
value: 29.99,
|
|
572
|
+
currency: 'USD',
|
|
573
|
+
items: [
|
|
574
|
+
{ id: 'item1', name: 'Product 1', price: 29.99 }
|
|
575
|
+
]
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// Track page views
|
|
579
|
+
await trackPageView('/dashboard', {
|
|
580
|
+
page_title: 'Dashboard',
|
|
581
|
+
user_type: 'premium'
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
// Track current page view
|
|
585
|
+
await trackPageView();
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### Manual Event Tracking (Legacy)
|
|
531
589
|
|
|
532
590
|
```typescript
|
|
533
591
|
const { logEvent, incrementInteraction } = useAnalytics();
|
|
534
592
|
|
|
535
|
-
// Log custom event
|
|
593
|
+
// Log custom event with full control
|
|
536
594
|
await logEvent({
|
|
537
595
|
eventType: 'purchase',
|
|
538
596
|
productId: '123',
|
package/package.json
CHANGED