npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hadx/analytics

v1.1.33

Published

Hadex's analytics service to track and report app's usage

Downloads

50

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

  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) {
    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)

  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:

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

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.

Todo

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