As a user of many apps, you likely receive a lot of push notifications. You might read some but not others, perhaps because you consider the latter as spam. On the other hand, as an app developer who sends push notifications to your users, you might be concerned that your app’s notifications end up being in the bucket of spammy notifications for your users.
With Firebase Cloud Messaging (also known as FCM), you can use targeting with notifications so that your app sends notifications only to users who will find them useful. As a reminder of what FCM is: it's a no-cost service to send messages across Android, iOS, and web, and through Rest APIs, the Firebase Admin SDK, or campaigns in the Firebase Console. You can send FCM notifications to either a single device, all users of your app, or some group of users.
While sending notifications to all users might sound like a great idea, especially for events that truly pertain to everyone such as your app launching a new version, sending too many notifications leads to annoyed users who will probably skip over your messages and treat them like spam. To help send notifications that your users will actually care about, FCM has targeting capabilities that enable delivering personalized messages to subsets of your userbase.
To start off, let’s take a look at Analytics-based targeting, which includes audiences, topics, and imported segments, all intended to help you send notifications to particular user segments. All of these require Google Analytics.
Default User Properties
Out of the box, Analytics-based targeting provides targeting on some default user properties, meaning you don’t need to gather this information, because Google Analytics automatically does so for you. Default user properties include: the country or region in which a user is using the app, app version, the language with which a user is using the app, when a user first opened the app, and the last time a user engaged with the app. With these criteria, you can, for example, target users using a specific version of your app or those using your app in a specific country.
Let’s say you built an app called Summit, an outdoor activities app that helps users discover trails and plan hiking trips. Since the weather has been getting much nicer lately, you want to send a reminder to encourage users to get outdoors, but you probably don't want to send it to users who are already regularly using the app. So, you decide to send it to users who haven't opened the app for a while. For that, you can use the “last app engagement” user-targeting criteria to send a reminder to users who haven't opened the app for 2 weeks or more.
Custom User Properties
While sending reminders to just those who haven't opened the app in a while is already an improvement over sending this notification to all users, this audience is still quite broad, and the message is probably a bit too generic. Looking at the user base, you likely have hikers of all experience levels, ranging from beginners to intermediate to expert. A more personalized message would be a customized one relevant to each of these groupings, like "Explore short 1 to 3 mile hikes near you!" to beginner hikers.
How would you go about doing this? In just a few lines of code, you can set this up by first tagging our users with custom Analytics user properties such as skill level and current region.
After setting this up in the app code, you can then use Firebase Console to define custom definitions.
Once this is done, these properties can be used as targeting criteria when drafting a messaging campaign in Firebase Console.
To combine multiple properties together for even more granular targeting, you can create user audiences, which enables us to save an audience defined by a combination of properties. An example of how this could be useful for Summit could be creating a user audience that has:
- an expert skill level
- is currently located in the Northern California region
- and uses English in the app.
Similar to before, you can select the user audience as a targeting criteria when you set up the messaging campaign. Now, you are able to send messages to the experienced hikers, notifying them that overnight backpacking in Yosemite (which is in Northern California) is now open.
After setting up this messaging campaign, you can view metrics in Firebase Console and look for audience growth over time.
Audience Membership and Notification Metrics
So, by using FCM with Analytics, you’ve seen how to narrow down our messages for users through default user-targeting, custom user properties, and user audiences. Firebase keeps track of membership to each of these audiences for you, and these analytics properties, dimensions, and audiences are general to Analytics as a whole and available across various Firebase products as well. The Firebase console for Messaging provides information on the number of opened notifications and conversion metrics, which provides you with even more information on the engagement of your messaging campaign.
Limitations of Analytics-Based Targeting
Using analytics and user properties are ways to send messages to specific users, but there are some limitations. First, there is a quota on the number of custom properties you can define. Next, user properties can only be mapped to a single value. For example, a user with the
current_region tag can only be assigned to either Northern California or Pacific Northwest, but not both. To solve this problem, we can target messages via topic subscriptions.
Let's say you want to provide Summit users with a way of favoriting trails, so that they can get updates on trail conditions such as closures and inclement weather. Users might have multiple trails that they are currently considering for this upcoming weekend, so there is no easy way to map this to an Analytics user property. How will you send our users notifications based on the trails they are interested in?
Well, you can do this with FCM topics. First, you can create a trail_condition topic for each trail, and after a user favorites this trail in the app, users can be subscribed to a topic within the Summit app through client-side code.
Now when you want to send out a message, like for trail closures on the Sparky Trail, you can use the "Sparky Trail" topic as targeting criteria either through the Firebase Console or the Admin SDK.
With topics, FCM takes care of managing which of your users are subscribed to which topic and fanning out messages to your users in a timely manner keeps your infrastructure simple - imagine having to build all of this yourself! If you would like to get additional hands-on experience with topics, here is a codelab that takes you through implementing topics in a real working app.
Now, as you saw with topics, group membership is handled on the client side through subscriptions and unsubscriptions. To incorporate server-side analytics, we can use imported segments. Let’s say for Summit, you have a hiker's retreat coming up and based on a user's hiking history and trail preferences, an in-house analytics engine has already identified a group of users that would be interested in signing up for the retreat. You want to deliver a targeted invitation to these users.
To do so, you can use imported segments. Unlike targeting with Google Analytics or topics, you will have to maintain an internal database that associates each user with their corresponding FCM registration tokens for imported segments. Once the analytics engine runs on the internal database and identifies users that you would like to label as "retreat-interested-users", you can import them into BigQuery.
Once the data is imported, you can once again specify the "imported segment" as the targeting criteria for the messaging campaign for retreat-interested users. By combining FCM with BigQuery, imported segments enable a high degree of personalization for sending messages. You can incorporate server-side analytics (either off-the-shelf or in-house) to label specific groups of users. Then, through integration with FCM, you are able to directly send messages to labeled users with just a few clicks.
We have now covered five different targeting methods to improve sending engaging messages to users of an app. Using Analytics, we explored how to send notifications to users using provided user targeting criteria user properties, custom user properties, and user audiences. We then saw how users can be targeted using client side subscriptions. Lastly, we were able to identify a specific segment of users through server-side analytics and deliver notifications to them through imported segments.
Using these tools, you're able to build and deploy your targeting campaigns with just a few lines of code! FCM not only takes care of maintaining audience membership and maintaining the infrastructure necessary to fan out messages to your users but also enables devs to view conversions and engagement on the FCM Console. Using FCM's targeting capabilities, you can be more deliberate with messaging, engage users in the most effective manner, and measure messaging campaigns with intention.