Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR Error: Uncaught (in promise): Firebase analytics is not initialized. Make sure initializeFirebase() is called once #186

Open
volimpiuloyal opened this issue May 7, 2024 · 1 comment

Comments

@volimpiuloyal
Copy link

Describe the bug
Hi there!

I'm using this plugin in my Capacitor app, it works great but every time I start the app y get the following message on console

ERROR Error: Uncaught (in promise): Firebase analytics is not initialized. Make sure initializeFirebase() is called once

To Reproduce
Steps to reproduce the behavior:

  1. Open the app
  2. See the console logs

Expected behavior
Don't show any error message on the console

Screenshots

Captura de pantalla 2024-05-07 a las 16 42 49

Desktop (please complete the following information):

  • OS: Mac OS 14.4.1 (23E224)
  • Browser Chrome
  • Version 124.0.6367.119

Additional context
Plugin version: 4.0.0
Capacitor version: 4.0.0

@rtpHarry
Copy link

If you're running it in the browser while developing it then are running it on the "web" platform so you need to call this.

Alternatively you can wrap you firebase calls to confirm that this is running on device.

For my code, I don't need it on the web, its only for on device builds so I made a service that wraps my firebase calls, and skips it if its not the right platform:

import { Injectable } from '@angular/core';
import { FirebaseAnalytics } from '@capacitor-community/firebase-analytics';
import { Platform } from '@ionic/angular';

@Injectable({
  providedIn: 'root',
})
export class FirebaseAnalyticsLoggerService {
  constructor(private platform: Platform) {}

  async logEvent(name: FirebaseAnalyticsEventTypes, value: any) {
    await this.platform.ready();

    if (!this.platform.is('hybrid')) {
      console.log('Firebase Analytics aborted: not running on a device.');
      return;
    }

    try {
      const result = await FirebaseAnalytics.logEvent({ name, params: value });
      console.log('Firebase Analytics Result: ', result);
    } catch (error) {
      console.error('Firebase Analytics Error: ', error);
    }
  }
}

This is for an ionic / angular app, if you're working in something else then I believe capacitor has its own platform class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants