2.3.0 • Published 19 days ago

@janiscommerce/app-analytics v2.3.0

Weekly downloads
-
License
ISC
Repository
-
Last release
19 days ago

@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

Classes

Functions

initialize

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

ParamTypeDescription
appVersionstringa 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

ParamTypeDescription
actionNamestringis the name of the action the user completed
screenNamestringis the name of the screen where the action was called
paramsobjectAn object with any additional information you would like to register for the event

sendCustomEvent

send a new customEvent to analytics console

ParamTypeDescription
eventNamestringis the name that will be received the event logged
paramsobjectAn object with any additional information you would like to register for the event
requiredParamsarrayarray of extra strings required for a custom event

sendScreenTracking

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

ParamTypeDescription
screenNamestringScreen name the user is currently viewing.
screenClassstringCurrent 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

ParamTypeDescription
paramsobjectan 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.appVersionstringa 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
ParamTypeDescription
paramsobjectdata set to send
params.actionNamestringname of the action that will be registered
params.clientstringjanis operating client
params.userEmailstringjanis registered user email
params.userIdstringregistered user id
params.languagestringlanguage used in the application
params.appVersionstringapp version in use
params.screenNamestringscreen where the action was called
params.anotherKey...stringany 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
ParamTypeDescription
eventNamestringname of the event that we are going to register
paramsobjectevent parameters, information that we are going to send
params.clientstringjanis operating client
params.userEmailstringjanis registered user email
params.userIdstringregistered user id
params.appVersionstringapp version in use
params.languagestringuser app language
params.anotherKey...stringany extra data that you want to be sent will be cataloged as dataEvent
customRequiredParamsArray.<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
ParamTypeDescription
screenNamestringScreen name the user is currently viewing.
screenClassstringCurrent class associated with the view the user is currently viewing.
params.clientstringjanis operating client
params.userEmailstringjanis registered user email
params.userIdstringregistered user id
params.languagestringlanguage used in the application
params.appVersionstringapp 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
ParamTypeDescription
paramsobjectdata set to send
params.appNamestringname of the app in use
params.appVersionstringapp version in use
params.devicestringdevice model
params.osVersionstringversion of the model
params.userEmailstringjanis registered user email
params.userIdstringregistered user id
params.clientstringjanis operating client
params.languagestringlanguage used in the application
params.screenSizestringscreen size to user'device
params.screenSize.screenHeightstringuser device screen height
params.screenSize.screenWidthstringuser 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'})