In this article we'll see what are the best strategies to add web push notifications to many domains or subdomains using Pushpad.
If you provide a service such as a website builder where each customer has their own domain or subdomain, you may need to add web push notifications for each of them. Pushpad offers multiple ways to achieve this, depending on your use case.
Option 1: Create a separate sender and project for each customer
This option offers the highest level of separation. You create one sender and one project for each company website. This ensures that each company can manage its own subscribers and notifications independently (and you can even allow them to export their subscribers in the future).
Use case
This option is suitable if:
- Each company has its own domain or subdomain (e.g.
company1.yoursite.com
,company2.yoursite.com
,anothercompany.com
). - You want to allow customers to have full ownership over their push subscribers and VAPID keys.
- You deal with large customers or enterprise customers that may have particular needs in the future.
- You want strict separation between different customers.
- Most notifications are sent by customers to their end users.
Caution: Do not use this option if the different companies are under the same domain name (e.g. yoursite.com/company1
, yoursite.com/company2
) because you cannot mix different senders on the same domain.
How to implement
If you have a small number of customers, you can create a sender and project for each customer manually from the Pushpad dashboard.
Otherwise, if you have many customers and domains, use the Pushpad API to create a sender and project for each customer dynamically.
Here's an example using the Ruby library:
sender = Pushpad::Sender.create({
name: "Sender for Company1"
})
project = Pushpad::Project.create({
sender_id: sender.id,
name: "Company1",
website: "https://company1.yoursite.com"
})
notification = Pushpad::Notification.new({
body: "Hello subscribers of Company1"
})
notification.broadcast project_id: project.id
When sending notifications, each customer can have full control over their messages and audience.
Option 2: Create one sender and multiple projects
With this approach, you create one sender manually and then generate a separate project for each company using the API. While this option provides some level of separation, all projects share the same VAPID keys, meaning customers cannot export their subscribers individually.
Use case
This option is suitable if:
- Your customers are hosted under paths, such as
yoursite.com/company1
,yoursite.com/company2
. - Your customers have their own subdomains (like
company1.yoursite.com
,company2.yoursite.com
), but you don’t require strict separation. - You don’t need to allow customers to export their own subscriber data.
How to implement
Manually create one sender in Pushpad. Then use the API to create a separate project for each customer. This is similar to option 1, but uses the same sender for all the projects.
Option 3: Use a single sender and project with tags
Sometimes it is easier to have only one sender and one project and use it for all customers and domains. Then you can differentiate the subscribers of the different domains using tags.
This is the easiest setup but requires careful management of tags and targeting to avoid sending notifications to the wrong users (of another domain).
Use case
This option is best if:
- You prefer to manage only one project for simplicity.
- You don’t want to programmatically create multiple senders and projects.
- You often send notifications to the end users regardless of the company / domain they have subscribed to.
- You have thousands of small websites, each one with a few subscribers.
- You don’t need to allow customers to export their own subscriber data.
- You don't need to allow customers to manage their Pushpad project directly using the Pushpad dashboard.
- You want to easily manage the project settings and see aggregated stats for all the domains from a single place.
How to implement
Create one sender and one project manually from the Pushpad dashboard. This is simple and straightforward.
Then use tags to identify which subscribers belong to which domain:
pushpad('subscribe', function () {}, {
tags: ['domain:' + window.location.host] // e.g. 'domain:company1.yoursite.com'
});
When sending notifications, use tags to filter the recipients. For example:
notification = Pushpad::Notification.new({
body: "Hello subscribers of Company1"
})
notification.broadcast tags: ['domain:company1.yoursite.com']
Which option should you choose?
If each company has its own domain or subdomain and requires full control over their notifications and subscribers, Option 1 is the best choice.
If the customer websites share the same domain name (e.g. yoursite.com/company1
, yoursite.com/company2
) but still want a different project for each customer, you can use Option 2.
If you prefer to manage a single project for simplicity and don’t need strict separation between projects, Option 3 is a good solution.
By choosing the right approach, you can efficiently manage web push notifications across multiple customer domains using Pushpad. For more information you can also read the docs. Feel free to contact our support for assistance with your specific use case.