Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Analytic for Phonegap/Cordova App

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

like image 347
Divyaadz Avatar asked Aug 12 '16 09:08

Divyaadz


3 Answers

Here is one firebase plugin for cordova (I'm the author)

https://github.com/arnesson/cordova-plugin-firebase

like image 148
ropsnou Avatar answered Oct 21 '22 07:10

ropsnou


Wasted several hours on this, here is what I found:

Add app to firebase console

  • Create a project
  • Add an app, use the package name (com.x.y.app)

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.

enter image description here

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

like image 24
Manohar Reddy Poreddy Avatar answered Oct 21 '22 07:10

Manohar Reddy Poreddy


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.

like image 1
Cristian Avatar answered Oct 21 '22 07:10

Cristian