This repository was archived by the owner on Feb 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnalytics.js
More file actions
110 lines (97 loc) · 2.98 KB
/
Copy pathAnalytics.js
File metadata and controls
110 lines (97 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React, { Component } from 'react';
import firebase from '@react-native-firebase/app';
import analytics from '@react-native-firebase/analytics';
import {
StyleSheet,
Button,
View,
SafeAreaView,
Text,
Alert,
} from 'react-native';
function Separator() {
return <View style={styles.separator} />;
}
const User = {
uid :'10010id',
balance : 1000
}
export default class Analytics extends Component {
async componentDidMount() {
await firebase.app();
analytics().setCurrentScreen('Analytics');
}
async addCustomEvent() {
await analytics().logEvent('custom_event', {
id: '123123',
value: 'value',
variable: 'variable',
});
}
async onSignIn() {
await Promise.all([
analytics().setUserId(User.uid),
analytics().setUserProperty('account_balance', User.balance),
]);
}
async onSignOut() {
await analytics().resetAnalyticsData();
}
render() {
return (
<SafeAreaView style={styles.container}>
<View>
<Text style={styles.title}>
To log a custom event, use the logEvent method:
</Text>
<Button
title="Add custom event"
onPress={() => this.addCustomEvent()}
/>
</View>
<Separator />
<View>
<Text style={styles.title}>
User data can be attached to analytical events via the setUserId, setUserProperties and setUserProperty methods. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties.
</Text>
<Button
title="Set User"
color="#f194ff"
onPress={() => this.onSignIn()}
/>
</View>
<Separator />
<View>
<Text style={styles.title}>
In some cases, resetting all analytics data is required on certain events such as signing out of the application. To achieve this call the resetAnalyticsData method.
</Text>
<Button
title="Reset Analyticss Data"
onPress={() => this.resetAnalyticsData()}
/>
</View>
<Separator />
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 44,
marginHorizontal: 16,
},
title: {
textAlign: 'center',
marginVertical: 8,
},
fixToText: {
flexDirection: 'row',
justifyContent: 'space-between',
},
separator: {
marginVertical: 8,
borderBottomColor: '#737373',
borderBottomWidth: StyleSheet.hairlineWidth,
},
});