addicted20015
addicted20015

Reputation: 644

click_action attribute for web push notification through FCM

My questions is some what similar to (question) but with some differences. I am using FCM Admin SDK, but still do not see an option to send the click_action attribute for Web Push notifications. I checked out admin.messaging.NotificationMessagePayload as well, but looks like this is only applicable to Android and iOS.

As per the comments in the above questions, this click_action is not available for web push using http v1 API (and I think FCM admin SDK as well)

Please help me on how to send the click_action attribute for a web push notification using FCM Admin SDK. If there are any other workarounds, that would be helpful as well.

Thanks in advance.

Upvotes: 7

Views: 11871

Answers (3)

Saiful Islam Adar
Saiful Islam Adar

Reputation: 221

click_action which is not being used anymore. Updated one should like following:

{
"notification": {
      "title": "Message Title",
      "body": "Message body"
    },
    "webpush": {
      "fcm_options": {
        "link": "https://google.com" // This one, we can put any link here
      }
    }
}

Note: According to push notification behavior for web browsers.

If the link value points to a page that is already open in a browser tab, a click on the notification brings that tab into the foreground.
A notification click opens the page in a new tab if the page is not already open.

ref: https://firebase.google.com/docs/cloud-messaging/js/receive#setting_notification_options_in_the_send_request

Upvotes: 0

mixdev
mixdev

Reputation: 2844

There is some confusion on how to open a page once you click on the notification popup. The documentation asks to use FCMOptions link attribute however it does not correctly open the page but just brings the browser to the foreground with the last tab to focus(). The solution to this is to change the payload to use click_action.

"notification":{
   "body":"this is the notification text",
   "title":"New Notification",
   "click_action":"https://theURLyouwanttoopen.com/"
}

Check more

Upvotes: 5

rexx
rexx

Reputation: 88

I've got the same issue here.

After some trial, as Adrien said, it works but just not documented yet.

And also not included in admin SDK as well. (at least in Python, which I'm using)

Refer to another answer to the same question https://stackoverflow.com/a/52764782/1318878

You can use custom data to do it.

Here's how I create a notification with click action in Python:

notification=messaging.WebpushNotification(
    title=<your_title>,
    body=<your_body>,
    custom_data={"click_action": <your_url>}
)

Upvotes: 2

Related Questions