Skip to content

Instantly share code, notes, and snippets.

@elof elof/index.ios.js
Created Feb 28, 2017

Embed
What would you like to do?
Using Keen IO to collect and query event data in React Native
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Fetch
} from 'react-native';
export default class AwesomeProject extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Reactive native is pretty dang cool
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
// This is how you can send an event to Keen using the fetch method
fetch('https://api.keen.io/3.0/projects/<YOUR_PROJECT_ID_GOES_HERE>/events/<CHOOSE_A_COLLECTION_NAME>?api_key=<YOUR_KEEN_IO_KEY_GOES_HERE>', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstParam: 'yourValue',
secondParam: 'yourOtherValue',
})
})
// This is how you can query Keen using the fetch method
fetch('https://api.keen.io/3.0/projects/<YOUR_PROJECT_ID_GOES_HERE>/queries/count?api_key=<YOUR_KEEN_IO_KEY_GOES_HERE>&event_collection=pageviews&timezone=UTC&timeframe=this_14_days&filters=%5B%5D')
.then((response) => response.json())
.then((responseJson) => {
var queryResult = responseJson.result;
console.log(queryResult);
})
.catch((error) => {
console.error(error);
});
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.