New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hadx/analytics

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hadx/analytics

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

  • 1.1.33
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 IDWhenData
newUnita new user installs your appdeviceID

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

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

Keywords

FAQs

Package last updated on 22 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc