FCM with Gdevelop (Firebase Cloud messaging)

Is there anyone who has already tried or succeeded in using FCM with Gdevelop? I would like to incorporate it. At this moment I have manually exported it to a cordova project and imported it into android studio. I am trying to do this :

Sending push notifications

I am stuck as where to put the code that gets the registration code and does the subscribing to a topic. I would guess that could be done in Gdevelop as Javascript but I do not know exactly where. I have used Firebase for many projects now and like very much what can be done with it. Is FCM planned to become a part of Gdevelop in the future too?

I can see that apply plugin: ā€˜com.google.gms.google-servicesā€™ is already in the project thus would it be as simple as using

FirebaseInstanceId.getInstance().getInstanceId()
                        .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
        @Override
        public void onComplete(@NonNull Task<InstanceIdResult> task) {
            if (!task.isSuccessful()) {
                Log.w(TAG, "getInstanceId failed",
                task.getException());
                return;
            }

            // Get new Instance ID token
            String token = task.getResult().getToken();        
        }
    });

that code in Gdevelop? If so where would I do that best?

estoy en la mismo problema y sigo sin encontrarlo hallaste alguna manera

I did not solve it. The trouble is getting the device token. If there was a way to just get that I could sent it to my server and with a python script sent the notification messages. It has to do with the electron browser I believe. I also tried to compile it myself and change the code in android studio but I am just not savvy enough to get it to work unfortunatly. Hopefully one of the developers can come up with a solution one day. FCM would be the holy grail for my big two game as it would be able then to if users want to sent a message that their day dash is in danger for example.

It should look probably something like this

cordova.plugins.firebase.messaging.getToken().then(function(token) {
// Send the token to your server using a WebSocket or any other method
// ā€¦
console.log(ā€˜FCM device token:ā€™, token);
}).catch(function(error) {
console.error(ā€˜Error getting FCM device token:ā€™, error);
});

But that requires a firebase plugin for cordova(cordova plugin add cordova-plugin-firebase). Then the project would need to be compiled using android studio that uses it to wrap all the html/css and javascript in it.

Is there anyone that can explain better why this is not working or if it at all one day will be?

FCM is trickyā€¦

The Cordova plugin adds some interesting functionality, including this, crash analytics, native google/apple authenticationā€¦

The issue is that it is incompatibility with the web version, so you cannot for example authenticate with the mobile app then use that to access user data with the regular web SDK used for the rest of the Firebase integrationā€¦ If we run both in parallel, itā€™ll also mess up the analytics, and possibly add other issues. Firebase is already one of the most absurdly big extensions for GDevelop, so adding support for the mobile ask would double the implementation count and therefore the amount of code to maintainā€¦ They also do not have feature parity leading to some features not working on mobile, some not working on the other platformsā€¦

So we cannot easily integrate the mobile version of the sdk. Luckily, FCM also works on the web! There is a small problem thoughā€¦ It requires a service worker to handle notifications while your app is not open. GDevelopā€™s code generator is very generic, so that it can compile events to any programming language. Therefore it does not know about concepts such as a service worker, since itā€™s something specific to the web platform and therefore we cannot generate the necessary service worker codeā€¦

2 Likes

Hello, I have been looking into FCM and making it so I can send push notifications based off information as it comes into the server. I have developed what I consider a complicated app that involves users sending cards to each other. When a card is sent, I really need to get a push notification to go to the other persons phone/device. Without this the game becomes much less enjoyable considering players will just have to log on at random times and check to see if a card is sent. Alternatively a player will have to text the other to let them know or something. Either way it really takes away from my game. I notice that Gdevelop already has a thing with firebase that send a email to update their password, it seems odd to me that this can be implemented but in app purchases cannot at the moment. If you or anyone else has any ideas on how to implement this please let me know. I have tried the onesignal extension and couldnt quite get it to work and even if I can it wonā€™t have the feature I really need. Any help would be greatly appreciated.

Hi Cosmic,

Yes, weā€™ve been looking into implementing FCM as well, but as far as I understand, it currently requires manual compilation of the game to get it working. Unfortunately, we havenā€™t managed to make it work either; itā€™s beyond our expertise at this point.

I believe there are two critical features that GDevelop needs to improve retention and user engagement:

  1. Google Sign-In integration for mobile users
  2. FCM push notifications

Weā€™re struggling to keep players engaged or upgrade them from guest accounts to registered accounts. The built-in GDevelop authentication works well, but it doesnā€™t match the reach and ease of use that Google Sign-In could provide. This is an untapped opportunity right now.

I understand the challenges with these kinds of integrations. Like with all third-party services, if Google or Firebase changes their APIs, someone would need to update the implementation in GDevelop, which is a community-driven open-source platform. However, if enough of us come together on this issue, maybe we can tackle it once and for all. Iā€™m sure it would improve user retention and engagement significantly.

Technical suggestions:

  • For now, one option might be to manually export your project to a Cordova project and then integrate Firebase via the Cordova Firebase plugin (cordova-plugin-firebase). You would then handle token generation and push notifications through Firebase Cloud Messaging on the native side.
  • Another route could be exploring OneSignal further, as it is often easier to set up for push notifications compared to Firebase, especially for cross-platform apps like the ones developed in GDevelop. It might take some tweaking, but it could offer a quicker solution while we wait for native FCM support.

Hopefully, as the community grows, weā€™ll be able to push for these features to be integrated into GDevelop directly.

1 Like

Good news, there is a pending OneSignal extension (not approved yet):

Thank you very much for the detailed reply. I would love to contribute to the community and help implement push notifications. Unfortunately I have little JavaScript knowledge and I have tried to implement push notifications using your suggestion and exporting it to Cordova. Unfortunately I have had no luck yet. I will try again in the future once my app is completely done. Hopefully a solution is made as I agree that by adding FCM it would greatly improve Gdevelop. If you ever hear of a solution please let me know and I will let you know if I make any progress. Thanks!

Thank you for this. Unfortunately, I have looked at this before and briefly tried to get it to work but was unable to. I then also looked more into the details and even if I get this to work as it is intended, it will not work for my situation. I need to send push notifications based off of user actions, from what I can tell, this just allows the owner of the app to send out push notifications when they want. This wouldnā€™t necessarily work for my app specifically since I need to send notifications at random times of the day to specific people based off who sends a card to who.

1 Like