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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
- Enable Email/Password Authentication and add a new user, note down the email and password
- Install this package
yarn add @hadx/analytics
- 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 {
constructor(props: Props) {
super(props);
Analytics.initialize({
debug: __DEV__,
appID: THIS_APP_ID,
firebaseAuth: {email: ..., password: ...},
firebaseConfig: ...,
}).then(() => {
Analytics.logEvent('openApp');
});
}
}
In your Report website or app:
import Analytics from '@hadx/analytics';
Analytics.initialize({
debug: __DEV__,
firebaseAuth: {email: ..., password: ...},
firebaseConfig: ...,
}).then(() => {
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)
- You need 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
In the app you want to track:
Analytics.initialize({
...,
notificationConfig: {apiKey: ..., appID: ...},
});
In your private app that receives notifications:
import OneSignal from 'react-native-one-signal';
Analytics.initialize({
...,
notificationConfig: {
apiKey: ...,
appID: ...,
oneSignalModule: OneSignal
},
});
Dependencies
Automatic events
These events below are logged automatically for you
newUnit | a new user installs your app | deviceID |
Pricing & Scaling up
This library is pratically free for small and medium size app. (the library itself is free ofcourse)
It uses the free plan of 2 main services:
Firebase firestore:
- Unlimited authentication
- 1 GiB total stored data
- Network egress 10GiB/month
- Write 20K/day
- Read 50K/day
- Delete 20K/day
1GiB ≈ 1.074GB
One Signal: shoutout to One Signal for their great free plan. The features used by this library is unlimited on One Signal.
- 30K web subscribers (but you won't have more than 30K people who have access to your apps report website right?)
- Unlimited mobile subscribers
- Unlimited web and mobile push notification
So if you usage of firebase firestore is more than what the free plan allowed, you can easily scale up with their paid plan. The price is pretty reasonable. When this happens, usually you should have gain more money with ads (or whatever your bussiness model is) than what you have to pay for firebase.
Todo