react-native-inapp-inspector 2.0.1 → 2.0.3
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 +10 -0
- package/android/src/main/java/com/inappinspector/NetworkInspectorModule.kt +23 -0
- package/dist/commonjs/components/AppHeaderLogo.js +21 -2
- package/dist/commonjs/components/Inspector/InspectorHeader.js +84 -11
- package/dist/commonjs/components/Inspector/MainScreen.js +8 -0
- package/dist/commonjs/components/Inspector/NpmUpdateToast.d.ts +3 -0
- package/dist/commonjs/components/Inspector/NpmUpdateToast.js +288 -0
- package/dist/commonjs/components/Inspector/SettingsPanel.js +192 -1
- package/dist/commonjs/components/Inspector/TelemetryConsentModal.d.ts +3 -0
- package/dist/commonjs/components/Inspector/TelemetryConsentModal.js +359 -0
- package/dist/commonjs/constants/version.d.ts +1 -1
- package/dist/commonjs/constants/version.js +1 -1
- package/dist/commonjs/helpers/index.d.ts +1 -0
- package/dist/commonjs/helpers/index.js +1 -0
- package/dist/commonjs/helpers/telemetry.d.ts +99 -0
- package/dist/commonjs/helpers/telemetry.js +398 -0
- package/dist/commonjs/index.d.ts +2 -0
- package/dist/commonjs/index.js +37 -3
- package/dist/commonjs/native/NativeInspector.d.ts +5 -0
- package/dist/commonjs/native/NativeInspector.js +3 -2
- package/dist/commonjs/types/interfaces.d.ts +5 -0
- package/dist/esm/components/AppHeaderLogo.js +21 -2
- package/dist/esm/components/Inspector/InspectorHeader.js +85 -12
- package/dist/esm/components/Inspector/MainScreen.js +8 -0
- package/dist/esm/components/Inspector/NpmUpdateToast.d.ts +3 -0
- package/dist/esm/components/Inspector/NpmUpdateToast.js +251 -0
- package/dist/esm/components/Inspector/SettingsPanel.js +192 -1
- package/dist/esm/components/Inspector/TelemetryConsentModal.d.ts +3 -0
- package/dist/esm/components/Inspector/TelemetryConsentModal.js +322 -0
- package/dist/esm/constants/version.d.ts +1 -1
- package/dist/esm/constants/version.js +1 -1
- package/dist/esm/helpers/index.d.ts +1 -0
- package/dist/esm/helpers/index.js +1 -0
- package/dist/esm/helpers/telemetry.d.ts +99 -0
- package/dist/esm/helpers/telemetry.js +380 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +27 -3
- package/dist/esm/native/NativeInspector.d.ts +5 -0
- package/dist/esm/native/NativeInspector.js +3 -2
- package/dist/esm/types/interfaces.d.ts +5 -0
- package/ios/{NetworkInspectorModule.m → NetworkInspectorModule.mm} +175 -119
- package/package.json +2 -2
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// ─── Google Analytics 4 (GA4) Measurement Protocol Telemetry ───────────────
|
|
2
|
+
//
|
|
3
|
+
// Comprehensive, anonymous usage telemetry for react-native-inapp-inspector.
|
|
4
|
+
//
|
|
5
|
+
// - NEVER collects user PII, auth tokens, device names, or network payload bodies.
|
|
6
|
+
// - Zero main-thread blocking; 100% fail-safe fire-and-forget.
|
|
7
|
+
// - Full environment diagnostics (Hermes, New Arch, RN version, screen size, UI mode).
|
|
8
|
+
// - Tracks developer interactions: tab switches, page views, search, exports, retries.
|
|
9
|
+
// - Supports opt-out via `telemetry={false}` or `DO_NOT_TRACK=1`.
|
|
10
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
11
|
+
import { Platform, Dimensions, Appearance } from 'react-native';
|
|
12
|
+
import { LIB_VERSION } from '../constants';
|
|
13
|
+
import { getNativeStorageItem, setNativeStorageItem, isNativeModuleAvailable, getNativeDeviceMetrics, } from '../native/NativeInspector';
|
|
14
|
+
// ─── GA4 Measurement Protocol Configuration ──────────────────────────────────
|
|
15
|
+
// Automatically replaced at build-time from .env by scripts/inject-telemetry.js
|
|
16
|
+
export const GA4_MEASUREMENT_ID = 'G-XXXXXXXXXX';
|
|
17
|
+
export const GA4_API_SECRET = 'YOUR_GA4_API_SECRET';
|
|
18
|
+
const GA4_ENDPOINT = 'https://www.google-analytics.com/mp/collect';
|
|
19
|
+
const CLIENT_ID_KEY = 'telemetry_client_id';
|
|
20
|
+
// Stable session ID created once per JavaScript runtime instance
|
|
21
|
+
const CURRENT_SESSION_ID = String(Math.floor(Date.now() / 1000));
|
|
22
|
+
let hasPingedSession = false;
|
|
23
|
+
let cachedClientId = null;
|
|
24
|
+
let lastModalOpenTimestamp = 0;
|
|
25
|
+
let cachedAppDiagnostics = null;
|
|
26
|
+
/**
|
|
27
|
+
* Generates an anonymous, pseudorandom UUIDv4-like string for client grouping.
|
|
28
|
+
* Contains zero hardware or personal identifiers.
|
|
29
|
+
*/
|
|
30
|
+
function generateAnonymousClientId() {
|
|
31
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
32
|
+
const r = (Math.random() * 16) | 0;
|
|
33
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
34
|
+
return v.toString(16);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves or generates the anonymous client identifier.
|
|
39
|
+
*/
|
|
40
|
+
async function getOrCreateClientId() {
|
|
41
|
+
if (cachedClientId)
|
|
42
|
+
return cachedClientId;
|
|
43
|
+
try {
|
|
44
|
+
const stored = await getNativeStorageItem(CLIENT_ID_KEY);
|
|
45
|
+
if (stored && typeof stored === 'string' && stored.length > 0) {
|
|
46
|
+
cachedClientId = stored;
|
|
47
|
+
return stored;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Fallback to memory
|
|
52
|
+
}
|
|
53
|
+
const newId = generateAnonymousClientId();
|
|
54
|
+
cachedClientId = newId;
|
|
55
|
+
try {
|
|
56
|
+
await setNativeStorageItem(CLIENT_ID_KEY, newId);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Silently ignore storage errors
|
|
60
|
+
}
|
|
61
|
+
return newId;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Asynchronously loads host application and device metadata (strictly non-PII/technical).
|
|
65
|
+
*/
|
|
66
|
+
export async function loadAppDiagnosticsAsync() {
|
|
67
|
+
if (cachedAppDiagnostics)
|
|
68
|
+
return cachedAppDiagnostics;
|
|
69
|
+
try {
|
|
70
|
+
const metrics = await getNativeDeviceMetrics();
|
|
71
|
+
cachedAppDiagnostics = {
|
|
72
|
+
app_name: metrics?.appName ||
|
|
73
|
+
Platform.constants?.appName ||
|
|
74
|
+
'unknown',
|
|
75
|
+
app_version: metrics?.appVersion ||
|
|
76
|
+
Platform.constants?.appVersion ||
|
|
77
|
+
'unknown',
|
|
78
|
+
app_build: metrics?.appBuild || 'unknown',
|
|
79
|
+
app_bundle_id: metrics?.appBundleId || metrics?.appPackageName || 'unknown',
|
|
80
|
+
device_brand: metrics?.deviceBrand ||
|
|
81
|
+
Platform.constants?.Brand ||
|
|
82
|
+
Platform.constants?.systemName ||
|
|
83
|
+
'unknown',
|
|
84
|
+
device_model: metrics?.deviceModel ||
|
|
85
|
+
Platform.constants?.Model ||
|
|
86
|
+
Platform.constants?.interfaceIdiom ||
|
|
87
|
+
'unknown',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
cachedAppDiagnostics = {
|
|
92
|
+
app_name: Platform.constants?.appName || 'unknown',
|
|
93
|
+
app_version: Platform.constants?.appVersion || 'unknown',
|
|
94
|
+
app_build: 'unknown',
|
|
95
|
+
app_bundle_id: 'unknown',
|
|
96
|
+
device_brand: Platform.constants?.Brand || 'unknown',
|
|
97
|
+
device_model: Platform.constants?.Model || 'unknown',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return cachedAppDiagnostics;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Extracts React Native framework version string (e.g. "0.81.4").
|
|
104
|
+
*/
|
|
105
|
+
function getReactNativeVersion() {
|
|
106
|
+
try {
|
|
107
|
+
const constants = Platform.constants;
|
|
108
|
+
if (constants && constants.reactNativeVersion) {
|
|
109
|
+
const { major, minor, patch, prerelease } = constants.reactNativeVersion;
|
|
110
|
+
return `${major}.${minor}.${patch}${prerelease ? `-${prerelease}` : ''}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Fallback
|
|
115
|
+
}
|
|
116
|
+
return 'unknown';
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Collects complete anonymous device, host app & runtime environment diagnostics.
|
|
120
|
+
*/
|
|
121
|
+
function getEnvironmentDiagnostics(extraParams = {}) {
|
|
122
|
+
const isHermes = Boolean(global.HermesInternal);
|
|
123
|
+
const isNewArch = Boolean(global._RN_FABRIC_ENABLED || global.__turboModuleProxy);
|
|
124
|
+
const isNativeLinked = isNativeModuleAvailable();
|
|
125
|
+
const rnVersion = getReactNativeVersion();
|
|
126
|
+
const isExpo = Boolean(global?.expo?.modules?.ExponentConstants ||
|
|
127
|
+
global?.__expo ||
|
|
128
|
+
(typeof process !== 'undefined' &&
|
|
129
|
+
process?.env?.EXPO_PUBLIC_PROJECT_ROOT));
|
|
130
|
+
let screenResolution = 'unknown';
|
|
131
|
+
let fontScale = 1;
|
|
132
|
+
try {
|
|
133
|
+
const { width, height, scale, fontScale: fs } = Dimensions.get('window');
|
|
134
|
+
screenResolution = `${Math.round(width)}x${Math.round(height)}@${scale}x`;
|
|
135
|
+
fontScale = fs || 1;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Ignore dimension errors
|
|
139
|
+
}
|
|
140
|
+
let colorScheme = 'unknown';
|
|
141
|
+
try {
|
|
142
|
+
colorScheme = Appearance.getColorScheme() || 'unspecified';
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// Ignore appearance errors
|
|
146
|
+
}
|
|
147
|
+
const appMeta = cachedAppDiagnostics || {
|
|
148
|
+
app_name: Platform.constants?.appName || 'unknown',
|
|
149
|
+
app_version: Platform.constants?.appVersion || 'unknown',
|
|
150
|
+
app_build: 'unknown',
|
|
151
|
+
app_bundle_id: 'unknown',
|
|
152
|
+
device_brand: Platform.constants?.Brand ||
|
|
153
|
+
Platform.constants?.systemName ||
|
|
154
|
+
'unknown',
|
|
155
|
+
device_model: Platform.constants?.Model ||
|
|
156
|
+
Platform.constants?.interfaceIdiom ||
|
|
157
|
+
'unknown',
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
session_id: CURRENT_SESSION_ID,
|
|
161
|
+
engagement_time_msec: 100,
|
|
162
|
+
lib_version: LIB_VERSION,
|
|
163
|
+
platform: Platform.OS,
|
|
164
|
+
os_version: String(Platform.Version),
|
|
165
|
+
rn_version: rnVersion,
|
|
166
|
+
is_hermes: isHermes,
|
|
167
|
+
is_new_arch: isNewArch,
|
|
168
|
+
is_native_linked: isNativeLinked,
|
|
169
|
+
is_expo: isExpo,
|
|
170
|
+
is_dev: Boolean(typeof __DEV__ !== 'undefined' && __DEV__),
|
|
171
|
+
screen_resolution: screenResolution,
|
|
172
|
+
font_scale: fontScale,
|
|
173
|
+
color_scheme: colorScheme,
|
|
174
|
+
...appMeta,
|
|
175
|
+
...extraParams,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const CONSENT_STORAGE_KEY = 'telemetry_consent_status';
|
|
179
|
+
let cachedConsentStatus = null;
|
|
180
|
+
/**
|
|
181
|
+
* Returns the developer's telemetry consent status.
|
|
182
|
+
*/
|
|
183
|
+
export async function getTelemetryConsentStatus() {
|
|
184
|
+
if (cachedConsentStatus)
|
|
185
|
+
return cachedConsentStatus;
|
|
186
|
+
try {
|
|
187
|
+
const stored = await getNativeStorageItem(CONSENT_STORAGE_KEY);
|
|
188
|
+
if (stored === 'granted' || stored === 'declined') {
|
|
189
|
+
cachedConsentStatus = stored;
|
|
190
|
+
return stored;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
// Fallback
|
|
195
|
+
}
|
|
196
|
+
return 'undetermined';
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Saves the developer's telemetry consent choice.
|
|
200
|
+
*/
|
|
201
|
+
export async function setTelemetryConsent(granted) {
|
|
202
|
+
const status = granted ? 'granted' : 'declined';
|
|
203
|
+
cachedConsentStatus = status;
|
|
204
|
+
try {
|
|
205
|
+
await setNativeStorageItem(CONSENT_STORAGE_KEY, status);
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// Ignore storage errors
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Checks if the user or environment has opted out of telemetry.
|
|
213
|
+
*/
|
|
214
|
+
export function isTelemetryOptedOut(explicitSetting) {
|
|
215
|
+
if (explicitSetting === false)
|
|
216
|
+
return true;
|
|
217
|
+
if (cachedConsentStatus === 'declined')
|
|
218
|
+
return true;
|
|
219
|
+
try {
|
|
220
|
+
if (typeof process !== 'undefined' &&
|
|
221
|
+
process?.env &&
|
|
222
|
+
(process.env.DO_NOT_TRACK === '1' || process.env.DISABLE_TELEMETRY === '1')) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
// Ignore environments where process is undefined or restricted
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Track an anonymous event via GA4 Measurement Protocol.
|
|
233
|
+
*/
|
|
234
|
+
export async function trackTelemetryEvent(eventName, params = {}, options) {
|
|
235
|
+
if (isTelemetryOptedOut(options?.telemetry))
|
|
236
|
+
return;
|
|
237
|
+
// Don't send if credentials haven't been configured yet
|
|
238
|
+
if (!GA4_MEASUREMENT_ID ||
|
|
239
|
+
GA4_MEASUREMENT_ID === 'G-XXXXXXXXXX' ||
|
|
240
|
+
!GA4_API_SECRET ||
|
|
241
|
+
GA4_API_SECRET === 'YOUR_GA4_API_SECRET') {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
const clientId = await getOrCreateClientId();
|
|
246
|
+
await loadAppDiagnosticsAsync();
|
|
247
|
+
const eventParams = getEnvironmentDiagnostics(params);
|
|
248
|
+
const payload = {
|
|
249
|
+
client_id: clientId,
|
|
250
|
+
events: [
|
|
251
|
+
{
|
|
252
|
+
name: eventName,
|
|
253
|
+
params: eventParams,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
};
|
|
257
|
+
const url = `${GA4_ENDPOINT}?measurement_id=${encodeURIComponent(GA4_MEASUREMENT_ID)}&api_secret=${encodeURIComponent(GA4_API_SECRET)}`;
|
|
258
|
+
fetch(url, {
|
|
259
|
+
method: 'POST',
|
|
260
|
+
headers: {
|
|
261
|
+
'Content-Type': 'application/json',
|
|
262
|
+
},
|
|
263
|
+
body: JSON.stringify(payload),
|
|
264
|
+
}).catch(() => {
|
|
265
|
+
// If offline on initial cold start, allow a single delayed retry
|
|
266
|
+
if (eventName === 'inspector_session_init') {
|
|
267
|
+
hasPingedSession = false;
|
|
268
|
+
setTimeout(() => {
|
|
269
|
+
sendSessionTelemetryPing(options);
|
|
270
|
+
}, 8000);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
// Fail silently
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 1. Session initialization heartbeat ping.
|
|
280
|
+
*/
|
|
281
|
+
export async function sendSessionTelemetryPing(options) {
|
|
282
|
+
if (hasPingedSession && !options?.force)
|
|
283
|
+
return;
|
|
284
|
+
if (isTelemetryOptedOut(options?.telemetry))
|
|
285
|
+
return;
|
|
286
|
+
hasPingedSession = true;
|
|
287
|
+
await trackTelemetryEvent('inspector_session_init', {
|
|
288
|
+
environment: options?.environment || 'unknown',
|
|
289
|
+
has_navigation: Boolean(options?.hasNavigation),
|
|
290
|
+
has_app_icon: Boolean(options?.hasAppIcon),
|
|
291
|
+
}, options);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 2. Track when the inspector modal is opened.
|
|
295
|
+
*/
|
|
296
|
+
export function trackInspectorOpen(options) {
|
|
297
|
+
lastModalOpenTimestamp = Date.now();
|
|
298
|
+
trackTelemetryEvent('inspector_open', {
|
|
299
|
+
open_source: options?.openSource || 'fab',
|
|
300
|
+
active_tab: options?.activeTab || 'apis',
|
|
301
|
+
}, options);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* 3. Track when the inspector modal is closed.
|
|
305
|
+
*/
|
|
306
|
+
export function trackInspectorClose(options) {
|
|
307
|
+
const durationSec = lastModalOpenTimestamp > 0
|
|
308
|
+
? Math.round((Date.now() - lastModalOpenTimestamp) / 1000)
|
|
309
|
+
: 0;
|
|
310
|
+
trackTelemetryEvent('inspector_close', {
|
|
311
|
+
open_duration_seconds: durationSec,
|
|
312
|
+
}, options);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 4. Track tab / page view navigation inside the inspector.
|
|
316
|
+
*/
|
|
317
|
+
export function trackTabSwitch(tabName, options) {
|
|
318
|
+
trackTelemetryEvent('page_view', {
|
|
319
|
+
page_title: `Tab: ${tabName}`,
|
|
320
|
+
page_location: `inapp-inspector://tab/${tabName}`,
|
|
321
|
+
tab_name: tabName,
|
|
322
|
+
from_tab: options?.fromTab || 'unknown',
|
|
323
|
+
}, options);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* 5. Track network API interaction (inspect details, copy cURL, retry).
|
|
327
|
+
*/
|
|
328
|
+
export function trackNetworkInteraction(action, options) {
|
|
329
|
+
trackTelemetryEvent('network_interaction', {
|
|
330
|
+
action_type: action,
|
|
331
|
+
http_method: options?.method || 'GET',
|
|
332
|
+
status_code: options?.statusCode || 0,
|
|
333
|
+
duration_ms: options?.durationMs || 0,
|
|
334
|
+
}, options);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* 6. Track Redux / State management interaction.
|
|
338
|
+
*/
|
|
339
|
+
export function trackReduxInteraction(action, options) {
|
|
340
|
+
trackTelemetryEvent('redux_interaction', {
|
|
341
|
+
action_type: action,
|
|
342
|
+
reducer_name: options?.reducerName || 'root',
|
|
343
|
+
}, options);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* 7. Track Crash & Exception interaction.
|
|
347
|
+
*/
|
|
348
|
+
export function trackCrashInteraction(action, options) {
|
|
349
|
+
trackTelemetryEvent('crash_interaction', {
|
|
350
|
+
action_type: action,
|
|
351
|
+
crash_type: options?.crashType || 'js_exception',
|
|
352
|
+
}, options);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* 8. Track Performance monitoring tab interaction.
|
|
356
|
+
*/
|
|
357
|
+
export function trackPerformanceInteraction(subTab, options) {
|
|
358
|
+
trackTelemetryEvent('performance_interaction', {
|
|
359
|
+
sub_tab: subTab,
|
|
360
|
+
}, options);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* 9. Track search queries and filter applications.
|
|
364
|
+
*/
|
|
365
|
+
export function trackSearchOrFilter(target, actionType, options) {
|
|
366
|
+
trackTelemetryEvent('search_and_filter', {
|
|
367
|
+
target_tab: target,
|
|
368
|
+
action_type: actionType,
|
|
369
|
+
filter_value: options?.filterValue || 'all',
|
|
370
|
+
}, options);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* 10. Track when logs / reports are exported or shared.
|
|
374
|
+
*/
|
|
375
|
+
export function trackLogExport(exportType, options) {
|
|
376
|
+
trackTelemetryEvent('log_export', {
|
|
377
|
+
export_type: exportType,
|
|
378
|
+
item_count: options?.count || 1,
|
|
379
|
+
}, options);
|
|
380
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -13,4 +13,6 @@ export { getEventCategory, registerGAPlugin, type GAPlugin, } from './helpers/ga
|
|
|
13
13
|
export { usePerformanceTracker, useComponentProfiler, useNavigationProfiler, trackComponentRender, trackNavigationTransition, trackHeavyTask, measureAsync, getHermesMemoryStats, registerComponentProfile, subscribeRenderProfiles, getRenderProfiles, logPerformanceEvent, clearPerformanceEvents, subscribePerformanceEvents, getPerformanceEvents, getInitialRenderProfiles, getInitialPerformanceEvents, generateFixSnippet, } from './customHooks/performanceTracker';
|
|
14
14
|
export { InspectLog, InspectTrackTime, InspectCatch, type InspectLogOptions, } from './decorators';
|
|
15
15
|
export { getNativeDeviceMetrics, enableNativeCrashProtection, subscribeNativeCrashes, showNativeFloatingButton, hideNativeFloatingButton, setNativeFloatingButtonBadge, subscribeNativeFloatingButtonPress, subscribeNativeDeviceShake, startNativeFpsMonitoring, stopNativeFpsMonitoring, getNativeFpsMetrics, getNativeStorageItem, setNativeStorageItem, isNativeModuleAvailable, type NativeDeviceMetrics, type NativeCrashEvent, type FloatingButtonOptions, type NativeFpsMetrics, } from './native/NativeInspector';
|
|
16
|
+
export { sendSessionTelemetryPing, trackTelemetryEvent, trackInspectorOpen, trackTabSwitch, trackLogExport, GA4_MEASUREMENT_ID, GA4_API_SECRET, } from './helpers';
|
|
17
|
+
export { BrandSquareIcon, BrandCircleIcon, } from './components/NetworkIcons';
|
|
16
18
|
export { ActiveTab, Method, StatusFilter, SortOrder, LocalFilter, ModalAnimationType, SettingsPage, SettingsSubTab, LogFilter, ConsoleLogType, AnalyticsEventSource, GAEventCategory, StackFrameType, DiffResultType, BundleSubTab, PerformanceSubTab, CrashType, CrashExportFormat, CrashDetailSubTab, CrashFilterType, BreadcrumbType, } from './types';
|
package/dist/esm/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import ErrorBoundary from './components/ErrorBoundary';
|
|
|
8
8
|
import MainScreen from './components/Inspector/MainScreen';
|
|
9
9
|
import { InspectorContext, animateNextLayout, } from './components/Inspector/InspectorContext';
|
|
10
10
|
// Helpers
|
|
11
|
-
import { formatDisplayUrl, getNavigationInfo, deduplicateLogs, getDomainColor, getEventCategory, matchNetworkLogQuery, } from './helpers';
|
|
11
|
+
import { formatDisplayUrl, getNavigationInfo, deduplicateLogs, getDomainColor, getEventCategory, matchNetworkLogQuery, sendSessionTelemetryPing, trackInspectorOpen, } from './helpers';
|
|
12
12
|
// #5 — settings persistence
|
|
13
13
|
import { loadSettings, saveSettings, setCustomStorage, clearPersistedSettings, calculateRamBasedLimits, } from './helpers/settingsStore';
|
|
14
14
|
import { getNativeSystemMetrics, pushNativeLogRecord, fetchNativeCachedPage, } from './native/NativeInspector';
|
|
@@ -27,7 +27,7 @@ import { showNativeFloatingButton, hideNativeFloatingButton, setNativeFloatingBu
|
|
|
27
27
|
import { LIB_VERSION } from './constants';
|
|
28
28
|
// Stylesheet
|
|
29
29
|
import { toggleGlobalTheme } from './styles';
|
|
30
|
-
const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigationRef, appIcon, environment, }) => {
|
|
30
|
+
const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigationRef, appIcon, environment, initialVisible, visible: controlledVisible, }) => {
|
|
31
31
|
// Set custom storage synchronously during render phase
|
|
32
32
|
setCustomStorage(storage || null);
|
|
33
33
|
const [isDark, setIsDark] = useState(false);
|
|
@@ -39,7 +39,12 @@ const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigatio
|
|
|
39
39
|
const [modalHeightPercent, setModalHeightPercent] = useState(90);
|
|
40
40
|
const [modalAnimationType, setModalAnimationType] = useState('slide');
|
|
41
41
|
const [logs, setLogs] = useState([]);
|
|
42
|
-
const [visible, setVisible] = useState(false);
|
|
42
|
+
const [visible, setVisible] = useState(initialVisible ?? controlledVisible ?? false);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (controlledVisible !== undefined) {
|
|
45
|
+
setVisible(controlledVisible);
|
|
46
|
+
}
|
|
47
|
+
}, [controlledVisible]);
|
|
43
48
|
const [isReady, setIsReady] = useState(false);
|
|
44
49
|
const [selected, setSelected] = useState(null);
|
|
45
50
|
const [selectedLogs, setSelectedLogs] = useState(new Set());
|
|
@@ -184,6 +189,7 @@ const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigatio
|
|
|
184
189
|
// #6 — tab the inspector opens on. Shown with a DEFAULT badge in Settings.
|
|
185
190
|
const [defaultTab, setDefaultTab] = useState('apis');
|
|
186
191
|
const [showDuplicateLogs, setShowDuplicateLogs] = useState(false);
|
|
192
|
+
const [showUpdateToast, setShowUpdateToast] = useState(true);
|
|
187
193
|
// Synchronize runtime background listeners with active settings
|
|
188
194
|
useEffect(() => {
|
|
189
195
|
setNetworkModuleEnabled(!!tabVisibility.apis);
|
|
@@ -243,6 +249,7 @@ const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigatio
|
|
|
243
249
|
setReduxAutoRefreshState(true);
|
|
244
250
|
setReduxExpandDepth(1);
|
|
245
251
|
setShowDuplicateLogs(false);
|
|
252
|
+
setShowUpdateToast(true);
|
|
246
253
|
Alert.alert('Settings Reset', 'All settings have been reset to default values.');
|
|
247
254
|
};
|
|
248
255
|
// #5 — hydrate persisted settings once, then auto-save on any change.
|
|
@@ -286,6 +293,8 @@ const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigatio
|
|
|
286
293
|
setReduxExpandDepth(saved.reduxExpandDepth);
|
|
287
294
|
if (saved.showDuplicateLogs != null)
|
|
288
295
|
setShowDuplicateLogs(saved.showDuplicateLogs);
|
|
296
|
+
if (saved.showUpdateToast != null)
|
|
297
|
+
setShowUpdateToast(saved.showUpdateToast);
|
|
289
298
|
if (saved.defaultTab) {
|
|
290
299
|
const dt = saved.defaultTab;
|
|
291
300
|
const vis = {
|
|
@@ -327,6 +336,7 @@ const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigatio
|
|
|
327
336
|
reduxAutoRefresh,
|
|
328
337
|
reduxExpandDepth,
|
|
329
338
|
showDuplicateLogs,
|
|
339
|
+
showUpdateToast,
|
|
330
340
|
});
|
|
331
341
|
}, [
|
|
332
342
|
isDark,
|
|
@@ -699,6 +709,14 @@ const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigatio
|
|
|
699
709
|
}, [unreadPulseAnim]);
|
|
700
710
|
const isNativeModule = useMemo(() => isNativeModuleAvailable(), []);
|
|
701
711
|
const useNativeFab = (Platform.OS === 'ios' || Platform.OS === 'android') && isNativeModule;
|
|
712
|
+
// Send anonymous initialization heartbeat to GA4 Measurement Protocol
|
|
713
|
+
useEffect(() => {
|
|
714
|
+
sendSessionTelemetryPing({
|
|
715
|
+
environment,
|
|
716
|
+
hasNavigation: Boolean(navigationRef),
|
|
717
|
+
hasAppIcon: Boolean(appIcon),
|
|
718
|
+
});
|
|
719
|
+
}, [environment, navigationRef, appIcon]);
|
|
702
720
|
// 100% Native Main-Thread Floating Button Lifecycle
|
|
703
721
|
useEffect(() => {
|
|
704
722
|
if (!useNativeFab || !isEnabled || !enabled) {
|
|
@@ -753,6 +771,8 @@ const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigatio
|
|
|
753
771
|
? defaultTab
|
|
754
772
|
: 'apis';
|
|
755
773
|
setActiveTab(target);
|
|
774
|
+
// Track inspector opened event in GA4
|
|
775
|
+
trackInspectorOpen({ activeTab: target });
|
|
756
776
|
// Instant synchronization of data collected while modal was closed
|
|
757
777
|
if (latestNetworkLogsRef.current.length > 0) {
|
|
758
778
|
const deduped = deduplicateLogs(latestNetworkLogsRef.current);
|
|
@@ -1692,6 +1712,8 @@ const NetworkInspector = ({ enabled = true, isEnabled = true, storage, navigatio
|
|
|
1692
1712
|
setIsDark,
|
|
1693
1713
|
showDuplicateLogs,
|
|
1694
1714
|
setShowDuplicateLogs,
|
|
1715
|
+
showUpdateToast,
|
|
1716
|
+
setShowUpdateToast,
|
|
1695
1717
|
showConsoleLevels,
|
|
1696
1718
|
setShowConsoleLevels,
|
|
1697
1719
|
resetToDefaults,
|
|
@@ -1739,4 +1761,6 @@ export { getEventCategory, registerGAPlugin, } from './helpers/gaAnalyticsRegist
|
|
|
1739
1761
|
export { usePerformanceTracker, useComponentProfiler, useNavigationProfiler, trackComponentRender, trackNavigationTransition, trackHeavyTask, measureAsync, getHermesMemoryStats, registerComponentProfile, subscribeRenderProfiles, getRenderProfiles, logPerformanceEvent, clearPerformanceEvents, subscribePerformanceEvents, getPerformanceEvents, getInitialRenderProfiles, getInitialPerformanceEvents, generateFixSnippet, } from './customHooks/performanceTracker';
|
|
1740
1762
|
export { InspectLog, InspectTrackTime, InspectCatch, } from './decorators';
|
|
1741
1763
|
export { getNativeDeviceMetrics, enableNativeCrashProtection, subscribeNativeCrashes, showNativeFloatingButton, hideNativeFloatingButton, setNativeFloatingButtonBadge, subscribeNativeFloatingButtonPress, subscribeNativeDeviceShake, startNativeFpsMonitoring, stopNativeFpsMonitoring, getNativeFpsMetrics, getNativeStorageItem, setNativeStorageItem, isNativeModuleAvailable, } from './native/NativeInspector';
|
|
1764
|
+
export { sendSessionTelemetryPing, trackTelemetryEvent, trackInspectorOpen, trackTabSwitch, trackLogExport, GA4_MEASUREMENT_ID, GA4_API_SECRET, } from './helpers';
|
|
1765
|
+
export { BrandSquareIcon, BrandCircleIcon, } from './components/NetworkIcons';
|
|
1742
1766
|
export { ActiveTab, Method, StatusFilter, SortOrder, LocalFilter, ModalAnimationType, SettingsPage, SettingsSubTab, LogFilter, ConsoleLogType, AnalyticsEventSource, GAEventCategory, StackFrameType, DiffResultType, BundleSubTab, PerformanceSubTab, CrashType, CrashExportFormat, CrashDetailSubTab, CrashFilterType, BreadcrumbType, } from './types';
|
|
@@ -17,6 +17,11 @@ export interface NativeDeviceMetrics {
|
|
|
17
17
|
osVersion?: string;
|
|
18
18
|
apiLevel?: number;
|
|
19
19
|
cpuAbi?: string;
|
|
20
|
+
appName?: string;
|
|
21
|
+
appVersion?: string;
|
|
22
|
+
appBuild?: string;
|
|
23
|
+
appBundleId?: string;
|
|
24
|
+
appPackageName?: string;
|
|
20
25
|
}
|
|
21
26
|
export interface NativeCrashEvent {
|
|
22
27
|
platform: 'android' | 'ios';
|
|
@@ -5,8 +5,9 @@ const NativeModule = NativeNetworkInspector || NativeModules.NetworkInspectorMod
|
|
|
5
5
|
export const isNativeModuleAvailable = () => {
|
|
6
6
|
return !!NativeModule;
|
|
7
7
|
};
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const eventTarget = NativeModules.NetworkInspectorModule || NativeNetworkInspector;
|
|
9
|
+
const nativeEmitter = eventTarget
|
|
10
|
+
? new NativeEventEmitter(eventTarget)
|
|
10
11
|
: null;
|
|
11
12
|
/**
|
|
12
13
|
* Retrieves low-level native hardware and system metrics (RAM, Heap, Disk, Battery, CPU).
|
|
@@ -151,6 +151,7 @@ export interface PersistedSettings {
|
|
|
151
151
|
reduxAutoRefresh?: boolean;
|
|
152
152
|
reduxExpandDepth?: number;
|
|
153
153
|
showDuplicateLogs?: boolean;
|
|
154
|
+
showUpdateToast?: boolean;
|
|
154
155
|
}
|
|
155
156
|
export interface NetworkInspectorProps {
|
|
156
157
|
enabled?: boolean;
|
|
@@ -160,6 +161,8 @@ export interface NetworkInspectorProps {
|
|
|
160
161
|
navigationRef?: any;
|
|
161
162
|
appIcon?: any;
|
|
162
163
|
environment?: 'DEV' | 'UAT' | 'PrePROD' | 'PROD' | 'QA' | 'Staging' | string;
|
|
164
|
+
initialVisible?: boolean;
|
|
165
|
+
visible?: boolean;
|
|
163
166
|
}
|
|
164
167
|
export interface NavigationTrackerProps {
|
|
165
168
|
onStateChange: (state: any) => void;
|
|
@@ -301,6 +304,8 @@ export interface InspectorContextValue {
|
|
|
301
304
|
setIsDark: React.Dispatch<React.SetStateAction<boolean>>;
|
|
302
305
|
showDuplicateLogs: boolean;
|
|
303
306
|
setShowDuplicateLogs: React.Dispatch<React.SetStateAction<boolean>>;
|
|
307
|
+
showUpdateToast: boolean;
|
|
308
|
+
setShowUpdateToast: React.Dispatch<React.SetStateAction<boolean>>;
|
|
304
309
|
showConsoleLevels: {
|
|
305
310
|
info: boolean;
|
|
306
311
|
warn: boolean;
|