@hadx/analytics
v1.1.33
Published
Hadex's analytics service to track and report app's usage
Downloads
50
Maintainers
Readme
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 Email/Password Authentication and add a new user, note down the email and password
- Install this package
yarn add @hadx/analytics
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 {
constructor(props: Props) {
super(props);
Analytics.initialize({
debug: __DEV__,
appID: THIS_APP_ID,
firebaseAuth: {email: ..., password: ...}, // created earlier
firebaseConfig: ..., // copied above
}).then(() => {
Analytics.logEvent('openApp'); // example event
});
}
}
In your Report website or app:
import Analytics from '@hadx/analytics';
Analytics.initialize({
debug: __DEV__,
firebaseAuth: {email: ..., password: ...}, // created earlier
firebaseConfig: ..., // copied above
}).then(() => {
// newUnit is an event that is logged automatically by Hadex Analytics
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({
..., // just like example in Basic Usage
notificationConfig: {apiKey: ..., appID: ...}, // copied above
});
In your private app that receives notifications:
import OneSignal from 'react-native-one-signal';
Analytics.initialize({
..., // just like example in Basic Usage
notificationConfig: {
apiKey: ..., // copied above
appID: ..., // copied above
oneSignalModule: OneSignal
},
});
You can set the notification content and heading for each event type with dynamic values
Analytics.updateEventType('myAppID', 'newUnit', {
'notification.heading': 'New user',
'notification.content': 'There is a new user from {countryCode}'
});
// Notificaiton receive: 'There is a new user from US'
Available dynamic values are fields from the Event interface (See documentation for detail) and values from data when you log your event. For example:
// In the tracked app
Analytics.logEvent('newUnit', {name: 'Arthur'});
// In the report app
Analytics.updateEventType('myAppID', 'newUnit', {
'notification.content': 'There is a new user {name}'
});
/*
* When the 'newUnit' event is logged,
* the report app will recieve:
* 'There is a new user Arthur'
*/
Dependencies
- react-native-device-info: used to get device's informations
- firebase: used mainly for firestore api
- onesignal (optional): used to receive real time notification on event triggered
Automatic events
These events below are logged automatically for you
| Event ID | When | Data | | -------- | ------------------------------ | ------------- | | 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:
- 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
- [x] Analytics functions
- [x] Event node system
- [x] Notification with dynamic values
- [ ] Web report support
- [ ] Web notification