question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FirebaseAnalytics.initializeFirebase is not a function on a vanilla angular project

See original GitHub issue

Describe the bug

Starting an angular vanilla project with firebase-analytics throws a initializeFirebase is not a function error. Note that Firebase itself does work (the default events), as can be seen on the xcode console and on firebase analytics debug steam.

To Reproduce

  1. run the following script
project_name="ABC"
project_id="com.company.abc"
ionic start "$project_name" "sidemenu" --type="angular" --project-id="$project_id" --package-id="$project_id" --capacitor --no-interactive
cd "$project_id"
yarn add "@capacitor-community/firebase-analytics"
mkdir www && touch www/index.html
sudo gem install cocoapods
ionic cap add "ios"
ionic cap sync
  1. Add GoogleService-Info.plist via xcode
  2. Add imports and FirebaseAnalytics.initializeFirebase per the code examples with the correct init options taken from GoogleService-Info.plist (btw, why do we need this data duplicity – it’s bug prone).

Bug

The following error appears on xcode console:

[error] - ERROR Error: Uncaught (in promise): TypeError: Z.initializeFirebase is not a function. (In 'Z.initializeFirebase(...)', 'Z.initializeFirebase' is undefined)

Expected behavior

Not to have an error.

Smartphone

  • Device: emulator iphone 8 and real iphone 8.
  • OS: iOS 13.7

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
j--wcommented, Sep 15, 2020

Sorry, I don’t think I was clear with what I was suggesting, I end up doing:

import "@capacitor-community/firebase-analytics";
import { Plugins } from "@capacitor/core";

const { FirebaseAnalytics, Device } = Plugins;
const deviceInfo = Device.getInfo();

// bunch of other stuff, call this when my app bootstraps
  if ((await deviceInfo).platform === "web") {
    FirebaseAnalytics.initializeFirebase(firebaseConfig);
  }

For ios and android it works from the plist and google-services.json without any extra JS code but I need this for local debugging and the web version.

If you look at the example you posted, it’s doing the same thing, the deviceinfo stuff is the important part.

0reactions
snekocommented, May 5, 2022

Hi,

Had also the error:

File: http://localhost/js/chunk-vendors.8a3c126f.js - Line 1626 - Msg: Firebase analytics is not initialized. Make sure initializeFirebase() is called once

I found the documentation very misleading about https://github.com/capacitor-community/firebase-analytics#migration letting me think no add(FirebaseAnalytics.class); was required to work on Android. But it is.

As pointed by @mic345 , follow https://devdactic.com/firebase-analytics-ionic/ to prevent wasting time, the steps are pretty clear! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

firebase.analytics is not a function - Stack Overflow
I am trying to add analytics to an already existing web app. I initialize Firebase Analytics as described here.
Read more >
Add Firebase to your JavaScript project - Google
Step 1: Create a Firebase project and register your app; Step 2: Install the SDK and initialize Firebase; Step 3: Access Firebase in...
Read more >
no firebase.app.app instance is currently initialized - You.com
My Angular project use Firebase authentication to verify phone number. ... plastering vanilla JS onto the dom which is usually not optimized, pollifilled, ......
Read more >
[Solved]-firebase.analytics is not a function-Reactjs
your config // Initialize Firebase let app = null; let analytics = null; isSupported().then((result) => { if (result) { app = initializeApp(firebaseConfig); ...
Read more >
How To Use Firebase Push Notification In Website Using ...
Firebase Push Notification In Pure Vanilla Javascript , Let's Get ... like (Angular, React ,Vue.js) but what if we are not using any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found