Using tags with push notifications from Azure Notification Hub

Dominic Burford
3 min readFeb 18, 2019

In my previous article Sending Push Notifications with Azure Notification Hub[^] I briefly described our rationale for selecting Azure Notification Hub over alternatives. I have now fully implemented an ASP.NET Web API service for sending push notifications as well as managing their associated tags.

The service provides the following functionality.

- Send push notifications to either Android or iOS devices (with or without tags)
- Adds tags
- Removes tags

If you aren’t familiar with the concept of tags where push notifications are concerned, you aren’t alone. I hadn’t heard of them either until I started working with push notifications. The concept is surprisingly simple, yet provides great flexibility in how you target where your push notifications are sent.

When a device is registered for push notifications (via code running on the device), you can optionally assign tags with the device registration. This is a list of characteristics (or interests) that the device wishes to receive push notifications about. Tags can either be set by the user (perhaps via a system preferences page where they can tick boxes to select the items they wish to receive push notifications about) or by the backend (where we can set characteristics to allow us to target specific devices(s) when sending push notifications).

In our case, we have implemented the latter i.e. we are adding tags that relate to the user’s device to allow us to send targetted push notifications. For example, we have added tags that specify the user’s ID, their company ID etc. This allows us to send a push notification to a specific user’s device (by specifying the user’s ID) or to all the user’s for a specific company (by specifying the company ID).

When a push notification is sent, you can specify a tag alongside your push notification message. The push notification is then only sent to any registered devices that have expressed an interest in that particular tag. So in our case, we can send a message to a specific user by supplying their ID as the tag. Or we can send a push notification and supply the company ID, thus ensuring that the push notification is only sent to user’s of that specific company. We can slice and dice the demographics of our user base in any way that we find meaningful by simply registering the device with the desired tag(s).

This is a powerful way of decomposing the demographics of your user base. You can now explicitly categorise your user base by the tags they have registered with. By doing so, this then allows us to send targetted push notifications, right the way down to a specific user’s device.

The service that I have implemented manages these tags, as well as providing the ability to send the push notificationsthemselves. The service therefore allows the backend to add and / or remove tags from a user’s device. For example, when a user logs in on a device, the service is invoked to register them with various tags according to the information we hold on them. Likewise, we will remove those tags when they sign out.

This process is very straight forward, yet gives us an incredible level of flexibility for sending targetted push notifications to our users. If you have’t already looked into the concept of push notification tags, then I’d definitely have a look at them. They’re a great idea.

--

--

Dominic Burford

A father, cyclist, vegetarian, atheist, geek and multiple award winning technical author. Loves real ale, fine wine and good music. All round decent chap.