0
# React Native Integration
1
2
React Native specific functionality for person management and error tracking in React Native applications.
3
4
## Capabilities
5
6
### Set Person
7
8
Associate a person with error reports and telemetry events.
9
10
```typescript { .api }
11
/**
12
* Set the person associated with error reports
13
* @param personInfo - Person information to associate with errors
14
*/
15
function setPerson(personInfo: PersonInfo): void;
16
17
interface PersonInfo {
18
id: string | number | null;
19
username?: string;
20
email?: string;
21
[property: string]: any;
22
}
23
```
24
25
**Usage Examples:**
26
27
```javascript
28
// Set basic person information
29
rollbar.setPerson({
30
id: '12345',
31
username: 'alice',
32
email: 'alice@example.com'
33
});
34
35
// Set person with custom fields
36
rollbar.setPerson({
37
id: 67890,
38
username: 'bob',
39
email: 'bob@company.com',
40
role: 'admin',
41
department: 'engineering',
42
custom_field: 'value'
43
});
44
45
// Set person with minimal info
46
rollbar.setPerson({
47
id: 'anonymous_user_123'
48
});
49
```
50
51
### Clear Person
52
53
Remove person association from future error reports.
54
55
```typescript { .api }
56
/**
57
* Clear the person associated with error reports
58
*/
59
function clearPerson(): void;
60
```
61
62
**Usage Example:**
63
64
```javascript
65
// Clear person information (e.g., on logout)
66
rollbar.clearPerson();
67
68
// Subsequent errors will not be associated with any person
69
rollbar.error('This error has no person associated');
70
```
71
72
## React Native Setup Example
73
74
```javascript
75
import Rollbar from 'rollbar';
76
77
// Initialize Rollbar for React Native
78
const rollbar = new Rollbar({
79
accessToken: 'YOUR_POST_CLIENT_ITEM_ACCESS_TOKEN',
80
environment: 'production',
81
captureUncaught: true,
82
captureUnhandledRejections: true
83
});
84
85
// Set person information after login
86
function onUserLogin(user) {
87
rollbar.setPerson({
88
id: user.id,
89
username: user.username,
90
email: user.email,
91
role: user.role,
92
subscription_tier: user.subscriptionTier
93
});
94
95
rollbar.info('User logged in', { userId: user.id });
96
}
97
98
// Clear person information on logout
99
function onUserLogout() {
100
rollbar.info('User logging out');
101
rollbar.clearPerson();
102
}
103
104
// Error handling with person context
105
function processPayment(paymentData) {
106
try {
107
// Payment processing logic
108
return processPaymentAPI(paymentData);
109
} catch (error) {
110
// Error will be associated with current person
111
rollbar.error('Payment processing failed', {
112
paymentAmount: paymentData.amount,
113
paymentMethod: paymentData.method
114
});
115
throw error;
116
}
117
}
118
119
export { rollbar, onUserLogin, onUserLogout };
120
```
121
122
## Person Information Guidelines
123
124
### Required Fields
125
126
- **id**: Unique identifier for the person (string or number)
127
128
### Optional Fields
129
130
- **username**: Display name or username
131
- **email**: Email address for notifications
132
- **[custom fields]**: Any additional custom properties
133
134
### Best Practices
135
136
1. **Set person early**: Call `setPerson()` as soon as user authentication is available
137
2. **Clear on logout**: Always call `clearPerson()` when users log out
138
3. **Update on changes**: Call `setPerson()` again if person information changes
139
4. **Privacy considerations**: Only include necessary information, avoid sensitive data
140
5. **Custom fields**: Use custom fields for application-specific context like user roles, subscription tiers, etc.
141
142
### Person Data Privacy
143
144
The person information is sent with error reports to help with debugging and user impact assessment. Be mindful of:
145
146
- **PII Data**: Consider your privacy policy when including email addresses or other personally identifiable information
147
- **Data Retention**: Person data follows Rollbar's data retention policies
148
- **Access Control**: Ensure appropriate team access controls are in place for person data
149
150
## Integration with Other Features
151
152
### Error Context
153
154
When a person is set, all subsequent error reports will include the person information:
155
156
```javascript
157
rollbar.setPerson({ id: '123', username: 'alice' });
158
159
// This error will be associated with alice
160
rollbar.error('Database connection failed');
161
```
162
163
### Telemetry Events
164
165
Person information is also included with telemetry events:
166
167
```javascript
168
rollbar.setPerson({ id: '123', role: 'admin' });
169
170
rollbar.captureEvent({
171
type: 'user_action',
172
action: 'admin_panel_access'
173
}, 'info');
174
// Event will include person context
175
```
176
177
### Custom Data
178
179
Person information can be supplemented with custom data in individual error reports:
180
181
```javascript
182
rollbar.setPerson({ id: '123', username: 'alice' });
183
184
rollbar.error('Operation failed', {
185
// This additional context is added to the person info
186
currentPage: '/dashboard',
187
feature: 'data-export'
188
});
189
```