Hi, I'am Sergey and i like React Native.
Recently me needed analytics for my app in React Native and i make small script.
Go to https://appmetrica.yandex.ru , yeah this is Russian service for analytics, but he very cool.
Registration and create 'metrica'
Write this code
const API_KEY = 'WRITE_THIS_YOUR_KEY'
const BOTAN_URL = 'https://api.botan.io/track';
const DEFAULT_NAME = 'Message';
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
//better you use really UID in your app
}
export default function sendEvent(message, name = DEFAULT_NAME) {
return fetch(`${BOTAN_URL}/?token=${API_KEY}&name=${name}&uid=${getRandomInt(0,9999)}`, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify(message)
})
.then(res => res.json())
.then(data => {
return data
})
}
- Done!
How use this function?
componentDidMount() {
getAllCategories()
.then(data => {
let categories = data.response.category
sendEvent({},'loadCategories')
this.setState({
categories : categories,
end_loading_categories : false
})
})
.catch(() => {
sendEvent({},'loadCategoriesError',() => {})
this.setState({
end_loading_categories : false
})
})
}
Here's how it looks on the charts.
Top comments (0)