@lavarage/telemetry 1.0.0 → 1.1.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 +21 -6
- package/dist/index.d.ts +6 -1
- package/dist/index.js +91 -10
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -22,7 +22,9 @@ const telemetry = new LavarageTelemetry({
|
|
|
22
22
|
telemetry.interceptFetch();
|
|
23
23
|
|
|
24
24
|
// Connect wallet (triggers login event)
|
|
25
|
-
|
|
25
|
+
// Wallet platform is automatically detected (MetaMask, Phantom, etc.)
|
|
26
|
+
// or you can specify it manually:
|
|
27
|
+
telemetry.setWallet('YourWalletAddress123...', 'MetaMask');
|
|
26
28
|
|
|
27
29
|
// Track trading pair views
|
|
28
30
|
telemetry.trackPairView('SOL/USDC', { source: 'homepage' });
|
|
@@ -206,12 +208,25 @@ All telemetry operations are wrapped in try-catch blocks. Telemetry errors will
|
|
|
206
208
|
|
|
207
209
|
### Methods
|
|
208
210
|
|
|
209
|
-
#### `setWallet(walletAddress: string)`
|
|
211
|
+
#### `setWallet(walletAddress: string, walletPlatform?: string)`
|
|
212
|
+
|
|
213
|
+
Set the current wallet address and trigger a login event. The wallet platform (e.g., 'MetaMask', 'Phantom', 'WalletConnect') is automatically detected from the browser environment, but you can also specify it manually.
|
|
210
214
|
|
|
211
|
-
|
|
215
|
+
**Supported auto-detected platforms:**
|
|
216
|
+
- MetaMask
|
|
217
|
+
- Coinbase Wallet
|
|
218
|
+
- Trust Wallet
|
|
219
|
+
- WalletConnect
|
|
220
|
+
- Phantom (Solana)
|
|
221
|
+
- Solflare (Solana)
|
|
222
|
+
- Generic Ethereum/Solana providers
|
|
212
223
|
|
|
213
224
|
```typescript
|
|
225
|
+
// Auto-detect wallet platform
|
|
214
226
|
telemetry.setWallet('YourWalletAddress123...');
|
|
227
|
+
|
|
228
|
+
// Or specify manually
|
|
229
|
+
telemetry.setWallet('YourWalletAddress123...', 'MetaMask');
|
|
215
230
|
```
|
|
216
231
|
|
|
217
232
|
#### `interceptFetch()`
|
|
@@ -425,12 +440,12 @@ await telemetry.sendLog(
|
|
|
425
440
|
);
|
|
426
441
|
```
|
|
427
442
|
|
|
428
|
-
#### `setWallet(walletAddress: string)`
|
|
443
|
+
#### `setWallet(walletAddress: string, walletPlatform?: string)`
|
|
429
444
|
|
|
430
|
-
Set the default wallet address for subsequent events. This is optional for backend use since you can specify the wallet in each log call.
|
|
445
|
+
Set the default wallet address for subsequent events. This is optional for backend use since you can specify the wallet in each log call. You can also optionally specify the wallet platform.
|
|
431
446
|
|
|
432
447
|
```typescript
|
|
433
|
-
telemetry.setWallet('WalletAddress123...');
|
|
448
|
+
telemetry.setWallet('WalletAddress123...', 'MetaMask');
|
|
434
449
|
// Now all events will use this wallet by default
|
|
435
450
|
telemetry.logWalletEvent(
|
|
436
451
|
null, // Will use the wallet set above
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export declare class LavarageTelemetry {
|
|
|
17
17
|
constructor(config: TelemetryConfig);
|
|
18
18
|
private generateSessionId;
|
|
19
19
|
private generateRequestId;
|
|
20
|
+
/**
|
|
21
|
+
* Detect wallet platform/provider from browser environment
|
|
22
|
+
* Checks for common wallet providers like MetaMask, Phantom, WalletConnect, etc.
|
|
23
|
+
*/
|
|
24
|
+
private detectWalletPlatform;
|
|
20
25
|
private normalizeHostFilter;
|
|
21
26
|
private shouldCaptureHost;
|
|
22
27
|
private matchesHost;
|
|
@@ -29,7 +34,7 @@ export declare class LavarageTelemetry {
|
|
|
29
34
|
private flush;
|
|
30
35
|
private initializeCapture;
|
|
31
36
|
private trackError;
|
|
32
|
-
setWallet(walletAddress: string): void;
|
|
37
|
+
setWallet(walletAddress: string, walletPlatform?: string): void;
|
|
33
38
|
interceptFetch(): void;
|
|
34
39
|
interceptAxios(axiosInstance: any): void;
|
|
35
40
|
trackPairView(pair: string, metadata?: object): void;
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,77 @@ class LavarageTelemetry {
|
|
|
33
33
|
generateRequestId() {
|
|
34
34
|
return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Detect wallet platform/provider from browser environment
|
|
38
|
+
* Checks for common wallet providers like MetaMask, Phantom, WalletConnect, etc.
|
|
39
|
+
*/
|
|
40
|
+
detectWalletPlatform() {
|
|
41
|
+
if (typeof window === 'undefined') {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const win = window;
|
|
46
|
+
// Check for Ethereum wallets
|
|
47
|
+
if (win.ethereum) {
|
|
48
|
+
// MetaMask
|
|
49
|
+
if (win.ethereum.isMetaMask) {
|
|
50
|
+
return 'MetaMask';
|
|
51
|
+
}
|
|
52
|
+
// Coinbase Wallet
|
|
53
|
+
if (win.ethereum.isCoinbaseWallet) {
|
|
54
|
+
return 'Coinbase Wallet';
|
|
55
|
+
}
|
|
56
|
+
// Trust Wallet
|
|
57
|
+
if (win.ethereum.isTrust) {
|
|
58
|
+
return 'Trust Wallet';
|
|
59
|
+
}
|
|
60
|
+
// WalletConnect
|
|
61
|
+
if (win.ethereum.isWalletConnect) {
|
|
62
|
+
return 'WalletConnect';
|
|
63
|
+
}
|
|
64
|
+
// Generic Ethereum provider
|
|
65
|
+
if (win.ethereum.providers && Array.isArray(win.ethereum.providers)) {
|
|
66
|
+
// Multiple providers detected, try to identify
|
|
67
|
+
for (const provider of win.ethereum.providers) {
|
|
68
|
+
if (provider.isMetaMask)
|
|
69
|
+
return 'MetaMask';
|
|
70
|
+
if (provider.isCoinbaseWallet)
|
|
71
|
+
return 'Coinbase Wallet';
|
|
72
|
+
if (provider.isTrust)
|
|
73
|
+
return 'Trust Wallet';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Check provider name/version
|
|
77
|
+
if (win.ethereum.providerName) {
|
|
78
|
+
return win.ethereum.providerName;
|
|
79
|
+
}
|
|
80
|
+
// Default to generic Ethereum
|
|
81
|
+
return 'Ethereum';
|
|
82
|
+
}
|
|
83
|
+
// Check for Solana wallets
|
|
84
|
+
if (win.solana) {
|
|
85
|
+
// Phantom
|
|
86
|
+
if (win.solana.isPhantom) {
|
|
87
|
+
return 'Phantom';
|
|
88
|
+
}
|
|
89
|
+
// Solflare
|
|
90
|
+
if (win.solana.isSolflare) {
|
|
91
|
+
return 'Solflare';
|
|
92
|
+
}
|
|
93
|
+
// Generic Solana
|
|
94
|
+
return 'Solana';
|
|
95
|
+
}
|
|
96
|
+
// Check for other wallet providers
|
|
97
|
+
if (win.web3) {
|
|
98
|
+
return 'Web3';
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
// Silently fail detection
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
36
107
|
normalizeHostFilter(input) {
|
|
37
108
|
if (!input) {
|
|
38
109
|
return { mode: 'all' };
|
|
@@ -211,17 +282,24 @@ class LavarageTelemetry {
|
|
|
211
282
|
if (typeof fetch !== 'undefined') {
|
|
212
283
|
return fetch;
|
|
213
284
|
}
|
|
214
|
-
//
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const nodeFetch = require('node-fetch');
|
|
218
|
-
// Handle both node-fetch v2 (default export) and v3 (named export)
|
|
219
|
-
return (nodeFetch.default || nodeFetch);
|
|
285
|
+
// In browser environments, fetch should always be available
|
|
286
|
+
if (typeof window !== 'undefined') {
|
|
287
|
+
throw new Error('fetch is not available in browser environment');
|
|
220
288
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
289
|
+
// Only try to use node-fetch in Node.js environments (for older Node.js versions)
|
|
290
|
+
// This code will be tree-shaken by bundlers for browser builds
|
|
291
|
+
if (typeof require !== 'undefined') {
|
|
292
|
+
try {
|
|
293
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
294
|
+
const nodeFetch = require('node-fetch');
|
|
295
|
+
// Handle both node-fetch v2 (default export) and v3 (named export)
|
|
296
|
+
return (nodeFetch.default || nodeFetch);
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
// node-fetch not available
|
|
300
|
+
}
|
|
224
301
|
}
|
|
302
|
+
throw new Error('fetch is not available. Please use Node.js 18+ or install node-fetch');
|
|
225
303
|
}
|
|
226
304
|
async flush(useKeepalive = false) {
|
|
227
305
|
if (this.eventQueue.length === 0) {
|
|
@@ -318,9 +396,11 @@ class LavarageTelemetry {
|
|
|
318
396
|
url: typeof window !== 'undefined' ? window.location.href : '',
|
|
319
397
|
});
|
|
320
398
|
}
|
|
321
|
-
setWallet(walletAddress) {
|
|
399
|
+
setWallet(walletAddress, walletPlatform) {
|
|
322
400
|
try {
|
|
323
401
|
this.wallet = walletAddress;
|
|
402
|
+
// Detect wallet platform if not provided
|
|
403
|
+
const detectedPlatform = walletPlatform || this.detectWalletPlatform();
|
|
324
404
|
// Track login event
|
|
325
405
|
this.enqueue({
|
|
326
406
|
type: 'login',
|
|
@@ -329,6 +409,7 @@ class LavarageTelemetry {
|
|
|
329
409
|
timestamp: Date.now(),
|
|
330
410
|
sessionId: this.sessionId,
|
|
331
411
|
userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : '',
|
|
412
|
+
walletPlatform: detectedPlatform || null,
|
|
332
413
|
});
|
|
333
414
|
}
|
|
334
415
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lavarage/telemetry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Production telemetry SDK for Lavarage and partner applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"browser": {
|
|
9
|
+
"./dist/index.js": "./dist/index.js",
|
|
10
|
+
"node-fetch": false
|
|
11
|
+
},
|
|
7
12
|
"scripts": {
|
|
8
13
|
"build": "tsc",
|
|
9
14
|
"dev": "tsc --watch",
|
|
@@ -13,9 +18,6 @@
|
|
|
13
18
|
"keywords": ["telemetry", "analytics", "monitoring", "lavarage"],
|
|
14
19
|
"author": "Lavarage",
|
|
15
20
|
"license": "MIT",
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": ">=18.0.0"
|
|
18
|
-
},
|
|
19
21
|
"peerDependencies": {
|
|
20
22
|
"node-fetch": "^2.6.0 || ^3.0.0"
|
|
21
23
|
},
|