Managing metrics at scale is hard. When an application has millions of customers, dozens of features, and multiple surfaces, it is imperative to collect data on almost all aspects of the application. This may include performance metrics to monitor efficiency, business metrics to measure feature success, and engagement metrics to get insights into how customers interact with the product. Each segment drives decision-making within different parts of the organization. Everything from feature success to pricing can be driven by these metrics, so it’s imperative our metrics are accurate. This becomes an increasing challenge as the application grows across multiple surfaces. Feature development may occur at different times, implementation decisions can become isolated, and changes can go undocumented, all while metric requirements continue to evolve.
At Audible, we took this problem head-on by creating a shared, code-enforced system for implementing new and existing metrics. We’ll walk through each step of the metric reporting life cycle.
First, let’s define some terms and talk about the “traditional” metric reporting system.
Definitions
- Metric Definition: Characterization of a metric with its corresponding attributes and metadata. Includes trigger criteria, name, type, and more.
- Shared Metrics Repository: Repository of metric definitions and attributes that are shared across surface engineering teams.
- Metric Datastore: Database used to store metric data and provide access to data analysts.
The Traditional Way
We commonly see metric reporting systems configured with the following life cycle:
- A product manager (PM) requests a new metric for a feature.
- An engineer works with the PM to define the schema of the metric.
- The engineer implements the metric on the client with a loosely typed dictionary.
- The metric’s data store is hard coded based on the metric type.
- A quality assurance engineer (QA) validates that the metric implementation is correct for that feature.
Although reliable in isolation, doing that across multiple surfaces, dozens of features, and with hundreds of stakeholders all at the same time is a different story. At Audible, customers interact with our applications from several unique client types, such as iOS, Android, Web, tablet and more. By definition, each surface adds a layer of complexity to our metrics and can reduce parity across them. This lack of consistency is driven mainly by the human error introduced in each stage of the process. An iOS engineer could misinterpret the metric requirements set by the product team, an Android engineer might forget to add a data field to the metric payload, or a Web engineer may even misspell the name of an attribute. Each mistake drives confusion and creates distrust with the application’s metrics. There has to be a better way.
The New Way
Focus Areas
We can break the life cycle down into three main areas where there is room for improvement.
- Defining the metric
- Client implementation
- Reporting to the data store
Using automation, type safety, code reviews, and more, we were able to increase reliability and consistency within each area.
Defining the Metric
Some metrics are simpler than others, but all require engineering and product stakeholders to come to an agreement on what they look like. For this step to be complete, the metric must include a name, trigger criteria, target data store, a list of attributes, and its affected surfaces. In the past, we documented these properties in plain text. We now do this in code so we can use it during implementation.
Once the PM agrees, an engineer will create a TypeScript interface for the metric. The header of the file contains metadata about the metric with tags corresponding to the required values. The body of the interface holds the attributes required for an event with a description for each.
Below is a complete metric definition:
import { AssetType } from “../Attributes/AssetType.ts”;
/**
* Start Download
*
* @Name Start Download
* @ReportTargets Datastore
* @Surfaces iOS, Android
* @TriggerCriteria Whenever a customer begins to download an asset.
*/
export interface StartDownloadMetric {
/**
* The title of the asset
*/
“Title”: string;
/**
* The type of asset
*/
“Type”: AssetType;
}This interface will be committed to the shared metrics repository, then reviewed and approved by one member of each of the affected surface engineering teams, creating a new level of accountability and trust between engineering teams. Here, that would be iOS and Android.
Get Audible Tech’s stories in your inbox
Join Medium for free to get updates from this writer.
Once the metric definition is merged into the shared repository, we use automation to document this metric and make it available for use.
Documentation
In order to make these metric definitions accessible to non-technical stakeholders, we host a documentation site with content driven directly from the shared metric repository. Each of the TypeScript interfaces and their corresponding comments are converted into documentation using TypeDoc, an open-source documentation generator. Every time we make a change to the shared repository, the documentation site is automatically updated to reflect those changes. This allows users of the site to trust that they have the most up-to-date and accurate information about our metrics.
Below is an example of a metric’s generated documentation.

Client Implementation
Now that we have our metric defined, reviewed, approved, and merged, we need to implement this metric event on the client. Rather than creating a dictionary of key value pairs and hard coding the report target that the metric should route to, we will use the interface defined in TypeScript. The problem is that surfaces tend to use different programming languages. For example, iOS uses Swift while Android uses Kotlin. Neither client code base can support TypeScript out of the box, but TypeScript has some key attributes that make it the perfect language for the base metric definitions.
TypeScript is strongly typed, allows re-usability of objects, and is intuitive to most engineers. It also allows us to use open- source code transpiler tools that support TypeScript as its base language. We used ts-json-schema-converter to convert the TypeScript into JSON Schema and then QuickType to transpile into the client’s target language. Surface engineering teams can generate a ready-to-use library of metric data classes in Swift, Kotlin, or other languages they may require.
With these generated data classes, a surface engineer only needs to populate the new object with the application’s data and pass it along to the report target specified in the metric’s definition. Attributes like the metric’s report target and name can be accessed directly from the generated data class because of its conformance to a predefined protocol.
Below is an example of this in Swift.
// Generated Data Class
struct StartDownloadMetric: Codable {
let title: String
let type: AssetType
}
// Protocol Conformance
extension StartDownloadMetric: MetricProtocol {
var name: String {
“Start Download”
}
var reportTarget: ReportTarget {
.datastore
}
}// Implementation on the Client
// Populate metric with data
let startDownloadMetric = StartDownloadMetric(title: "Becoming", type: .book)
// Send metric
track(metric: startDownloadMetric)With an implementation like this, engineers do not have to worry about missing fields, spelling mistakes, or incorrect report targets. They can trust that what they are reporting is consistent with the expectations of the rest of the stakeholders.
Reporting to the Data Store
Now that we’ve implemented the metric on the client, we need to route it to its target data source. Given that these metrics are consumed and analyzed internally by many parts of our organization, it is natural and necessary for different metric types to flow into different internal reporting systems; behavioral metrics will route to one system, while performance metrics will route to another. Each system has their own set of qualities, like speed and capacity, that make it the right fit for certain metric types. Unfortunately, each of these systems have their own client SDKs. Therefore, surface engineers would traditionally onboard and maintain these SDKs and route the metrics through the right one. Instead, we created a funnel for all of our metrics to flow through.
The track(metric:) method above batches metric events together and
sends them to our own hosted server that handles all of the routing for us. The server uses the same metric definition created earlier to determine where the metric should route to, so surface engineers can trust and validate that their metrics are making it to where they need to be.
Below is a diagram showing the flow of data.

This also makes it simple to onboard a new metric reporting system. Rather than integrating the system’s SDK into each client that aims to use it, we only need to integrate once on the server side. Once it is set up, clients can start passing metrics to the server that belongs to that system. With this in place, surface engineers can focus on building what’s important: new features.
Challenges We Faced
Although the metric overhaul was successful, we had to overcome a number of obstacles along the way.
Versioning
Versioning of metrics was a difficult challenge. Although the iOS and Android development teams try to align their feature roadmaps with each other, their sibling teams will often work on features in different sprints, which causes one team to report a metric before the other. For example, if Android needs to add a field such as “Download Location” to the Start Download Metric and iOS is not ready to report that field, the new payload would break the iOS codebase since it is not expecting to send the new attribute. To solve this, engineers create versioned files (i.e., V1, V2, V3, etc.). In our example, the iOS engineer would configure the SDK to use V1 of the Play Metric while Android would use the latest V2. They can distinguish which metrics they want to use by providing a configuration JSON file in their SDK codebase. Below is the file structure of the shared repository. As one can infer, the number of files scales linearly over time. In the future, we hope to deprecate older versions or have one version of the metric and force clients to update to the latest one.