After publishing your app to the app stores, it’s important to keep users engaged. When used effectively, notifications help app developers:
Increase Retention and Bring Users Back
Most apps lose many users within the first 3 days. Notifications help keep users engaged by:
Bringing them back: reminding users why the app is useful.
Reducing churn: reconnecting with users who have not opened the app for a few days.
Building habits: encouraging daily actions like learning, exercise, or checking updates.
Make Notifications Personal and Relevant
Good notifications are not random messages. They are based on user behavior and interests.
Behavior-based: sending reminders about items left in a shopping cart.
Context-aware: sharing weather updates or nearby suggestions.
User choice: letting users choose topics they want to receive, which builds trust.
Improve Conversion Rates
Notifications are one of the fastest ways to drive action and sales.
Create urgency: using limited-time offers or low-stock alerts.
Easy action: sending users directly to checkout or a feature page with one tap.
Improve User Experience
Notifications are also useful for helping users, not just selling.
Real-time updates: shipping updates, flight delays, or breaking news.
Instant confirmations: payment success or file upload completed.
User education: helping new users learn how to use the app step by step.
In this article, we will focus on marketing or promotional notifications. These are messages sent to many users at once, often grouped by specific filters such as language, device platform, region, behavior, and more.
Understanding the Expo Notifications Ecosystem
Originally, push notifications on mobile are handled by Firebase Cloud Messaging (FCM) for Android and Apple Push Notification service (APNs) for iOS. These can be tricky for new developers to set up.
Expo makes it easier with two main tools:
expo-notifications – a React Native package that helps your app receive and manage push notifications.
Expo Push API – a simple API to send notifications to one or many devices.
Even with these tools, you still need to do a few things yourself: keep track of users’ devices, save their push tokens, and decide when and to whom to send notifications.
Subscribe the device for Push notification
Device subscription means letting a user’s device receive push notifications and saving its push token so you can send notifications later.
Before subscribing a device, you need to set up FCM for Android and APNs for iOS. Expo provides clear step-by-step instructions for this setup in their documentation.
Subscribe to Expo Push Notification
To get push notifications working on a device, we use Expo Notifications. Below is a simple example showing how to register a device and get its push token:
1import { useState } from "react";
2import { Text, View, Button, Platform } from "react-native";
3import * as Device from "expo-device";
4import * as Notifications from "expo-notifications";
5import Constants from "expo-constants";
6
7Notifications.setNotificationHandler({
8 handleNotification: async () => ({
9 shouldPlaySound: false,
10 shouldSetBadge: false,
11 shouldShowBanner: true,
12 shouldShowList: true,
13 }),
14});
15
16export default function App() {
17 const [expoPushToken, setExpoPushToken] = useState("");
18
19 const handleSubscribeToPushNotification = async () => {
20 const pushToken = await registerForPushNotificationsAsync();
21 if (pushToken) {
22 /* Push token is available, Save it on your database */
23 savePushToken(pushToken);
24 setExpoPushToken(pushToken);
25 }
26 };
27
28 return (
29 <View
30 style={{
31 flex: 1,
32 alignItems: "center",
33 justifyContent: "space-around",
34 }}
35 >
36 <Text>Your expo push token: {expoPushToken}</Text>
37
38 <Button
39 title="Subscribe a to push notification "
40 onPress={handleSubscribeToPushNotification}
41 />
42 </View>
43 );
44}
45
46async function registerForPushNotificationsAsync() {
47 let token;
48
49 if (Platform.OS === "android") {
50 await Notifications.setNotificationChannelAsync("myNotificationChannel", {
51 name: "A channel is needed for the permissions prompt to appear",
52 importance: Notifications.AndroidImportance.MAX,
53 vibrationPattern: [0, 250, 250, 250],
54 lightColor: "#FF231F7C",
55 });
56 }
57
58 if (Device.isDevice) {
59 const { status: existingStatus } =
60 await Notifications.getPermissionsAsync();
61 let finalStatus = existingStatus;
62 if (existingStatus !== "granted") {
63 const { status } = await Notifications.requestPermissionsAsync();
64 finalStatus = status;
65 }
66 if (finalStatus !== "granted") {
67 alert("Failed to get push token for push notification!");
68 return;
69 }
70 // Learn more about projectId:
71 // https://docs.expo.dev/push-notifications/push-notifications-setup/#configure-projectid
72 // EAS projectId is used here.
73 try {
74 const projectId =
75 Constants?.expoConfig?.extra?.eas?.projectId ??
76 Constants?.easConfig?.projectId;
77 if (!projectId) {
78 throw new Error("Project ID not found");
79 }
80 token = (
81 await Notifications.getExpoPushTokenAsync({
82 projectId,
83 })
84 ).data;
85 console.log(token);
86 } catch (e) {
87 token = `${e}`;
88 }
89 } else {
90 alert("Must use physical device for Push Notifications");
91 }
92
93 return token;
94}
95
96async function savePushToken(pushTokeng) {
97 /* The push token must be linked to the current user to identify who should receive notifications */
98 const user = {
99 firstName: "James",
100 lastName: "Madison",
101 id: 987654,
102 pushToken,
103 };
104 /* Store user's push token for notification delivery */
105
106 // fetch("/user",{method:"PUT",body: JSON.stringify(user)})
107}Push Notification to devices
Once a device is registered and its push token is stored in your database, you’re ready to start sending notifications to specific users.
Expo makes this easy by providing a REST API for sending push notifications to one or many devices. This part usually runs on your server, and you can build it with any backend language you prefer.
1async function getDevicePushTokens() {
2 /* Implement logic to get push tokens from your database
3 * We mocked response data for the sake of simplicity
4 */
5
6 return [
7 "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
8 "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
9 "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
10 ];
11}
12async function sendPushNotification() {
13 const targetDeviceTokens = await getDevicePushTokens();
14
15 const message = {
16 to: targetDeviceTokens,
17 title: "Update to our Terms & Policy",
18 body: "Review latest updates ....",
19 };
20
21 try {
22 const response = await fetch("https://exp.host/--/api/v2/push/send", {
23 method: "POST",
24 headers: {
25 "Content-Type": "application/json",
26 },
27 body: JSON.stringify(message),
28 });
29
30 const data = await response.json();
31 console.log("Push response:", data);
32 } catch (error) {
33 console.error("Error sending push notification:", error);
34 }
35}
36
37/* send push notification */
38sendPushNotification();Successful push notification marketing goes beyond just sending alerts. To drive engagement, you need analytics for delivery and open rates, deep links that take users directly to the right screen, smart scheduling for perfect timing, and more.
With Pushbase, you get a lightweight SDK to register devices effortlessly, along with a powerful dashboard to create, schedule, and launch campaigns in just a few clicks.
