@janiscommerce/app-analytics

2.4.0 • Public • Published

@janiscommerce/app-analytics

janis-logo

Library of methods to send information to firebase.

Firebase setting

Before getting started, you should have set up a new firebase project.

If you already have it set up, the next step to do would be to add the google-services.json file to the root directory of your module (/android/app).

Add the firebase sdk

For the Firebase SDKs to be able to access the google-services.json configuration values, you need the Google Services Gradle plugin.

Add the plugin as a dependency to your project-level build.gradle file: (android/build.gradle)

dependencies {
        // ...
        classpath 'com.google.gms:google-services:4.3.15'
    } 

Additionally, should add google services plugins in android/app/build.gradle and any Firebase SDKs you want to use in your app:

plugins {
  // ...

  // Add the Google services Gradle plugin
  id("com.google.gms.google-services")
}

dependencies {
  // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:32.2.2')


  // TODO: Add the dependencies for Firebase products you want to use
  // When using the BoM, don't specify versions in Firebase dependencies
  implementation 'com.google.firebase:firebase-analytics'


  // Add the dependencies for any other desired Firebase products
  // https://firebase.google.com/docs/android/setup#available-libraries
}

Clean the project

cd android && ./gradlew clean && cd ..

PeerDependencies Installation

For the methods of this library to work, the following dependencies must be installed:

npm install @react-native-firebase/app

The @react-native-firebase/app module must be installed before using any other Firebase service.

Additionally, you need to install the dependency of the firebase service you want to use. For example this:

npm install @react-native-firebase/analytics

This dependency will allow that, when executing the methods of the package, these can be registered as events in firebase

Installation

npm install @janiscommerce/app-analytics

Usage

Modules

initialize

This method is responsible for initializing the analytics class and obtaining the user information to build the instance;

sendUserInfo

send userInfo Event to analytics console with user, app and device data.

sendAction

send an action log to analytics console

sendCustomEvent

send a new customEvent to analytics console

sendScreenTracking

send a screenViewEvent to analytics console to record the screens the user visits

Classes

Analytics

Functions

actionEvent(params)boolean

is responsible for registering an event that reports the execution of an action by the user. Not use the camelCase format, since the function transforms the strings to lowercase. Instead write with spaces, as they will later be replaced by underscores

customEvent(eventName, params, customRequiredParams)boolean

allows to register a custom event, receives the name of the event to be registered and the associated data

screenViewEvent(screenName, screenClass)boolean

logs an event with information from the screen the user is viewing

userInfoEvent(params)boolean

is responsible for registering an event that reports all data of user, device and app

initialize

This method is responsible for initializing the analytics class and obtaining the user information to build the instance;

Param Type Description
appVersion string a string that represents the version number of the app

Example

const analyticsInstance = await Analytics.initialize('1.22.0.0')

sendUserInfo

send userInfo Event to analytics console with user, app and device data.

sendAction

send an action log to analytics console

Param Type Description
actionName string is the name of the action the user completed
screenName string is the name of the screen where the action was called
params object An object with any additional information you would like to register for the event

sendCustomEvent

send a new customEvent to analytics console

Param Type Description
eventName string is the name that will be received the event logged
params object An object with any additional information you would like to register for the event
requiredParams array array of extra strings required for a custom event

sendScreenTracking

send a screenViewEvent to analytics console to record the screens the user visits

Param Type Description
screenName string Screen name the user is currently viewing.
screenClass string Current class associated with the view the user is currently viewing.

Analytics

Kind: global class

new Analytics(params)

This class is responsible for handling events to record user information, actions and custom events

Param Type Description
params object an object that contains all the information regarding the user that you want to add as initial information. This will then be used based on the need of each event.
params.appVersion string a string that represents the version number of the app

Example

import Analytics from '@janiscommerce/app-analytics'

const analytics = new Analytics({appVersion:'1.22.0'})

actionEvent(params) ⇒ boolean

is responsible for registering an event that reports the execution of an action by the user. Not use the camelCase format, since the function transforms the strings to lowercase. Instead write with spaces, as they will later be replaced by underscores

Kind: global function
Throws:

  • an error when not pass valid params or any of the required parameters are missing
Param Type Description
params object data set to send
params.actionName string name of the action that will be registered
params.client string janis operating client
params.userEmail string janis registered user email
params.userId string registered user id
params.language string language used in the application
params.appVersion string app version in use
params.screenName string screen where the action was called
params.anotherKey... string any extra data that you want to be sent will be cataloged as dataEvent

Example

import {actionEvent} from '@janiscommerce/app-analytics'

actionEvent({actionName:'button press',client: 'client',userEmail: 'janis@janis.im',userId:'123456',appVersion:'1.20.0'})

customEvent(eventName, params, customRequiredParams) ⇒ boolean

allows to register a custom event, receives the name of the event to be registered and the associated data

Kind: global function
Throws:

  • an error when some required params is not passed
Param Type Description
eventName string name of the event that we are going to register
params object event parameters, information that we are going to send
params.client string janis operating client
params.userEmail string janis registered user email
params.userId string registered user id
params.appVersion string app version in use
params.language string user app language
params.anotherKey... string any extra data that you want to be sent will be cataloged as dataEvent
customRequiredParams Array.<string> any extra parameters that may be required for any custom event

Example

import {customEvent} from '@janiscommerce/app-analytics'

customEvent('event_init',{date:"2011-10-05T14:48:00.000Z"})

screenViewEvent(screenName, screenClass) ⇒ boolean

logs an event with information from the screen the user is viewing

Kind: global function
Throws:

  • an error when some required params is not passed
Param Type Description
screenName string Screen name the user is currently viewing.
screenClass string Current class associated with the view the user is currently viewing.
params.client string janis operating client
params.userEmail string janis registered user email
params.userId string registered user id
params.language string language used in the application
params.appVersion string app version in use

Example

import {screenViewEvent} from '@janiscommerce/app-analytics'

screenViewEvent('home','class_home')

userInfoEvent(params) ⇒ boolean

is responsible for registering an event that reports all data of user, device and app

Kind: global function
Throws:

  • an error when not pass valid params
Param Type Description
params object data set to send
params.appName string name of the app in use
params.appVersion string app version in use
params.device string device model
params.osVersion string version of the model
params.userEmail string janis registered user email
params.userId string registered user id
params.client string janis operating client
params.language string language used in the application
params.screenSize string screen size to user'device
params.screenSize.screenHeight string user device screen height
params.screenSize.screenWidth string user device screen width

Example

import {userInfoEvent} from '@janiscommerce/app-analytics

userInfoEvent({appName:'app_name',appVersion:'1.0.0',device:'samsung a10',os:'android',osVersion:'10',userEmail:'user_name@janis.im',userId:'012345678910', client: 'janis'})

Package Sidebar

Install

npm i @janiscommerce/app-analytics

Weekly Downloads

17

Version

2.4.0

License

ISC

Unpacked Size

35.1 kB

Total Files

11

Last publish

Collaborators

  • janiscommerce