Pushpad
Articles › Pushpad, Targeting Users, Web Push Notifications

Web Push: send a notification to all users

  • # push-api
  • # targeting

Sometimes you just need to send the same notification to all users that have subscribed to your website notifications. Let's see how to achieve that.

First of all you must note that it's possible to reach only the users that have granted permission for notifications. Then you can use the Push API / Web Push to deliver the same notification (e.g. a newsletter or marketing campaign) to all the subscribers.

If you use the standard you need to make a separate HTTP POST request for each recipient: there isn't a way to send to everyone with a single request. For example if you need to reach 1M users, you will need to make 1M requests from your server (e.g. using background jobs).

Otherwise you can use Pushpad, a more advanced service for push notifications, built on top of the standard, which allows to send a notification to all subscribers with a single API request. For example, you can use a code like this in your application:

notification = Pushpad::Notification.new({ body: "Web Notification Example" })

# deliver to everyone (all users that have subscribed to your notifications)
notification.broadcast

In this way a single request, that takes a few milliseconds, can deliver the notification to millions of subscribers: all the effort of sending and collecting analytics is managed by the service.

Otherwise you can simply send the notifications manually to all subscribers from the Pushpad dashboard (no code).

You may also be interested in sending a notification to some users (i.e. reach many users with a single API request, but not all users).