1

Documentation in FCM focuses heavily on Android/iOS and my lowly webpush self is struggling with click_action.

click_action was a key which could be used in older APIs and appears to be no longer available for webpush.

The only specific reference to this is in this blog post: https://firebase.googleblog.com/2017/11/whats-new-with-fcm-customizing-messages.html which again focuses on iOS and Android.

I am looking for clarity that click_action is indeed now unsupported for webpush messages.

Nick
  • 876
  • 1
  • 14
  • 35
  • See my [answer here](https://stackoverflow.com/a/42300152/4625829). Although this is for Legacy. I don't see any reason why they'd remove this in v1 – AL. Mar 08 '18 at 16:35
  • If it is supported, it's not documented as a [WebpushConfig](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushconfig) option, config header property, or [WebpushNotification](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#WebpushNotification) option. – Bob Snyder Mar 08 '18 at 16:59

4 Answers4

2

Click_action works for me but I think it is not documented yet.

I added it in webpush -> notification -> click_action.

Edit : a new option is available in HTTP v1 API.

Adrien
  • 914
  • 7
  • 9
  • And you're using `FCM HTTP v1 API`? – Nick Jul 12 '18 at 08:20
  • Sure. Because legacy doesn't authorize all parameters for notifications. – Adrien Jul 12 '18 at 09:18
  • I can confirm `click_action` does not work in `FCM HTTP v1`. Specifically: "message": "Invalid JSON payload received. Unknown name \"click_action\" at 'message.webpush': Cannot find field. – Nick Jul 12 '18 at 11:00
  • 1
    It's work very well for me. I'm looking for why it's ok for me et not for you. {"message":{"topic":"push-test","webpush":{"notification":{"actions":[],"tag":123456,"title":"Titre de test","body":"Un contenu de notification","image":".\/images\/icon.png","badge":".\/images\/badge.png","icon":".\/images\/icon256.png","vibrate":[50,200,50],"click_action":"\/"},"data":{"time":"1531396372"},"headers":{"TTL":"60"}}}} – Adrien Jul 12 '18 at 11:51
  • Edit: hmm, I've tested using your code and it's working well. Will mark your answer as correct when I can – Nick Jul 12 '18 at 11:55
  • 3
    Add click_action in message.webpush.notification. – Adrien Jul 12 '18 at 11:58
2

Use your WebpushNotification.Builder object and call the putCustomData() method with click_action as the key and your click_action URL as the value.

With the Java Firebase Admin SDK, it looks like this:

wpnb.putCustomData("click_action", "<your_url_here>");
Marcello B.
  • 4,177
  • 11
  • 45
  • 65
BearOverflow
  • 111
  • 1
  • 8
0

You can include whatever key=>value pairs you want within the data field of your Web Push payload.

Register a notificationclick event listener in your service worker and these data values are available within the event triggered when your notification is clicked. Access your data, then execute your desired click action.

miknik
  • 5,748
  • 1
  • 10
  • 26
  • I may be misunderstanding, but `FCM HTTP v1 API` has no documentation on the use of service workers as far as I can see. – Nick Jul 12 '18 at 10:56
  • It's documentation for the FCM API so I wouldn't expect it to cover service workers. They document different types of notifications you can create here https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#Notification and there are numberous websites which explain the service workers api. Using the Web Push format gives you many more options for customising your notifications as well as tracking user interactions with them – miknik Jul 12 '18 at 20:29
-2

Confirmed by multiple sources. click_action is not currently supported for WebPush in HTTP V1 on Firebase Cloud Messaging. Sad!

Nick
  • 876
  • 1
  • 14
  • 35