Search code examples
angularfirebaseionic-frameworkfirebase-analyticsionic5

Am I understanding Firebase Analytics correctly?


My goal is to integrate Ionic5(based on Angular) with Firebase analytics. I need to do it for Android, IOS and web.

The thing is that what works for IOS and Android - does not work for web.

So, my current solution - for mobile:

import { FirebaseAnalytics } from '@ionic-native/firebase-analytics/ngx';

and then use it to log events, ect:

this.fa.logEvent(name, properties); 

And if the user is from web (tried the same as for mobile - but it did not work):

import 'firebase/analytics';
import * as firebase from 'firebase/app';

and log events -         firebase.analytics().logEvent(name, properties); 

My question here: Do I understand it correctly? Should I have different ways of implementation for web and mobile for all methods (like on example)? Ex.

In constructor    (private fa: FirebaseAnalytics)

  logEvent(name: string, properties: LogEventPropertiesModel): void {
this.platform.ready().then(() => {
  if (this.isDesktop()) {
    firebase.analytics().logEvent(name, properties); // Ex: "select_content", {content_type: "page_view"}
  } else {
    this.fa.logEvent(name, properties); // Ex: "select_content", {content_type: "page_view"}
  }
  //
});

}


Solution

  • Your understanding is correct and in line with current documentation

    Firebase.Analytics leverages native implementations with iOS/Android and JS implementation for web.

    In theory you could just stick to one implementation being javascript which in case of Ionic would work across all platforms (due to web-view or browser), but native implementations allow you not to worry about another javascript code blocking main thread etc (so mostly performance reasons).