react-native-inapp-inspector 2.0.1 → 2.0.2

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 (47) hide show
  1. package/README.md +10 -0
  2. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  3. package/android/.gradle/8.9/checksums/md5-checksums.bin +0 -0
  4. package/android/.gradle/8.9/checksums/sha1-checksums.bin +0 -0
  5. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  6. package/android/.gradle/8.9/executionHistory/executionHistory.lock +0 -0
  7. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  8. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  9. package/android/.gradle/8.9/gc.properties +0 -0
  10. package/android/.gradle/9.2.0/checksums/checksums.lock +0 -0
  11. package/android/.gradle/9.2.0/fileChanges/last-build.bin +0 -0
  12. package/android/.gradle/9.2.0/fileHashes/fileHashes.bin +0 -0
  13. package/android/.gradle/9.2.0/fileHashes/fileHashes.lock +0 -0
  14. package/android/.gradle/9.2.0/gc.properties +0 -0
  15. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  16. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  17. package/android/.gradle/vcs-1/gc.properties +0 -0
  18. package/android/build/reports/problems/problems-report.html +659 -0
  19. package/android/src/main/java/com/inappinspector/NetworkInspectorModule.kt +23 -0
  20. package/dist/commonjs/components/Inspector/MainScreen.js +4 -0
  21. package/dist/commonjs/components/Inspector/TelemetryConsentModal.d.ts +3 -0
  22. package/dist/commonjs/components/Inspector/TelemetryConsentModal.js +212 -0
  23. package/dist/commonjs/constants/version.d.ts +1 -1
  24. package/dist/commonjs/constants/version.js +1 -1
  25. package/dist/commonjs/helpers/index.d.ts +1 -0
  26. package/dist/commonjs/helpers/index.js +1 -0
  27. package/dist/commonjs/helpers/telemetry.d.ts +99 -0
  28. package/dist/commonjs/helpers/telemetry.js +398 -0
  29. package/dist/commonjs/index.d.ts +2 -0
  30. package/dist/commonjs/index.js +23 -1
  31. package/dist/commonjs/native/NativeInspector.d.ts +5 -0
  32. package/dist/commonjs/native/NativeInspector.js +3 -2
  33. package/dist/esm/components/Inspector/MainScreen.js +4 -0
  34. package/dist/esm/components/Inspector/TelemetryConsentModal.d.ts +3 -0
  35. package/dist/esm/components/Inspector/TelemetryConsentModal.js +175 -0
  36. package/dist/esm/constants/version.d.ts +1 -1
  37. package/dist/esm/constants/version.js +1 -1
  38. package/dist/esm/helpers/index.d.ts +1 -0
  39. package/dist/esm/helpers/index.js +1 -0
  40. package/dist/esm/helpers/telemetry.d.ts +99 -0
  41. package/dist/esm/helpers/telemetry.js +380 -0
  42. package/dist/esm/index.d.ts +2 -0
  43. package/dist/esm/index.js +13 -1
  44. package/dist/esm/native/NativeInspector.d.ts +5 -0
  45. package/dist/esm/native/NativeInspector.js +3 -2
  46. package/ios/{NetworkInspectorModule.m → NetworkInspectorModule.mm} +175 -119
  47. package/package.json +2 -2
@@ -0,0 +1,175 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { Modal, View, Text, TouchableOpacity, StyleSheet, Animated, } from 'react-native';
3
+ import { AppColors } from '../../styles/AppColors';
4
+ import { BrandCircleIcon } from '../BrandCircleIcon';
5
+ import { getTelemetryConsentStatus, setTelemetryConsent, sendSessionTelemetryPing, } from '../../helpers/telemetry';
6
+ export const TelemetryConsentModal = () => {
7
+ const [visible, setVisible] = useState(false);
8
+ const fadeAnim = useState(new Animated.Value(0))[0];
9
+ useEffect(() => {
10
+ let isMounted = true;
11
+ getTelemetryConsentStatus().then(status => {
12
+ if (isMounted && status === 'undetermined') {
13
+ setVisible(true);
14
+ Animated.timing(fadeAnim, {
15
+ toValue: 1,
16
+ duration: 300,
17
+ useNativeDriver: true,
18
+ }).start();
19
+ }
20
+ });
21
+ return () => {
22
+ isMounted = false;
23
+ };
24
+ }, [fadeAnim]);
25
+ const handleDecision = async (granted) => {
26
+ Animated.timing(fadeAnim, {
27
+ toValue: 0,
28
+ duration: 200,
29
+ useNativeDriver: true,
30
+ }).start(async () => {
31
+ setVisible(false);
32
+ await setTelemetryConsent(granted);
33
+ if (granted) {
34
+ // Immediately trigger the session initialization ping
35
+ sendSessionTelemetryPing({ force: true });
36
+ }
37
+ });
38
+ };
39
+ if (!visible)
40
+ return null;
41
+ return (<Modal transparent visible={visible} animationType="none" statusBarTranslucent>
42
+ <View style={styles.overlay}>
43
+ <Animated.View style={[styles.card, { opacity: fadeAnim }]}>
44
+ <View style={styles.headerRow}>
45
+ <View style={styles.iconWrapper}>
46
+ <BrandCircleIcon size={40}/>
47
+ </View>
48
+ <View style={styles.titleContainer}>
49
+ <Text style={styles.title}>Help Improve In-App Inspector</Text>
50
+ <Text style={styles.subtitle}>Anonymous Diagnostic Insights</Text>
51
+ </View>
52
+ </View>
53
+
54
+ <Text style={styles.description}>
55
+ To help us continually enhance tooling performance and compatibility,
56
+ would you mind sharing anonymous diagnostics (such as React Native
57
+ version, JavaScript engine, and platform architecture)?
58
+ </Text>
59
+
60
+ <View style={styles.privacyBadge}>
61
+ <Text style={styles.privacyText}>
62
+ 🔒 <Text style={{ fontWeight: '700' }}>Privacy Guaranteed:</Text> We
63
+ only collect non-identifiable environment metrics. No personal
64
+ data, tokens, or network request payloads are ever collected.
65
+ </Text>
66
+ </View>
67
+
68
+ <View style={styles.buttonRow}>
69
+ <TouchableOpacity style={styles.declineButton} onPress={() => handleDecision(false)} activeOpacity={0.7}>
70
+ <Text style={styles.declineText}>Not Now</Text>
71
+ </TouchableOpacity>
72
+
73
+ <TouchableOpacity style={styles.allowButton} onPress={() => handleDecision(true)} activeOpacity={0.8}>
74
+ <Text style={styles.allowText}>Allow & Share</Text>
75
+ </TouchableOpacity>
76
+ </View>
77
+ </Animated.View>
78
+ </View>
79
+ </Modal>);
80
+ };
81
+ const styles = StyleSheet.create({
82
+ overlay: {
83
+ flex: 1,
84
+ backgroundColor: 'rgba(0, 0, 0, 0.65)',
85
+ justifyContent: 'center',
86
+ alignItems: 'center',
87
+ padding: 24,
88
+ zIndex: 999999,
89
+ },
90
+ card: {
91
+ width: '100%',
92
+ maxWidth: 420,
93
+ backgroundColor: '#1E1F29',
94
+ borderRadius: 20,
95
+ padding: 22,
96
+ borderWidth: 1,
97
+ borderColor: 'rgba(255, 255, 255, 0.12)',
98
+ shadowColor: '#000',
99
+ shadowOffset: { width: 0, height: 10 },
100
+ shadowOpacity: 0.5,
101
+ shadowRadius: 20,
102
+ elevation: 24,
103
+ },
104
+ headerRow: {
105
+ flexDirection: 'row',
106
+ alignItems: 'center',
107
+ marginBottom: 14,
108
+ },
109
+ iconWrapper: {
110
+ marginRight: 14,
111
+ },
112
+ titleContainer: {
113
+ flex: 1,
114
+ },
115
+ title: {
116
+ fontSize: 17,
117
+ fontWeight: '700',
118
+ color: '#FFFFFF',
119
+ letterSpacing: -0.2,
120
+ },
121
+ subtitle: {
122
+ fontSize: 12,
123
+ color: AppColors.purple || '#9055FF',
124
+ fontWeight: '600',
125
+ marginTop: 2,
126
+ },
127
+ description: {
128
+ fontSize: 13,
129
+ lineHeight: 19,
130
+ color: 'rgba(255, 255, 255, 0.75)',
131
+ marginBottom: 14,
132
+ },
133
+ privacyBadge: {
134
+ backgroundColor: 'rgba(144, 85, 255, 0.12)',
135
+ borderRadius: 10,
136
+ padding: 10,
137
+ borderWidth: 1,
138
+ borderColor: 'rgba(144, 85, 255, 0.25)',
139
+ marginBottom: 20,
140
+ },
141
+ privacyText: {
142
+ fontSize: 11,
143
+ lineHeight: 16,
144
+ color: '#D8C6FF',
145
+ },
146
+ buttonRow: {
147
+ flexDirection: 'row',
148
+ justifyContent: 'flex-end',
149
+ alignItems: 'center',
150
+ gap: 12,
151
+ },
152
+ declineButton: {
153
+ paddingVertical: 10,
154
+ paddingHorizontal: 16,
155
+ borderRadius: 10,
156
+ backgroundColor: 'rgba(255, 255, 255, 0.08)',
157
+ },
158
+ declineText: {
159
+ fontSize: 13,
160
+ fontWeight: '600',
161
+ color: 'rgba(255, 255, 255, 0.7)',
162
+ },
163
+ allowButton: {
164
+ paddingVertical: 10,
165
+ paddingHorizontal: 20,
166
+ borderRadius: 10,
167
+ backgroundColor: '#7C3AED',
168
+ },
169
+ allowText: {
170
+ fontSize: 13,
171
+ fontWeight: '700',
172
+ color: '#FFFFFF',
173
+ },
174
+ });
175
+ export default TelemetryConsentModal;
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "2.0.1";
1
+ export declare const LIB_VERSION = "2.0.2";
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED FILE — do not edit by hand.
2
2
  // Regenerated from package.json on every build by scripts/gen-version.js.
3
- export const LIB_VERSION = '2.0.1';
3
+ export const LIB_VERSION = '2.0.2';
@@ -1,5 +1,6 @@
1
1
  import { NetworkLog, RouteInfo, DiffResult, JsonContent, StackFrameType } from '../types';
2
2
  export * from './searchQueryParser';
3
+ export * from './telemetry';
3
4
  export declare const getDomainColor: (domain: string) => string;
4
5
  export declare const formatDateTime: (timestamp: number) => string;
5
6
  export declare const formatTimestamp: (timestamp: number) => string;
@@ -6,6 +6,7 @@ import { AppColors } from '../styles/AppColors';
6
6
  // Constants
7
7
  import { DOMAIN_COLORS, DURATION_FAST_MS, DURATION_SLOW_MS } from '../constants';
8
8
  export * from './searchQueryParser';
9
+ export * from './telemetry';
9
10
  export const getDomainColor = (domain) => {
10
11
  if (!domain)
11
12
  return DOMAIN_COLORS[0];
@@ -0,0 +1,99 @@
1
+ export declare const GA4_MEASUREMENT_ID = "G-XXXXXXXXXX";
2
+ export declare const GA4_API_SECRET = "YOUR_GA4_API_SECRET";
3
+ /**
4
+ * Asynchronously loads host application and device metadata (strictly non-PII/technical).
5
+ */
6
+ export declare function loadAppDiagnosticsAsync(): Promise<Record<string, any>>;
7
+ /**
8
+ * Returns the developer's telemetry consent status.
9
+ */
10
+ export declare function getTelemetryConsentStatus(): Promise<'granted' | 'declined' | 'undetermined'>;
11
+ /**
12
+ * Saves the developer's telemetry consent choice.
13
+ */
14
+ export declare function setTelemetryConsent(granted: boolean): Promise<void>;
15
+ /**
16
+ * Checks if the user or environment has opted out of telemetry.
17
+ */
18
+ export declare function isTelemetryOptedOut(explicitSetting?: boolean): boolean;
19
+ /**
20
+ * Track an anonymous event via GA4 Measurement Protocol.
21
+ */
22
+ export declare function trackTelemetryEvent(eventName: string, params?: Record<string, any>, options?: {
23
+ telemetry?: boolean;
24
+ force?: boolean;
25
+ }): Promise<void>;
26
+ /**
27
+ * 1. Session initialization heartbeat ping.
28
+ */
29
+ export declare function sendSessionTelemetryPing(options?: {
30
+ telemetry?: boolean;
31
+ environment?: string;
32
+ hasNavigation?: boolean;
33
+ hasAppIcon?: boolean;
34
+ force?: boolean;
35
+ }): Promise<void>;
36
+ /**
37
+ * 2. Track when the inspector modal is opened.
38
+ */
39
+ export declare function trackInspectorOpen(options?: {
40
+ activeTab?: string;
41
+ openSource?: 'fab' | 'shake' | 'programmatic';
42
+ telemetry?: boolean;
43
+ }): void;
44
+ /**
45
+ * 3. Track when the inspector modal is closed.
46
+ */
47
+ export declare function trackInspectorClose(options?: {
48
+ telemetry?: boolean;
49
+ }): void;
50
+ /**
51
+ * 4. Track tab / page view navigation inside the inspector.
52
+ */
53
+ export declare function trackTabSwitch(tabName: string, options?: {
54
+ telemetry?: boolean;
55
+ fromTab?: string;
56
+ }): void;
57
+ /**
58
+ * 5. Track network API interaction (inspect details, copy cURL, retry).
59
+ */
60
+ export declare function trackNetworkInteraction(action: 'view_detail' | 'copy_curl' | 'retry_request' | 'copy_url' | 'clear_logs' | 'export_har', options?: {
61
+ method?: string;
62
+ statusCode?: number;
63
+ durationMs?: number;
64
+ telemetry?: boolean;
65
+ }): void;
66
+ /**
67
+ * 6. Track Redux / State management interaction.
68
+ */
69
+ export declare function trackReduxInteraction(action: 'view_diff' | 'view_state' | 'view_action' | 'filter_reducer', options?: {
70
+ reducerName?: string;
71
+ telemetry?: boolean;
72
+ }): void;
73
+ /**
74
+ * 7. Track Crash & Exception interaction.
75
+ */
76
+ export declare function trackCrashInteraction(action: 'view_crash_detail' | 'share_crash_report' | 'copy_stacktrace' | 'clear_crashes', options?: {
77
+ crashType?: string;
78
+ telemetry?: boolean;
79
+ }): void;
80
+ /**
81
+ * 8. Track Performance monitoring tab interaction.
82
+ */
83
+ export declare function trackPerformanceInteraction(subTab: 'fps' | 'memory' | 'rerenders' | 'bundles', options?: {
84
+ telemetry?: boolean;
85
+ }): void;
86
+ /**
87
+ * 9. Track search queries and filter applications.
88
+ */
89
+ export declare function trackSearchOrFilter(target: 'apis' | 'console' | 'redux' | 'crashes' | 'analytics', actionType: 'search_query' | 'status_filter' | 'method_filter' | 'tag_filter', options?: {
90
+ filterValue?: string;
91
+ telemetry?: boolean;
92
+ }): void;
93
+ /**
94
+ * 10. Track when logs / reports are exported or shared.
95
+ */
96
+ export declare function trackLogExport(exportType: 'logs_json' | 'logs_har' | 'curl' | 'crash_report', options?: {
97
+ telemetry?: boolean;
98
+ count?: number;
99
+ }): void;
@@ -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-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
+ }
@@ -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';