Track Firebase Push notification for web in console - firebase

Is there any way to track the count of successfully sent push notifications in FCM ? I can see the messages sent using Firebase console but i need to track the number of messages sent via web app to the devices.
I have tried the same using onMessaging event of firebase, tried sending direct hit for google analytics as well from service worker but without any success.
return fetch('https://www.google-analytics.com/collect', {
method: 'post',
body: payloadString
})
Also tried logEvent using following -
const analytics = firebase.analytics();
logEvent(analytics, 'web_notification', {action : 'send'});
No event is getting saved in firebase console. Is there any way I can achieve the same?

You can check those data in BigQuery export. Just link your Firebase app to BigQuery. From there, you can query the messages that were successfully sent.

Related

Not able to read as well as write data in firebase database

I am using firebase cloud server to save the data of the user when using a mobile device via expo. The information is not getting saved(or read) in the firebase database. But on using firebase functions like
firebase.auth().createUserWithEmailAndPassword(email, password);
the data gets stored in the Authentication tab of firebase console.
createNewUser: (userData) => {
return firebase
.firestore()
.collection("users")
.doc(`${userData.uid}`)
.set(userData);
}
But on the running this(the code above) the information of the user is not getting saved in the firebase database.
I tried the same running on the web browser and it works just fine(storing data on database as well as on the authentication tab) but not on mobile devices. My friend has the same code and it works fine for him.
After many attempts i came to a realization that on using mobile devices, my server is not able to send information to the firebase cloud service. this is the snapshot of the no of request firebase cloud service got. The snapshot shows that it has not received an requests which is not true I have sent it many requests.
I get an error saying
Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
(Saw setTimeout with duration 3299524ms)
But the same error is being shown on my friends device so i don't think that the possible reason for the issue is this.
Can anyone tell what could be the possible issue here, please. THANK YOU

How to Connect Google Play Real-Time Developer Notifications to Firebase Cloud Function via Pub/Sub?

I'm in the final stages of development for my new mobile app, but can't seem to find a way to allow Google Play Real-Time Developer Notifications to communicate to a firebase cloud function via the recommended Google Pub/Sub method.
The expected payload flow should go as follows:
User Purchases Subscription via Play Store > Play Store sends R-T Dev Notification to Pub/Sub > Pub/Sub sends message across to firebase cloud function > Cloud function runs with payload.
I currently have an Apple Developer webhook set-up in a similar way, which webhooks a receipt payload to an iOS cloud function I have setup.
During the pub/sub setup phase, the Pub/Sub page asks to verify the cloud function URL, which I cannot do as I am not the true webmaster of cloud function domain, hence halting me about halfway down the 'Add real-time developer notification' docs that google supplies.
Is there a way to get the RT notification to either a Pub/Sub cloud function or a HTTPS cloud function bypassing the google Pub/Sub and going directly to the webhook or another way to complete the flow above?
The ultimate aim is to provide a way to ensure the purchase made is actually a valid purchase, and not a forged request made by someone intercepting the client > server webhook and submitting one of their own accord.
After creating the new topic you DO NOT have to create manually a Pub/Sub subscription as explained in the documentation.
To make it work with firebase you have to deploy a new cloud function like this:
exports.YOUR_FUNCTION_NAME = functions.pubsub.topic('YOUR_TOPIC_NAME').onPublish((message) => {
// Decode the PubSub Message body.
const messageBody = message.data ? Buffer.from(message.data, 'base64').toString() : null;
// Print the message in the logs.
console.log(`Hello ${messageBody || 'World'}!`);
return null;
});
Please note that you need to replace YOUR_FUNCTION_NAME and YOUR_TOPIC_NAME.
When the deploy of this function finish, you will finally find the function in the subscription list.
At this point, you can edit the params of the automatically created subscription, and you will find the url endpoint already filled with an internal url.
Here you can find an example: how to setup a PubSub triggered Cloud Function using the Firebase SDK for Cloud Functions.

Firebase console

I'm still new with Firebase cloud messaging.
Whenever I send a push notification to an app, does it get recorded in this table in the firebase console like in the image below?
That only shows notifications that you compose at the console. It doesn't show messages that you send programmatically with the Admin SDK or HTTP API.

Enabling the notification feature for my firebase app

I have made an app with the use of firebase. It is basically a chat application in which you van send and receive the text and images. I want to add a functionality in it that whenever a user sends a msg, then another user should get a notification . When I try to send a notification through the firebase console, then it is working, but when a user messages through the app, then it is not showing any notification to another user. So, can anyone tell me that how can this functionality be achieved ?Also, provide some sample code to see how things are working
You need to use cloud functions for that:
https://firebase.google.com/docs/functions
Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests
First, you can register the user to a topic:
FirebaseMessaging.getInstance().subscribeToTopic("news");
https://firebase.google.com/docs/cloud-messaging/android/topic-messaging
Then when the message is sent to the database, you can use onWrite() in cloud functions which is a database trigger to be able to send the notification.
https://firebase.google.com/docs/functions/database-events

Parameters to the Firebase Push Messaging System

I am using Firebase Push notification its works fine but i have a question what if,
I need the ability to provide parameters to the Firebase push
messaging system that will allow me to display a message that, when
clicked, goes to a specified web link - in a web view. Most
importantly, this needs to function when the user does not have the
app loaded.
Is it possible ?? I gone through the documentation of firebase but didn't get anything about it.
For sending notifications to a user when they might not have the app running, use Firebase Cloud Messaging.
For sending messages to a user when they might not have the app installed, use Firebase Dynamic Links or Invites.
May be you have to try "Advance options" under the pushnotification by sending the key value pair like following(link is parameter and you set this parameter value in firebase console):
window.FirebasePlugin.onNotificationOpen ((notification) {
if notification.link != '' && notification.tap == true
ref = cordova.InAppBrowser.open(notification.link, '_blank', 'location=yes')
window.open = cordova.InAppBrowser.open
}

Resources