Skip to content

Instantly share code, notes, and snippets.

@siwananda
Last active June 24, 2017 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siwananda/7d9b62b2a9b09442abb532a177187157 to your computer and use it in GitHub Desktop.
Save siwananda/7d9b62b2a9b09442abb532a177187157 to your computer and use it in GitHub Desktop.
Analytics in react native using fabric
Brief gists to enable user analytics in react native using fabric
...
import { Crashlytics, Answers } from 'react-native-fabric'; //Add Answers
export default class FabricAnalytics extends Component {
componentDidMount(){
...
//Additional answers
Answers.logContentView('To Do 1', 'To-Do', 'to-do-42');
Answers.logContentView('To Do 2', 'To-Do', 'to-do-42');
}
...
}
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import { Crashlytics } from 'react-native-fabric'; //Get Crashlytics component
export default class FabricAnalytics extends Component {
componentDidMount(){
//Sets user details
Crashlytics.setUserName('megaman');
Crashlytics.setUserEmail('user@email.com');
Crashlytics.setUserIdentifier('1234');
}
render() {
return (
<View style={styles.container}>
<Text style={styles.text}>
React native fabric
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
text: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}
});
AppRegistry.registerComponent('FabricAnalytics', () => FabricAnalytics);
export default class FabricAnalytics extends Component {
componentDidMount(){
...
setTimeout(()=> Crashlytics.crash(), 5000); //simulates a crash after 5 seconds
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment