I have developed fews apps using Phonegap/Cordova. I'd like to integrate Firebase Analytics instead of Google Analytics. Is it possible? Is there any Cordova Plugin for Firebase Analytics? Please explain.
Also I don't find web support for Firebase Analytics in the official documentation samples
Here is one firebase plugin for cordova (I'm the author)
https://github.com/arnesson/cordova-plugin-firebase
Wasted several hours on this, here is what I found:
Add app to firebase console
Installation:
cordova plugin add cordova-plugin-firebase --save
cordova plugin add cordova-android-play-services-gradle-release --save --variable PLAY_SERVICES_VERSION=16.+
cordova prepare && cordova compile
Code:
initializeAnalytics() {
window.FirebasePlugin.setAnalyticsCollectionEnabled(true); // Enables analytics collection
window.FirebasePlugin.setScreenName("Home");
window.FirebasePlugin.logEvent("select_content", { content_type: "page_view", item_id: "home" });
// window.FirebasePlugin.setUserId("user_id");
// window.FirebasePlugin.setUserProperty("name", "value");
}
Solving the build error:
I had below error:
The library com.google.firebase:firebase-analytics-impl is being requested by various other libraries at [[15.0.2,15.0.2], [16.3.0,16.3.0]], but resolves to 16.3.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
The solution was since it is resolving at 16.3.0, I changed all PLAY_SERVICES_VERSION in the entire project
change all code:
from "PLAY_SERVICES_VERSION": "15.+"
to "PLAY_SERVICES_VERSION": "16.+"
But before above, I had done:
cordova platform rm android
cordova platform add android
But, be careful to have a copy of your platform directory, maybe you did some changes in that directory, though ideally, you shouldn't, but as a beginner, you will as many other solutions suggest you do it.
Upload the app:
With all integration done, upload the app to Play console.
Check your firebase console
After several hours waiting, after some downloads happened, it showed below screenshot.
Links:
https://github.com/arnesson/cordova-plugin-firebase
https://firebase.google.com/docs/
https://firebase.google.com/docs/samples/
https://firebase.google.com/docs/libraries/
Hope that helps.
Update
I wrote the app in Cordova + Reactjs.
Now a days, it is better create in React Native Or Flutter
Another Cordova plugin, although this is only for Analytics (one: https://github.com/chemerisuk/cordova-plugin-firebase-analytics
To debug your events remember to properly configure your apps as described here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With