Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import firebase from '@react-native-firebase/app';
  3. import analytics from '@react-native-firebase/analytics';
  4. import {
  5. StyleSheet,
  6. Button,
  7. View,
  8. SafeAreaView,
  9. Text,
  10. Alert,
  11. } from 'react-native';
  12.  
  13. function Separator() {
  14. return <View style={styles.separator} />;
  15. }
  16.  
  17. const User = {
  18. uid :'10010id',
  19. balance : 1000
  20. }
  21.  
  22. export default class Analytics extends Component {
  23.  
  24.  
  25. async componentDidMount() {
  26. await firebase.app();
  27. analytics().setCurrentScreen('Analytics');
  28. }
  29.  
  30. async addCustomEvent() {
  31. await analytics().logEvent('custom_event', {
  32. id: '123123',
  33. value: 'value',
  34. variable: 'variable',
  35. });
  36. }
  37.  
  38. async onSignIn() {
  39. await Promise.all([
  40. analytics().setUserId(User.uid),
  41. analytics().setUserProperty('account_balance', User.balance),
  42. ]);
  43. }
  44.  
  45. async onSignOut() {
  46. await analytics().resetAnalyticsData();
  47. }
  48.  
  49. render() {
  50. return (
  51. <SafeAreaView style={styles.container}>
  52. <View>
  53. <Text style={styles.title}>
  54. To log a custom event, use the logEvent method:
  55. </Text>
  56. <Button
  57. title="Add custom event"
  58. onPress={() => this.addCustomEvent()}
  59. />
  60. </View>
  61. <Separator />
  62. <View>
  63. <Text style={styles.title}>
  64. 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.
  65. </Text>
  66. <Button
  67. title="Set User"
  68. color="#f194ff"
  69. onPress={() => this.onSignIn()}
  70. />
  71. </View>
  72. <Separator />
  73. <View>
  74. <Text style={styles.title}>
  75. 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.
  76. </Text>
  77. <Button
  78. title="Reset Analyticss Data"
  79.  
  80. onPress={() => this.resetAnalyticsData()}
  81. />
  82. </View>
  83. <Separator />
  84. </SafeAreaView>
  85. );
  86. }
  87. }
  88.  
  89.  
  90. const styles = StyleSheet.create({
  91. container: {
  92. flex: 1,
  93. marginTop: 44,
  94. marginHorizontal: 16,
  95. },
  96. title: {
  97. textAlign: 'center',
  98. marginVertical: 8,
  99. },
  100. fixToText: {
  101. flexDirection: 'row',
  102. justifyContent: 'space-between',
  103. },
  104. separator: {
  105. marginVertical: 8,
  106. borderBottomColor: '#737373',
  107. borderBottomWidth: StyleSheet.hairlineWidth,
  108. },
  109. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement