TypeScript icon, indicating that this package has built-in type declarations

1.1.33 • Public • Published

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

  1. Create a new project on firebase console (ex: AppsAnalytics)

  2. Create Firestore database with Rules

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
  1. Enable Email/Password Authentication and add a new user, note down the email and password
  2. Install this package
yarn add @hadx/analytics
  1. Install react-native-device-info

  2. Add a Web App to the project

  1. 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) {
      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';

      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)

  1. You need your own private mobile app to receive notifications (not your tracked apps)
  2. Create an app on One Signal (ex: AppsAnalytics)
  3. Install One Signal for React Native
  4. Copy your One Signal API key and app id from the dashboard

In the app you want to track:

  ..., // 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';

  ..., // 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'


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:

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.


  • [x] Analytics functions
  • [x] Event node system
  • [x] Notification with dynamic values
  • [ ] Web report support
  • [ ] Web notification


npm i @hadx/analytics

DownloadsWeekly Downloads






Unpacked Size

62 kB

Total Files


Last publish


  • newbiebr