[MUSIC PLAYING] [NOTIFICATION CHIMES] DEREK CHEN: Wow, that's a lot
of notifications coming in. I wonder what that's all about. Let me take a look. Oh, wait, that's
coming from my own app. A few weeks ago, I had built
a new app called Summit. This is an outdoors
activities app that allows my users to discover
trails and plan hiking trips. I had recently just
implemented notifications. However, I realized
that messages were being sent to everyone
who's downloaded my app. This ends up being quite
spammy to all of my users. Thankfully, Firebase Messaging,
which I may or may not be an engineer on, provides
the ability to target. And today, we'll
be taking a look at how we can fix Summit
to send notifications only to those who will find
these notifications useful. Hi. My name is Derek Chen. And I am indeed a
software engineer on the Firebase Messaging team. So what is Firebase
Messaging, also known as FCM? Well, it is a
no-cost service that allows you to send messages
across Android, iOS, and web. Through the Firebase
Admin SDK, the REST APIs, and campaigns on the
Firebase Console, you can send messages
to all users of your app or specific devices. While sending to
all of your users might be a great idea,
especially for events that pertain to everyone, such
as a new version of Summit launching, we saw before that
sending too many messages ends up with annoyed
users who will end up skipping your messages or
treating them like spam. Thankfully, Firebase
Cloud Messaging has targeting capabilities
that can help. This allows you to deliver
personalized messages to subsets of your user base,
allowing you to find and send messages to those that will
find them most relevant. So instead of sending
messages to all of your users or those with
specific devices, you can target FCM notifications
to groups of users in between using Google
Analytics-based targeting, topics, and imported segments. We'll be going over each
of these in today's talk. So let's first get started
with Analytics-based targeting. Like its name implies,
for Google Analytics-based targeting, you'll need to
enable Google Analytics within your app. Let's see how we can
use Analytics-based targeting to narrow down the
users that you send messages to. So out of the box,
Analytics-based targeting already provides default
user targeting criteria, such as version, language,
country and region, first open, and last app engagement. These are very useful
when, for example, you want to target
specific users that use specific
versions of your app or are located within
a specific region. Since the weather has
gotten a lot nicer, we want to send a
reminder to our users encouraging them to get
more outdoors recently. So who should we send
this notification to? We probably don't
want to send it to users who are already
regularly using our app. So how about we
send it to those who haven't opened our app
within the past two weeks? For that, we can use
the Last App Engagement targeting criteria. This will allow us
to send a reminder to those who haven't opened our
app within the last two weeks. While sending
reminders to those who haven't opened
our app in a while is already a great improvement
over sending to everyone, this is still pretty broad. And our message is
still pretty generic. Looking at our users,
we can probably group them into more descriptive
groups, such as skill level. Looking at Summit's
users, we probably have hikers that
range from beginners to intermediate to expert. A more customized message
will be one that's personalized to each group. For example, we would
want to send beginners a message such as, explore
short one- to three-mile hikes near you. How would we go
about doing this? Well, we can set this up
using custom user properties. First, within our app,
we can tag our users with properties such as skill
level or current region. After we set this up, we can
then go to the Firebase Console in order to define
a custom definition. Once that is all
done, now we can then select this as a
targeting criteria when drafting a new messaging
campaign within the Firebase Console. And this allows us to
send messages directly to these users with
these Analytics tags. If we wanted to combine
multiple of these properties together for more
granular targeting, we can even create
a user audience. This 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
an audience that has a skill level
of expert, located within the northern
California region, and then uses the
app with English. Similar to before,
once that's all set up, we can then select
this user audience as a targeting
criteria when we're setting up a message campaign. So now we'll be able
to let our English app users that are expert hikers
located in northern California know that reservations for
backpacking in Yosemite, which is also located
in northern California, are now open. We can even track metrics
within the Firebase Console and track how our
audiences grow over time. So using Firebase
Cloud Messaging with Google
Analytics, we've seen how to customize our messages
for subsets of our users through provided user targeting
criteria, customized user properties, and user audiences. For each of these,
Firebase keeps track of membership for you. The Analytics properties,
custom dimensions, and audiences are general to
Analytics as a whole, and they're usable across
various Firebase products-- so not just Firebase
Cloud Messaging. This also allows you to view
open counts and conversion metrics within your
Firebase Messaging Console in order for you to
determine the engagement of your messaging campaigns. So using Analytics
and user properties are a great way to
customize your messages. However, there are
a few limitations. First, there's a quota on the
number of custom dimensions that you can create. Next, for your user
properties, user properties can only be mapped
to a single value. For example, the
current region can only be set as northern California
or the Pacific Northwest, but not both. This gets tricky to set up
for one-to-many relationships. To solve this
problem, let's see how we can use targeting
via topic subscriptions. Let's say, for
Summit users, we will want to provide them with
a way of favoriting trails so that they can get
updates on trail conditions, such as inclement weather
or trail closures. They may have multiple
trails that they're currently watching, so there
is no easy way to map this to an
Analytics user property. How will we send users
these notifications based on the trails that
they're interested in? Well, we can do this
using FCM topics. First, we can create a trail
condition topic for each trail. The example that
we're using here is a trail condition
for the Sparky Trail. Upon favoriting, we can
then subscribe a user to this trail
topic in the Summit app using client-side code. Once that is done, we can then
select the Sparky Trail topic as targeting criteria within the
Firebase Console or Admin SDK. You can even combine multiple
topics together using Boolean operators
via topic conditions. So with topics,
FCM also takes care of managing which of your users
is subscribed or unsubscribed to a specific topic and
fanning out your messages within a timely manner. Topics keeps your
infrastructure simple. Imagine having to build
all of this yourself. Finally, now that we saw topic
membership can be handled through client-side
subscriptions, what if we wanted to include
server-side analytics? Well, for that, we can
use imported segments. So to set up a example use
case again, for Summit, we have a hikers'
retreat coming up. Based on our users' hiking
history and trail preferences, we have to use an
in-house analytics engine and identified a
group of users who would be interested in
signing up for our retreat. How can we deliver a
targeted invitation to each of these users? Well, using imported
segments, we can do that. Unlike targeting with
Google Analytics or topics, for imported segments,
we will, however, need to maintain an
internal database that associates each user with their
corresponding FCM registration tokens. Once our analytics engine
runs on our internal database and identifies the
users that we would want to label as
retreat-interested users, we would have to import
this group into BigQuery. Data is imported into
BigQuery as two tables-- a SegmentMemberships table
and a SegmentMetadata table. For SegmentMemberships, it
contains the instance ID from each user's registration
token and segment labels. The SegmentMetadata table then
contains all segment labels and display names for use
within the Firebase Console. Once that's done,
like before, we can now select this
imported segment, retreat-interested users, as
our targeting campaign criteria. So by combining
FCM with BigQuery, imported segments allows for a
high degree of personalization for your message sends. It enables you to incorporate
server-side analytics, either in house
or out of the box, to label specific groups of
your users with segment labels. Then, through integration
with Firebase Messaging, you're able to deliver
messages to these users with just a few clicks. So that brings us to the
conclusion of targeting methods within FCM. Today we've talked about five
different targeting methods to improve how we can send
engaging messages to our users. Using Analytics, we explored
how to send notifications to users using default user
properties, custom user properties, and user audiences. Then we saw how we
can send messages to topic subscribers via
client-side subscriptions, using FCM topics. And finally, we were able to
leverage server-side analytics in order to identify,
label, and import these segments of our user base
into BigQuery for targeting through imported segments. Using these tools, you're
able to build and deploy your solutions within just a
few clicks and just a few lines of code. So now that we've
explored various ways to send notifications
to specific users, I'm going to go
back and fix Summit so that I don't end up spamming
and overburdening my users with a ton of notifications. Using FCM's targeting
capabilities, you can be more deliberate
with your messaging campaigns, send engaging messages to
relevant user segments, and measure the effectiveness
of your campaigns. I hope all of this was
helpful for all of you. I'm looking forward to
seeing how all of you can improve your messaging
with targeting within FCM. If you have any
questions for today, I will be in the
Ask Firebase lounge after this to answer
any questions. Thank you all for your time. [MUSIC PLAYING]