Compiling a List of Your Airship Tags

Airship (recently rebranded from Urban Airship) is a service that you can integrate into your mobile app or web application. It allows you to send push notifications to a targeted segment of your users based on a variety of filter mechanisms, including a series of Tags and Tag Groups.

You can configure custom Tag Groups through the Airship Dashboard, but Tags are created through the use of the Airship SDK in your mobile app. In this post, I’ll show you how to compile a list of your Airship Tags.

The Problem

While it’s easy to see a list of all of the Tag Groups that have been configured for a project, it’s not easy to see the full list of Tags in the Airship Dashboard. This makes discovering tags more difficult, unless someone is already familiar with the system.

I typically find myself in scenarios where I ask myself: “Was the Tag called “profile-incomplete,” “incomplete-profile,” or “insufficient-profile-data”? Oh, there it is! It was actually called “account-not-complete.”

The Airship Dashboard does have a search bar to help find Tags you might want for your message, but I find it harder to use than it should be. If I’ve already filtered the search results by the “Age” Tag Group, why can’t I see a dropdown list of the available Tag options?

The Solution

While this information might not be available through the Airship Dashboard, we can use the Airship API to determine the full list of Tags ourselves!

With the help of the Airship API, we can write a script that will generate the list of Tags for our project. To begin, we will need to install the urbanairship package. I’ll be using the urbanairship Ruby gem, but there’s also a library for Python and Java.

You can install the gem by adding the urbanairship gem in your project’s Gemfile or running the following command:

gem install urbanairship

Next, we’ll need to configure the Airship library with the App Key and App Secret for the Airship project. The App Key and App Secret for your project can be found under the Settings > APIs & Integrations section of your Airship project.


require 'urbanairship'
require 'set' # We'll use this later

# Setup Urban Airship client
UA = Urbanairship
airship = UA::Client.new(key: 'abc123', secret: '321cba')

With the client now configured with our App Key and Secret, we can acquire the full channel list.


# Retrieve channel list
channel_list = UA::ChannelList.new(client: airship)

By iterating over each channel, we can filter out any that aren’t associated with a Tag Group and store the Tag Groups/Tags that we find in a data structure. From there, we can sort and iterate over that data structure to print the information to the console.


# Get unique tags for tag groups
tags_by_group = {}
channel_list.each do |channel|
  next if channel["tag_groups"].empty?

  channel["tag_groups"].each do |key, values|
    tags_by_group[key] = Set.new if tags_by_group[key].nil?

    values.each do |v|
      tags_by_group[key] << v
    end
  end
end

# Generate output
tags_by_group.sort.each do |k, values|
  puts "#{k}:"
  values.to_a.sort.each do |v|
    puts "\t- #{v}"
  end
  puts
end

When we run this script, the output should look something like this.

tag_group_1:
    - tag_1
    - tag_2

tag_group_2:
    - tag_3
    - tag_4
    - tag_5

etc.

Seeing the full list of Tags is incredibly helpful. The process of filtering your audience is no longer a guessing game based on the Tags that you think might be there.


My full solution can be found on GitHub. Please give it a try if you think this might be useful and let me know what you think!