Getting started overview
Getting started with Pusher Beams involves a sequence of steps designed to integrate push notification capabilities into your applications. This process typically includes account registration, obtaining necessary API credentials, and then implementing client-side SDKs and server-side logic to send and receive notifications. Pusher Beams supports various platforms, including iOS, Android, and web applications, by providing dedicated SDKs for each, alongside server-side libraries for languages such as Node.js, Python, and Ruby Pusher Beams documentation.
The core objective of the getting started process is to enable you to send your first successful push notification. This initial interaction validates your setup and confirms that your application can communicate with the Pusher Beams service. Understanding the fundamental components, such as instance IDs and secret keys, is crucial for secure authentication and operation.
Below is a quick-reference guide outlining the steps to get started:
| Step | What to do | Where |
|---|---|---|
| 1. Sign Up | Create a Pusher account. | Pusher Beams homepage |
| 2. Create Beams Instance | Set up a new Beams project in the dashboard. | Pusher Dashboard |
| 3. Obtain Credentials | Retrieve your Instance ID and Secret Key. | Pusher Dashboard -> Your Beams instance settings |
| 4. Install SDK | Add the relevant SDK (e.g., iOS, Android, Web) to your client application. | Pusher Beams API reference |
| 5. Configure Client | Initialize the client-side SDK with your Instance ID. | Your client application code |
| 6. Send Notification | Use a server-side library to send a test notification. | Your server-side application code |
Create an account and get keys
To begin using Pusher Beams, the first step is to create a Pusher account. This account provides access to the Pusher Dashboard, where you manage all your Pusher services, including Beams. Navigate to the Pusher Beams homepage and follow the sign-up process. A free tier is available, which supports up to 200 daily active users and 100,000 messages per month, allowing initial development and testing without immediate cost Pusher Beams pricing details.
Once your account is created and you are logged into the Pusher Dashboard, you need to create a new Beams instance. This instance acts as a container for your push notification service. The process typically involves:
- Dashboard Navigation: From your Pusher Dashboard, locate the option to create a new app or service.
- Select Beams: Choose Pusher Beams from the available product options.
- Name Your Instance: Provide a descriptive name for your Beams instance. This helps differentiate it if you manage multiple applications.
- Region Selection: Select the geographic region for your instance. Choosing a region geographically closer to your users can help minimize latency.
After creating your Beams instance, the dashboard will display your essential API credentials: the Instance ID and the Secret Key.
- Instance ID: This public identifier is used by your client-side applications (iOS, Android, Web) to connect to your specific Beams instance. It identifies where your notifications should be routed.
- Secret Key: This private key is used by your server-side application to authenticate requests to the Beams API when sending notifications. It must be kept confidential and never exposed in client-side code, as it grants permission to send notifications through your account.
These credentials are vital for all subsequent interactions with the Pusher Beams API. The Instance ID is typically configured in your client-side SDK initialization, while the Secret Key is used in your server-side code to authorize notification send requests Pusher Beams API reference.
Your first request
Sending your first push notification with Pusher Beams involves two main components: configuring your client application to receive notifications and sending a notification from your server-side application.
Client-side setup (example: Web)
For a web application, you would integrate the Pusher Beams Web SDK. This typically involves adding the SDK script to your HTML and initializing it with your Instance ID. Before you can receive web push notifications, your application needs to request notification permission from the user and register a service worker. Service workers are essential for web push as they can intercept network requests and deliver notifications even when the browser tab is closed Mozilla's Service Worker API documentation.
<!DOCTYPE html>
<html>
<head>
<title>Pusher Beams Web Quickstart</title>
</head>
<body>
<h1>Web Push Notification Test</h1>
<script src="https://js.pusher.com/beams/1.0/beams.min.js"></script>
<script>
const beamsClient = new PusherPushNotifications.Client({
instanceId: 'YOUR_INSTANCE_ID',
});
beamsClient.start()
.then(() => beamsClient.addDeviceInterest('hello'))
.then(() => console.log('Successfully registered and subscribed!'))
.catch(console.error);
</script>
</body>
</html>
Replace 'YOUR_INSTANCE_ID' with your actual Instance ID from the Pusher Dashboard. This client-side code initializes the Beams client, starts the push notification service, and subscribes the device to an 'interest' called 'hello'. Interests are channels or topics to which devices can subscribe, allowing targeted notification delivery.
Server-side setup (example: Node.js)
To send a notification, you'll use a server-side library. Here's an example using Node.js:
const PusherPushNotifications = require('@pusher/push-notifications-server');
const beamsClient = new PusherPushNotifications({
instanceId: 'YOUR_INSTANCE_ID',
secretKey: 'YOUR_SECRET_KEY',
});
beamsClient.publishToInterests(['hello'], {
web: {
notification: {
title: 'Hello from Pusher Beams!',
body: 'This is your first web push notification.',
icon: 'https://pusher.com/static_assets/beams/logo.png',
deepLink: 'https://pusher.com',
},
},
})
.then(() => console.log('Push notification sent successfully!'))
.catch(error => console.error('Error sending push notification:', error));
In this Node.js example, replace 'YOUR_INSTANCE_ID' and 'YOUR_SECRET_KEY' with your actual credentials. This script initializes the server-side Beams client and then calls publishToInterests to send a notification to all devices subscribed to the 'hello' interest. The web object within the payload defines the content and behavior of the web push notification, including title, body, icon, and a deep link.
After running both the client-side and server-side code, your web application (with appropriate user permission) should receive the 'Hello from Pusher Beams!' notification.
Common next steps
After successfully sending your first notification, consider these common next steps to further integrate and optimize Pusher Beams:
- User Authentication: Implement user-specific notifications by associating device interests with authenticated users. This typically involves using the Beams Authenticated Users feature, allowing you to send notifications directly to specific users rather than general interests. Refer to the Pusher Beams API reference for details on user authentication.
- Advanced Targeting: Explore more sophisticated notification targeting using multiple interests, user IDs, or segments. Pusher Beams allows you to combine interests to reach specific user groups or exclude others.
- Notification Customization: Customize notification payloads with rich media, action buttons, and platform-specific options. This enhances user engagement and provides more interactive experiences.
- Error Handling and Logging: Implement robust error handling in both your client and server applications to gracefully manage potential issues with notification delivery or reception. Log relevant events for debugging and monitoring.
- Analytics and Monitoring: Utilize the Pusher Dashboard to monitor notification delivery rates, engagement metrics, and potential failures. This data is crucial for understanding user behavior and optimizing your notification strategy.
- A/B Testing: Experiment with different notification messages, timing, and targeting strategies to determine what resonates best with your audience.
- Platform-Specific Features: Dive into platform-specific configurations for iOS and Android, such as notification channels (Android) or notification service extensions (iOS), to take full advantage of native notification capabilities Google's Android Messaging documentation.
- Scalability Considerations: As your user base grows, review your current setup to ensure it can scale effectively. Pusher Beams is designed for scalability, but your application's architecture also plays a role.
Troubleshooting the first call
Encountering issues during your first interaction with Pusher Beams is common. Here are some troubleshooting steps:
- Check Credentials: Double-check that your Instance ID and Secret Key are correct and match the values in your Pusher Dashboard. A common mistake is using the wrong key for the client or server.
- Network Connectivity: Ensure both your client device and server have active internet connections and are not blocked by firewalls or proxies from reaching Pusher Beams endpoints.
- Client-Side Permissions: For web push, confirm that the browser has granted notification permissions. For mobile, verify that your app has requested and received the necessary system permissions for push notifications.
- Service Worker Registration (Web): For web push, ensure your service worker is correctly registered and active. Open browser developer tools, go to the 'Application' tab, and check 'Service Workers'.
- Interest Subscription: Verify that your client application has successfully subscribed to the interest you are publishing to (e.g., 'hello'). Check client-side console logs for any errors during subscription.
- Server-Side Errors: Examine your server-side application logs for any errors reported by the Pusher Beams SDK during the publish operation. These errors often provide specific clues about authentication failures or invalid payloads.
- Payload Format: Ensure your notification payload adheres to the expected JSON structure specified in the Pusher Beams API reference. Incorrectly formatted payloads can lead to rejection.
- Pusher Dashboard Logs: The Pusher Dashboard provides logs for your Beams instance. Check these logs for insights into received publish requests, delivery attempts, and any errors encountered by the Pusher Beams service itself.
- SDK Versions: Ensure you are using up-to-date versions of both client and server-side SDKs. Outdated SDKs might have compatibility issues or missing features.
- Review Documentation: Refer to the specific Pusher Beams documentation for your chosen client platform (iOS, Android, Web) and server-side language for platform-specific troubleshooting tips.