react-native-inapp-inspector 1.1.13 → 1.1.14

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.
@@ -55,9 +55,10 @@ const EVENT_PALETTE = [
55
55
  '#2E7D32', // dark green
56
56
  ];
57
57
  function getEventColor(name) {
58
+ const safeName = typeof name === 'string' ? name : String(name || '');
58
59
  let hash = 0;
59
- for (let i = 0; i < name.length; i++) {
60
- hash = (hash * 31 + name.charCodeAt(i)) | 0;
60
+ for (let i = 0; i < safeName.length; i++) {
61
+ hash = (hash * 31 + safeName.charCodeAt(i)) | 0;
61
62
  }
62
63
  return EVENT_PALETTE[Math.abs(hash) % EVENT_PALETTE.length];
63
64
  }
@@ -80,6 +81,63 @@ function formatGap(ms) {
80
81
  const rem = s % 60;
81
82
  return rem > 0 ? `+${m}m ${rem}s` : `+${m}m`;
82
83
  }
84
+ function getEventCategory(name) {
85
+ if (!name)
86
+ return 'Custom';
87
+ const lowercaseName = name.toLowerCase();
88
+ if (lowercaseName === 'screen_view' || lowercaseName === 'page_view') {
89
+ return 'Page View';
90
+ }
91
+ // Ecommerce events
92
+ const ecommerceEvents = [
93
+ 'purchase', 'add_to_cart', 'begin_checkout', 'view_item',
94
+ 'select_item', 'remove_from_cart', 'view_cart',
95
+ 'add_shipping_info', 'add_payment_info', 'refund',
96
+ 'view_item_list', 'select_promotion', 'view_promotion'
97
+ ];
98
+ if (ecommerceEvents.includes(lowercaseName)) {
99
+ return 'Ecommerce';
100
+ }
101
+ // Firebase System Auto-events
102
+ const systemEvents = [
103
+ 'first_open', 'session_start', 'user_engagement',
104
+ 'app_clear_data', 'app_exception', 'app_update', 'os_update',
105
+ 'notification_receive', 'notification_open', 'notification_dismiss',
106
+ 'screen_active', 'screen_inactive'
107
+ ];
108
+ if (systemEvents.includes(lowercaseName) || lowercaseName.startsWith('firebase_') || lowercaseName.startsWith('_')) {
109
+ return 'System';
110
+ }
111
+ return 'Custom';
112
+ }
113
+ function getCategoryColors(category) {
114
+ switch (category) {
115
+ case 'Page View':
116
+ return {
117
+ bg: '#E3F2FD',
118
+ border: '#BBDEFB',
119
+ text: '#1976D2',
120
+ };
121
+ case 'Ecommerce':
122
+ return {
123
+ bg: '#E8F5E9',
124
+ border: '#C8E6C9',
125
+ text: '#2E7D32',
126
+ };
127
+ case 'System':
128
+ return {
129
+ bg: '#F5F5F5',
130
+ border: '#E0E0E0',
131
+ text: '#616161',
132
+ };
133
+ default:
134
+ return {
135
+ bg: '#F3E5F5',
136
+ border: '#E1BEE7',
137
+ text: '#7B1FA2',
138
+ };
139
+ }
140
+ }
83
141
  // ─── Component ────────────────────────────────────────────────────────────────
84
142
  const AnalyticsEventCard = react_1.default.memo(function AnalyticsEventCard({ event, onPress, isNew = false, searchStr = '', msSincePrev, computedScreenName, }) {
85
143
  const color = getEventColor(event.name);
@@ -128,6 +186,19 @@ const AnalyticsEventCard = react_1.default.memo(function AnalyticsEventCard({ ev
128
186
  <HighlightText_1.default text={event.name} search={searchStr} style={[cardStyles.eventName, { color: color }]} highlightStyle={cardStyles.highlight}/>
129
187
  </react_native_1.View>
130
188
 
189
+ {(() => {
190
+ const category = getEventCategory(event.name);
191
+ const tagColors = getCategoryColors(category);
192
+ return (<react_native_1.View style={[
193
+ cardStyles.categoryBadge,
194
+ { backgroundColor: tagColors.bg, borderColor: tagColors.border },
195
+ ]}>
196
+ <react_native_1.Text style={[cardStyles.categoryText, { color: tagColors.text }]}>
197
+ {category}
198
+ </react_native_1.Text>
199
+ </react_native_1.View>);
200
+ })()}
201
+
131
202
  {event.count !== undefined ? (<react_native_1.View style={[
132
203
  cardStyles.duplicateBadge,
133
204
  event.count === 1 && {
@@ -151,20 +222,24 @@ const AnalyticsEventCard = react_1.default.memo(function AnalyticsEventCard({ ev
151
222
  {/* Bottom Row: Metadata Chips & Sparkline */}
152
223
  <react_native_1.View style={cardStyles.cardBody}>
153
224
  <react_native_1.View style={cardStyles.chipsRow}>
154
- {computedScreenName ||
155
- event.screenName ||
156
- event.params?.firebase_screen ||
157
- event.params?.screen_name ||
158
- event.params?.firebase_screen_class ? (<react_native_1.View style={[cardStyles.chip, { backgroundColor: AppColors_1.AppColors.grayBackground, borderColor: AppColors_1.AppColors.grayBorderSecondary }]}>
159
- <react_native_1.View style={[cardStyles.screenDot, { backgroundColor: color }]}/>
160
- <react_native_1.Text style={[cardStyles.chipText, { color: AppColors_1.AppColors.grayText }]} numberOfLines={1}>
161
- {computedScreenName ||
225
+ {(() => {
226
+ const rawScreenName = computedScreenName ||
162
227
  event.screenName ||
163
228
  event.params?.firebase_screen ||
164
229
  event.params?.screen_name ||
165
- event.params?.firebase_screen_class}
166
- </react_native_1.Text>
167
- </react_native_1.View>) : null}
230
+ event.params?.firebase_screen_class;
231
+ if (!rawScreenName)
232
+ return null;
233
+ const screenNameStr = typeof rawScreenName === 'object'
234
+ ? JSON.stringify(rawScreenName)
235
+ : String(rawScreenName);
236
+ return (<react_native_1.View style={[cardStyles.chip, { backgroundColor: AppColors_1.AppColors.grayBackground, borderColor: AppColors_1.AppColors.grayBorderSecondary }]}>
237
+ <react_native_1.View style={[cardStyles.screenDot, { backgroundColor: color }]}/>
238
+ <react_native_1.Text style={[cardStyles.chipText, { color: AppColors_1.AppColors.grayText }]} numberOfLines={1}>
239
+ {screenNameStr}
240
+ </react_native_1.Text>
241
+ </react_native_1.View>);
242
+ })()}
168
243
 
169
244
  <react_native_1.View style={[cardStyles.chip, { backgroundColor: AppColors_1.AppColors.grayBackground, borderColor: AppColors_1.AppColors.grayBorderSecondary }]}>
170
245
  <react_native_1.Text style={[cardStyles.chipText, { color: AppColors_1.AppColors.grayText }]}>
@@ -311,6 +386,18 @@ const cardStyles = react_native_1.StyleSheet.create({
311
386
  textTransform: 'uppercase',
312
387
  letterSpacing: 0.5,
313
388
  },
389
+ categoryBadge: {
390
+ borderWidth: 1,
391
+ paddingHorizontal: 5,
392
+ paddingVertical: 2,
393
+ borderRadius: 4,
394
+ },
395
+ categoryText: {
396
+ fontFamily: AppFonts_1.AppFonts.interBold,
397
+ fontSize: 9,
398
+ textTransform: 'uppercase',
399
+ letterSpacing: 0.5,
400
+ },
314
401
  miniGraphWrapper: {
315
402
  flexDirection: 'row',
316
403
  alignItems: 'flex-end',
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "1.1.13";
1
+ export declare const LIB_VERSION = "1.1.14";
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LIB_VERSION = void 0;
4
4
  // AUTO-GENERATED FILE — do not edit by hand.
5
5
  // Regenerated from package.json on every build by scripts/gen-version.js.
6
- exports.LIB_VERSION = '1.1.13';
6
+ exports.LIB_VERSION = '1.1.14';
@@ -2,6 +2,14 @@ import { AnalyticsEvent } from '../types';
2
2
  export declare const subscribeAnalyticsEvents: (callback: (events: AnalyticsEvent[]) => void) => () => void;
3
3
  export declare const clearAnalyticsEvents: () => void;
4
4
  export declare const getAnalyticsEvents: () => AnalyticsEvent[];
5
+ export declare const getCurrentUserProperties: () => {
6
+ [x: string]: any;
7
+ };
8
+ export declare const getCurrentUserId: () => string;
9
+ export declare const getDefaultEventParameters: () => {
10
+ [x: string]: any;
11
+ };
12
+ export declare const getCollectionEnabled: () => boolean;
5
13
  /**
6
14
  * Directly push an event into the inspector without going through Firebase.
7
15
  * Useful for custom analytics wrappers or testing.
@@ -22,7 +22,7 @@
22
22
  // setUserId(id)
23
23
  // ─────────────────────────────────────────────────────────────────────────────
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.autoSetupAnalyticsLogger = exports.setupAnalyticsLogger = exports.logAnalyticsEvent = exports.getAnalyticsEvents = exports.clearAnalyticsEvents = exports.subscribeAnalyticsEvents = void 0;
25
+ exports.autoSetupAnalyticsLogger = exports.setupAnalyticsLogger = exports.logAnalyticsEvent = exports.getCollectionEnabled = exports.getDefaultEventParameters = exports.getCurrentUserId = exports.getCurrentUserProperties = exports.getAnalyticsEvents = exports.clearAnalyticsEvents = exports.subscribeAnalyticsEvents = void 0;
26
26
  // ─── Internal state ───────────────────────────────────────────────────────────
27
27
  let events = [];
28
28
  let listeners = [];
@@ -30,6 +30,8 @@ let counter = 0;
30
30
  // Running snapshot of user properties set so far — attached to every event
31
31
  let currentUserProperties = {};
32
32
  let currentUserId;
33
+ let currentDefaultEventParameters = {};
34
+ let isCollectionEnabled = true;
33
35
  // ─── Core helpers ─────────────────────────────────────────────────────────────
34
36
  const notify = () => {
35
37
  const snapshot = [...events];
@@ -56,6 +58,14 @@ const clearAnalyticsEvents = () => {
56
58
  exports.clearAnalyticsEvents = clearAnalyticsEvents;
57
59
  const getAnalyticsEvents = () => [...events];
58
60
  exports.getAnalyticsEvents = getAnalyticsEvents;
61
+ const getCurrentUserProperties = () => ({ ...currentUserProperties });
62
+ exports.getCurrentUserProperties = getCurrentUserProperties;
63
+ const getCurrentUserId = () => currentUserId;
64
+ exports.getCurrentUserId = getCurrentUserId;
65
+ const getDefaultEventParameters = () => ({ ...currentDefaultEventParameters });
66
+ exports.getDefaultEventParameters = getDefaultEventParameters;
67
+ const getCollectionEnabled = () => isCollectionEnabled;
68
+ exports.getCollectionEnabled = getCollectionEnabled;
59
69
  // ─── Manual logging (escape hatch, rarely needed) ────────────────────────────
60
70
  /**
61
71
  * Directly push an event into the inspector without going through Firebase.
@@ -154,8 +164,39 @@ const setupAnalyticsLogger = (analyticsInstance) => {
154
164
  const originalSetUserId = analyticsInstance.setUserId.bind(analyticsInstance);
155
165
  analyticsInstance.setUserId = async (id) => {
156
166
  currentUserId = id ?? undefined;
167
+ notify();
157
168
  return originalSetUserId(id);
158
169
  };
170
+ // ── setDefaultEventParameters ──────────────────────────────────────────────
171
+ if (typeof analyticsInstance.setDefaultEventParameters === 'function') {
172
+ const originalSetDefaultEventParameters = analyticsInstance.setDefaultEventParameters.bind(analyticsInstance);
173
+ analyticsInstance.setDefaultEventParameters = async (params) => {
174
+ currentDefaultEventParameters = params ?? {};
175
+ notify();
176
+ return originalSetDefaultEventParameters(params);
177
+ };
178
+ }
179
+ // ── setAnalyticsCollectionEnabled ───────────────────────────────────────────
180
+ if (typeof analyticsInstance.setAnalyticsCollectionEnabled === 'function') {
181
+ const originalSetAnalyticsCollectionEnabled = analyticsInstance.setAnalyticsCollectionEnabled.bind(analyticsInstance);
182
+ analyticsInstance.setAnalyticsCollectionEnabled = async (enabled) => {
183
+ isCollectionEnabled = enabled;
184
+ notify();
185
+ return originalSetAnalyticsCollectionEnabled(enabled);
186
+ };
187
+ }
188
+ // ── resetAnalyticsData ──────────────────────────────────────────────────────
189
+ if (typeof analyticsInstance.resetAnalyticsData === 'function') {
190
+ const originalResetAnalyticsData = analyticsInstance.resetAnalyticsData.bind(analyticsInstance);
191
+ analyticsInstance.resetAnalyticsData = async () => {
192
+ (0, exports.clearAnalyticsEvents)();
193
+ currentUserProperties = {};
194
+ currentUserId = undefined;
195
+ currentDefaultEventParameters = {};
196
+ notify();
197
+ return originalResetAnalyticsData();
198
+ };
199
+ }
159
200
  };
160
201
  exports.setupAnalyticsLogger = setupAnalyticsLogger;
161
202
  const autoSetupAnalyticsLogger = () => {
@@ -3,7 +3,7 @@ declare const NetworkInspectorWrapper: (props: any) => React.JSX.Element;
3
3
  export default NetworkInspectorWrapper;
4
4
  export { setupNetworkLogger, clearNetworkLogs, subscribeNetworkLogs, addAxiosInterceptors, } from './customHooks/networkLogger';
5
5
  export { setupConsoleLogger, clearConsoleLogs, subscribeConsoleLogs, } from './customHooks/consoleLogger';
6
- export { setupAnalyticsLogger, logAnalyticsEvent, subscribeAnalyticsEvents, clearAnalyticsEvents, } from './customHooks/analyticsLogger';
6
+ export { setupAnalyticsLogger, logAnalyticsEvent, subscribeAnalyticsEvents, clearAnalyticsEvents, getCurrentUserProperties, getCurrentUserId, getDefaultEventParameters, getCollectionEnabled, } from './customHooks/analyticsLogger';
7
7
  export { WebView, getWebViewLogs, getWebViewNavHistory, getWebViewHtml, getWebViewCss, getWebViewJs, getWebViewHtmlUrl, clearWebViewData, subscribeWebView, } from './customHooks/webViewLogger';
8
8
  export { default as ErrorBoundary } from './components/ErrorBoundary';
9
9
  export { connectReduxStore, inspectorReduxMiddleware, getReduxState, subscribeReduxState, getActionHistory, clearActionHistory, } from './customHooks/reduxLogger';