react-native-inapp-inspector 2.2.4 → 2.2.6

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.
Files changed (43) hide show
  1. package/README.md +0 -10
  2. package/dist/commonjs/components/BrandSquareIcon.js +51 -117
  3. package/dist/commonjs/components/Inspector/InspectorHeader.js +0 -73
  4. package/dist/commonjs/components/Inspector/MainScreen.js +0 -4
  5. package/dist/commonjs/components/Inspector/SettingsPanel.js +2 -107
  6. package/dist/commonjs/constants/version.d.ts +1 -1
  7. package/dist/commonjs/constants/version.js +1 -1
  8. package/dist/commonjs/helpers/index.d.ts +0 -1
  9. package/dist/commonjs/helpers/index.js +0 -1
  10. package/dist/commonjs/index.d.ts +1 -1
  11. package/dist/commonjs/index.js +2 -19
  12. package/dist/commonjs/native/NativeInspector.js +50 -26
  13. package/dist/esm/components/BrandSquareIcon.js +52 -118
  14. package/dist/esm/components/Inspector/InspectorHeader.js +0 -73
  15. package/dist/esm/components/Inspector/MainScreen.js +0 -4
  16. package/dist/esm/components/Inspector/SettingsPanel.js +2 -107
  17. package/dist/esm/constants/version.d.ts +1 -1
  18. package/dist/esm/constants/version.js +1 -1
  19. package/dist/esm/helpers/index.d.ts +0 -1
  20. package/dist/esm/helpers/index.js +0 -1
  21. package/dist/esm/index.d.ts +1 -1
  22. package/dist/esm/index.js +2 -12
  23. package/dist/esm/native/NativeInspector.js +51 -27
  24. package/ios/NetworkInspectorModule.mm +34 -19
  25. package/package.json +2 -2
  26. package/src/components/BrandSquareIcon.tsx +109 -118
  27. package/src/components/Inspector/InspectorHeader.tsx +0 -93
  28. package/src/components/Inspector/MainScreen.tsx +0 -4
  29. package/src/components/Inspector/SettingsPanel.tsx +2 -128
  30. package/src/constants/version.ts +1 -1
  31. package/src/helpers/index.ts +0 -1
  32. package/src/index.tsx +2 -24
  33. package/src/native/NativeInspector.ts +56 -24
  34. package/dist/commonjs/components/Inspector/TelemetryConsentModal.d.ts +0 -3
  35. package/dist/commonjs/components/Inspector/TelemetryConsentModal.js +0 -368
  36. package/dist/commonjs/helpers/telemetry.d.ts +0 -99
  37. package/dist/commonjs/helpers/telemetry.js +0 -398
  38. package/dist/esm/components/Inspector/TelemetryConsentModal.d.ts +0 -3
  39. package/dist/esm/components/Inspector/TelemetryConsentModal.js +0 -331
  40. package/dist/esm/helpers/telemetry.d.ts +0 -99
  41. package/dist/esm/helpers/telemetry.js +0 -380
  42. package/src/components/Inspector/TelemetryConsentModal.tsx +0 -416
  43. package/src/helpers/telemetry.ts +0 -505
@@ -1,380 +0,0 @@
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-3QGMQVZX5V';
17
- export const GA4_API_SECRET = 'C46RQZ3PTfmHDnLnvU3KIg';
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-3QGMQVZX5V' ||
240
- !GA4_API_SECRET ||
241
- GA4_API_SECRET === 'C46RQZ3PTfmHDnLnvU3KIg') {
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
- }