Hadex Analytics
This is a lightweight analytics library to track and report React Native app's usage using Firebase's firestore. Supporting real time mobile notification using One Signal.
What for?
Why not use Firebase Analytics?
You can have access to all the data programmatically since it's hosted on your firebase firestore. Hadex Analytics also provides functions to read, filter and analyse those data. No need to export to BigQuery which is not free.
Getting started
-
Create a new project on firebase console (ex: AppsAnalytics)
-
Create Firestore database with Rules
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
- Enable Anonymous Authentication
- Install this package
yarn add @hadx/analytics
-
Install react-native-device-info
-
Add a Web App to the project
-
Copy and save the firebaseConfig part to your code
Basic Usage
In your React Native app that you want to track:
import Analytics from '@hadx/analytics';
export default class App extends React.Component {
componentDidMount() {
Analytics.initialize({appID: 'myappID', firebaseConfig: {
}}, () => {
Analytics.logEvent('openApp')
});
}
}
In your Report website or app:
import Analytics from '@hadx/analytics';
Analytics.initalize({firebaseConfig: {
}}, () => {
Analytics.getAppEvents('myappID', [["id", '==', 'newUnit']]).then(events => {
console.log('Total users: ' + events.length)
});
})
Event notification (optional)
Want to receive real time notification with your mobile app when an user buy your in-app-purchase? (or whatever event you want to subscribe to)
- Your own private mobile app to receive notifications (not your tracked apps)
- Create an app on One Signal (ex: AppsAnalytics)
- Install One Signal for React Native
- Copy your One Signal API key and app id from the dashboard
Dependencies
Automatic events
These events below are logged automatically for you
Event ID | When | Data |
---|
newUnit | a new user installs your app | deviceID |