6 min read

How to Visualize ARPU in Stripe

ARPU gives you a single number for customer quality—but Stripe doesn't calculate it for you. You need to pull invoice and subscription data, aggregate it, and visualize the trend. Here's how to do it programmatically.

Extract Revenue Data from Stripe

Start by pulling invoices and customers from Stripe's API. You'll need the Stripe SDK or REST API access.

Authenticate with your Stripe API key

Install the Stripe SDK and initialize it with your API key (found under Settings > API keys in Stripe). Never hardcode the key—use environment variables.

javascript
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

// Verify the connection works
stripe.apiVersion = '2024-04-10'; // Pin to a recent stable version
Initialize the Stripe SDK in Node.js

Fetch all customers

Use stripe.customers.list() to retrieve your entire customer base. Stripe's API returns paginated results, so loop through all pages.

javascript
let allCustomers = [];
let hasMore = true;
let startingAfter;

while (hasMore) {
  const response = await stripe.customers.list({
    limit: 100,
    starting_after: startingAfter
  });
  
  allCustomers = allCustomers.concat(response.data);
  hasMore = response.has_more;
  if (hasMore) {
    startingAfter = response.data[response.data.length - 1].id;
  }
}

console.log(`Fetched ${allCustomers.length} customers`);
Paginate through all customers using starting_after

Fetch invoices for the period you want to measure

Use stripe.invoices.list() to get paid invoices. Filter by status: 'paid' and set your date range with created to get invoices from a specific period.

javascript
const startDate = Math.floor(new Date('2024-01-01').getTime() / 1000);
const endDate = Math.floor(new Date('2024-03-31').getTime() / 1000);

const invoices = await stripe.invoices.list({
  status: 'paid',
  created: {
    gte: startDate,
    lte: endDate
  },
  limit: 100
});

console.log(`Found ${invoices.data.length} paid invoices in Q1`);
Fetch paid invoices within a date range
Watch out: Stripe's API is paginated. If you have thousands of invoices, you'll need to handle pagination like the customer example above.

Calculate ARPU

Now aggregate the revenue and divide by your active customer count to get ARPU.

Sum revenue from invoices

Loop through invoices and add up the amount_paid field. Be careful: amounts are in cents, so divide by 100 to get dollars.

javascript
let totalRevenue = 0;
invoices.data.forEach(invoice => {
  totalRevenue += invoice.amount_paid;
});

const totalRevenueInDollars = totalRevenue / 100;
console.log(`Total revenue: $${totalRevenueInDollars.toFixed(2)}`);
Sum invoice amounts and convert from cents to dollars

Count active customers in your period

Filter customers who had an invoice in your date range. A more precise approach is to count unique customer_id values from the invoices themselves.

javascript
const uniqueCustomers = new Set();
invoices.data.forEach(invoice => {
  uniqueCustomers.add(invoice.customer);
});

const activeCustomerCount = uniqueCustomers.size;
console.log(`Active customers: ${activeCustomerCount}`);
Extract unique customer IDs from invoices

Calculate ARPU

Divide total revenue by active customer count. This gives you the average revenue per user for the period.

javascript
const arpu = totalRevenueInDollars / activeCustomerCount;
console.log(`ARPU: $${arpu.toFixed(2)}`);

const monthlyArpu = arpu / 3;
console.log(`Monthly ARPU: $${monthlyArpu.toFixed(2)}`);
Tip: Calculate ARPU for different customer segments (by plan type, country, signup date) to find your best-performing cohorts. Use invoice.lines.data to see line-item breakdowns.

Export and Visualize

Stripe doesn't have a built-in ARPU visualization. Export your calculations to a dashboard tool.

Generate monthly ARPU time series

Loop through each month, recalculate ARPU using the filtered invoices, and export as JSON or CSV for visualization.

javascript
const timeSeriesData = [];

for (let month = 1; month <= 12; month++) {
  const startDate = new Date(2024, month - 1, 1);
  const endDate = new Date(2024, month, 0);
  
  const monthlyInvoices = await stripe.invoices.list({
    status: 'paid',
    created: {
      gte: Math.floor(startDate.getTime() / 1000),
      lte: Math.floor(endDate.getTime() / 1000)
    }
  });
  
  const revenue = monthlyInvoices.data.reduce((sum, inv) => sum + inv.amount_paid, 0) / 100;
  const customers = new Set(monthlyInvoices.data.map(inv => inv.customer)).size;
  const arpu = customers > 0 ? revenue / customers : 0;
  
  timeSeriesData.push({
    month: startDate.toISOString().split('T')[0],
    arpu: arpu.toFixed(2),
    revenue: revenue.toFixed(2),
    customers: customers
  });
}

console.log(JSON.stringify(timeSeriesData, null, 2));
Calculate ARPU for each month and export as JSON

Visualize the trend

Paste your JSON into Google Sheets, Metabase, Grafana, or Tableau. Plot ARPU over time to spot growth, plateaus, or downward trends. Track it monthly to catch changes early.

Common Pitfalls

  • Counting all customers instead of active ones—include only customers who had an invoice in your period
  • Forgetting to divide Stripe's cent-based amounts by 100 for accurate dollar calculations
  • Not handling refunds—use amount_paid (net) instead of amount (gross) to account for canceled or refunded invoices
  • Measuring subscription count instead of customer count—one customer can have multiple subscriptions

Wrapping Up

You now have a working script to calculate ARPU directly from Stripe. Run it monthly to track trends and spot when customer value is rising or falling. If you want to track this automatically across tools, Product Analyst can help.

Track these metrics automatically

Product Analyst connects to your stack and surfaces the insights that matter.

Try Product Analyst — Free