FirebaseAnalytics.initializeFirebase is not a function on a vanilla angular project
See original GitHub issueDescribe 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
- 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
- Add
GoogleService-Info.plist
via xcode - Add
import
s andFirebaseAnalytics.initializeFirebase
per the code examples with the correct init options taken fromGoogleService-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:
- Created 3 years ago
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, I don’t think I was clear with what I was suggesting, I end up doing:
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.
Hi,
Had also the error:
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! 😄