一个带鸟类 API 的仪表盘工具
扎卡里·萨缪尔斯
2022年3月24日
电子邮件
1 min read

关键要点
Bird APIs can be combined with Python and Plotly Dash to build powerful, interactive dashboards without needing the full Bird UI.
The project demonstrates how to visualize metrics and events using Bird’s Metrics API and Events API within a custom web app.
Plotly Dash provides a quick, open-source framework for building UI elements like dropdowns, charts, and tables.
Developers can extend the tool with deliverability analytics, filtering, and pagination for richer dashboards.
Future enhancements include caching, improved UI, and integration with other Bird products or third-party APIs.
The codebase (available on GitHub) offers a strong starting point for anyone wanting to build Bird-powered dashboards or customer-facing portals.
Q&A Highlights
What is the goal of this dashboarding project?
It demonstrates how developers can use Bird APIs with Python and Plotly Dash to create data-driven dashboards that visualize campaign metrics and recent events.
Why use Plotly Dash for Bird APIs?
Dash is open source, easy to customize, and ideal for creating interactive UIs without requiring front-end expertise.
What does the dashboard display?
It visualizes time-series metrics from Bird’s Metrics API and recent event data from the Events API, with options to filter and select metrics over custom time ranges.
How can the tool be expanded further?
By adding deliverability analytics, advanced filters, data caching, and pagination for large datasets to improve performance and usability.
What skills or tools are required to run it?
Basic Python knowledge and installation of requests, dash, and pandas. An API key from Bird is required to pull data.
How does this project fit into Bird’s ecosystem?
It illustrates how Bird’s open APIs can be leveraged to create custom dashboards and reporting tools for teams or clients without access to the full platform.
这个脚本只是触及了利用 Python、Plotly Dash 和我们的 API 所能实现的可能性的表面。
将近一年前,Bird的客户成功总监Tom Mairs编写了一个邮件工具,利用Bird APIs。在这篇文章中,我从他离开的地方继续。他的工具允许定时传输任务,但如果我们想创建自己的仪表盘和事件日志呢?
也许我想为一个业务群体创建一个特定的仪表盘或一个面向客户的仪表盘,但不为用户提供对Bird UI的完全访问权限。这个脚本只是利用Python、Plotly Dash以及我们的APIs可能实现的冰山一角。构建处理高容量API数据的仪表盘时,要注意像DNS这样的基础设施组件可能成为瓶颈——我们经历过AWS DNS扩展挑战,影响了我们的数据处理能力。对于视觉工作流爱好者,你还可以探索将Flow Builder与Google Cloud Functions和Vision API整合,为你的数据处理流程添加AI驱动的自动化。
当我开始在网上搜索时,我想找到阻力最小的路径。我本可以用HTML和python自己创建所有仪表盘和UI,但在Google搜索后,我发现Plotly的Dash,它能轻松与python集成。我选择Dash的原因有两个:1) 它是开源的,2) 阅读文档后,它似乎很容易定制,适合我想做的事情。Dash是一个开源库,非常适合构建和部署具有定制用户界面的数据应用。 这使得创建UI变得极其简单。然后问题变成了,我想把这个应用程序做得多复杂?我花的时间越多,就越想添加更多功能。
对于初始项目,我想确保有一个具有可定制指标和可选择时间范围的仪表盘。最初,我从一个仪表盘开始,你只能从下拉菜单中选择一个指标。然后,随着我从同事那里得到反馈,我稍微完善了仪表盘,添加了多重选择和轴标题。我还决定为事件日志添加一个额外的标签。我达到一个令我满意的程度,为任何希望自己构建仪表盘的人提供了一个良好的起点。对于想要将实时webhook数据输入其仪表盘的开发者,请查看我们的使用Azure Functions构建webhook消费者的指南。当然,我将项目放在Github供你克隆或分叉。
入门
要访问此app,您需要确保您运行的是 python 3.10 或以上版本,并安装以下库:
requests
dash
pandas
然后,将您的 API 密钥输入到 App.py 中并运行该应用程序。它将在http://localhost:8050上运行。有关将其部署到面向公众的服务器(如 AWS)的更多信息,请参见以下资源:
Creating the Dashboard Page
创建Event Details 页面
活动详情页面稍显复杂,因为我不知道如何以一种易于阅读的方式呈现所有活动指标。我考虑过在此页面添加过滤参数,但我认为这样做会为此项目增加大量时间,因为那样表格必须是动态的(同时添加参数、回调等)。我决定显示所有活动并将时间戳放在最前面(因为如果不这样做,图表将不易阅读)。起初,我发现仅使用原始HTML,表格对眼睛来说非常困难。没有边框,也没有标题与行的颜色差异。为了使表格更易于阅读,我能够在Dash中使用CSS。
活动详情的想法几乎和仪表板相同,除了这次我调用事件API并导入所有事件。请注意,活动详情仅显示最近的10个事件(利用max_rows参数和API过滤)。这可以增加,但是我决定只显示最近的10个事件,因为显示的活动越多,API调用的时间就越长。可以进行的一项重大改进是能够在UI中分页并包含“下一页/上一页”。
要构建事件选项卡(页面),首先,我调用事件API并将JSON响应解析为数据框。然后我对数据框进行排序和重新排序,以将时间戳放在第一列。最后,通过遍历数据框构建HTML表格。
这在UI中看起来像这样。

下一步
对于想要创建自己仪表盘或事件日志的人来说,这是一个不错的开始。由于这里的可定制性,天空是无限的。
如上所述,可以进行的一些未来改进包括:
添加交付分析功能到仪表板
为仪表板添加更多过滤器
可能的缓存选择,以便不必每次都调用API来显示页面
UI 改进
为事件详情页面添加过滤和分页功能
我很感兴趣听取任何反馈或关于扩展此项目的建议。
~ Zach Samuels, Bird高级解决方案工程师




