Skip to content

Commit 0dee690

Browse files
authored
Merge pull request #23 from sentry-demos/feat_set_useremail_override
Feat: Set user context
2 parents 04c572f + f9baa8f commit 0dee690

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

android/sentry.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
defaults.url=https://sentry.io/
22
defaults.org=testorg-az
3-
defaults.project=dustin-react-native
3+
defaults.project=react-native
44
auth.token=XXXX

ios/sentry.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
defaults.url=https://sentry.io/
22
defaults.org=testorg-az
3-
defaults.project=dustin-react-native
3+
defaults.project=react-native
44
auth.token=XXXX

src/App.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ const Stack = createStackNavigator();
7474

7575
const App = () => {
7676
const navigation = React.useRef();
77-
77+
78+
Sentry.configureScope(scope => {
79+
const customerType = ["medium-plan", "large-plan", "small-plan", "enterprise"][Math.floor(Math.random() * 4)]
80+
scope.setTag("customerType", customerType )
81+
let email = Math.random().toString(36).substring(2, 6) + "@yahoo.com";
82+
scope.setUser({ email: email })
83+
})
84+
7885

7986
return (
8087
<Provider store={store}>

src/reduxApp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ const initialState = {
1717
};
1818

1919
const reducer = (state = initialState, action) => {
20-
let {payload,type} = action;
20+
let {payload,type,onScope} = action;
2121

2222
switch (type) {
2323
case 'FILL_FIELDS':
2424
if (payload == 'dummydata') {
2525
return {
2626
...state,
2727
contactInfo: {
28-
email: Math.random().toString(36).substring(2, 6) + "@yahoo.com",
28+
email: onScope ? onScope:Math.random().toString(36).substring(2, 6) + "@yahoo.com",
2929
firstName:"john",
3030
lastName:"doe",
3131
address:"123 Hope St",

src/screens/CheckoutScreen.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ const CheckoutScreen = (props) => {
4545
const contactInfoData = useSelector((state: RootState) => state.contactInfo);
4646
const [orderStatusUI, setOrderStatusUI] = React.useState(false);
4747

48+
let se, customerType, email
49+
Sentry.withScope(function(scope) {
50+
[ se, customerType ] = [scope._tags.se, scope._tags.customerType ]
51+
email = scope._user.email
52+
});
4853
const performCheckoutOnServer = async () => {
4954
// ----------- Sentry Start Transaction ------------------------
5055
let transaction = Sentry.startTransaction({name: 'checkout'});
@@ -63,8 +68,12 @@ const CheckoutScreen = (props) => {
6368
};
6469

6570
const placeOrder = async (
71+
6672
uiToast: null | UIToast = null,
6773
): Promise<Response> => {
74+
75+
76+
6877
setOrderStatusUI(true);
6978

7079
const cart = Object.values(cartData)
@@ -87,7 +96,9 @@ const CheckoutScreen = (props) => {
8796
method: 'POST',
8897
headers: {
8998
'Content-Type': 'application/json',
90-
email: contactInfoData['email'],
99+
email,
100+
se,
101+
customerType
91102
},
92103
body: JSON.stringify(data),
93104
},
@@ -170,7 +181,7 @@ const CheckoutScreen = (props) => {
170181
value={contactInfoData[item.key] || ""}
171182
placeholder={item.placeholder}
172183
onPressIn={() => {
173-
dispatch({ type: 'FILL_FIELDS', payload: 'dummydata' })}
184+
dispatch({ type: 'FILL_FIELDS', payload: 'dummydata', onScope:email ? email:null})}
174185
}
175186
/>
176187
</SafeAreaView>

src/screens/EmpowerPlant.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ const EmpowerPlant = ({navigation}) => {
4040

4141
const loadData = () => {
4242
setProductData(null);
43+
let se, customerType, email;
44+
Sentry.withScope(function(scope) {
45+
[ se, customerType ] = [scope._tags.se, scope._tags.customerType ]
46+
email = scope._user.email
47+
});
4348

4449
fetch(`${BACKEND_URL}/products`, {
4550
method: 'GET',
46-
headers: { se:'willreactnative', customerType:'enterprise', email:'[email protected]', "Content-Type": "application/json" },
51+
headers: { se, customerType, email, "Content-Type": "application/json" },
4752
})
4853
.then((response) => response.json())
4954
.then((json) => {

0 commit comments

Comments
 (0)