Firebase analytics and Ionic

Firebase analytics and Ionic
Firebase analytics and Ionic

Firebase analytics and Ionic. With ionic native it is easy to add firebase to an ionic project. In this article I am going to show you how to add firebase analytics to your ionic project. Let’s Therefore jump into some learning.

STARTING AN IONIC PROJECT

Create a folder in which you are going to save your project.

Open your favourite terminal and go to the folder you created.For instance i use iTerm terminal for most of my work.

Firstly create the ionic project. The command below creates an App.The app is called MyGoogleDevApp.

ionic start MyGoogleDevApp blank

Add firebase cordova plugin

Run the following commands to add firebase cordova plugin.

ionic cordova plugin add cordova-plugin-firebasenpm install –save @ionic-native/firebase

Add the plugins the the apps module.

Add provider to implement firebase analytics

The next step is to create a provider that will implement firebase analytics so that it is used to log events to firebase in your app.

ionic generate provider FirebaseLogger

Add the provider to the app modules, if its not already there so that you do not get errors in starting up the application. Implement the code so that you can call firebase using ionic native.

constructor(public http: Http,private firebase:Firebase) {
 console.log('Hello FirebaseLoggerProvider Provider');
 }

logEvent(tag,event){
 this.firebase.logEvent(tag,event).then();
 }

After this the next step is to call the provider you created in your app in the home.ts file.

import { Component } from '@angular/core';
 import { NavController } from 'ionic-angular';
 import { FirebaseLoggerProvider } from "../../providers/firebase-logger/firebase-logger";

@Component({
 selector: 'page-home',
 templateUrl: 'home.html'
 })

 export class HomePage {
constructor(public navCtrl: NavController,private firebaselogger: FirebaseLoggerProvider) {
 this.firebaselogger.logEvent("welcome","app_open");
 }
}

In conclusion this is how simple it is to add firebase analytics to your ionic mobile app. Once done it can take several hours or even a day to start seeing the logged data. Google now links Google analytics and firebase analytics to allow users to see their logged events in firebase on the Google analytics portal. In other words you can use either firebase analytics or google analytics interchangeably.

Check out how to export json data to excel in ionic angular apps

bmukorera

Passionate software engineer with keen interest in solving world problems using technology.He has vast experience in developing enterprise solutions from Telecommunications ,Media,Banking and Consultancy.

You May Also Like

IONIC ANGULAR EXPORT EXCEL

Leave a Reply

Your email address will not be published. Required fields are marked *