5 min read

How to Visualize Unique Users in PostHog

Understanding how many unique users engage with your product is fundamental to growth metrics. PostHog lets you track and visualize this in multiple ways—from the dashboard to custom queries. We'll walk through setting up tracking, building visualizations, and exporting the data programmatically.

Setting Up Unique User Tracking

First, make sure PostHog knows who your users are. You can track unique users either implicitly via event captures or explicitly by identifying them.

Capture events with a distinct ID

Every event PostHog receives needs a distinct_id to identify the user. When you call posthog.capture(), include a stable identifier—usually a user ID from your database or a generated session ID. PostHog will automatically group events from the same distinct_id as a single user.

javascript
posthog.capture('page_view', {
  'page': '/dashboard',
  'referrer': document.referrer
}, {
  'distinct_id': 'user_12345'
});
Capture an event with an explicit distinct_id

Identify users explicitly

Use posthog.identify() to attach user properties to a distinct_id. This is useful when you know the user (e.g., after login). It enriches the user profile without sending an event.

javascript
posthog.identify('user_12345', {
  'email': '[email protected]',
  'name': 'Sarah',
  'plan': 'pro',
  'signup_date': '2025-01-15'
});
Identify a user with properties

Merge anonymous users into authenticated users

PostHog generates a random distinct_id for anonymous visitors automatically. Once they log in, call posthog.identify() with the actual user ID—PostHog will merge the anonymous session into the user profile so you don't double-count.

javascript
// On login
const userId = await fetchUserIdFromDB();
posthog.identify(userId, {
  'email': email,
  'signup_source': 'google',
  'first_login': false
});
Merge anonymous user with authenticated user
Watch out: If you don't set a stable distinct_id, PostHog will create a new user for each event, inflating your unique user count.

Visualizing Unique Users in the Dashboard

Once events are flowing, build charts to see your unique user trends.

Create a Trends chart for unique users

Go to Insights > Trends. Select an event (e.g., page_view or purchase). In the chart settings, change the metric from Total events to Unique users. PostHog will count the number of distinct distinct_id values.

javascript
// This is what PostHog runs internally:
// SELECT count(DISTINCT distinct_id) FROM events 
// WHERE event = 'page_view' AND timestamp BETWEEN ? AND ?
PostHog's Unique Users metric counts distinct IDs per event

Add filters and breakdowns

Filter by user properties (e.g., plan = 'pro') to isolate a segment. Add a breakdown by $country or a custom property to see unique users split by region, plan, or any dimension.

javascript
// PostHog generates SQL for filtered, broken-down queries:
// SELECT count(DISTINCT distinct_id), properties.country FROM events 
// WHERE event = 'purchase' AND properties.plan = 'pro'
// GROUP BY properties.country
Unique purchasers by country, filtered to pro plan

Use Retention to track returning users

Retention charts show what percentage of unique users from a starting event come back and trigger a second event. This is more actionable than raw unique counts—it tells you if users stick around.

javascript
// Retention doesn't require extra code—use the UI
// Go to Insights > Retention, select a starting event (e.g., signup)
// and a returning event (e.g., page_view), set the cohort interval
Retention is built into the Insights dashboard
Tip: Save recurring visualizations to your dashboard by clicking Save to dashboard. Group them by business area (acquisition, activation, revenue) for quick stakeholder reviews.

Exporting Unique User Data via API

If you need to pull unique user counts into a spreadsheet, data warehouse, or custom app, use PostHog's Insights API.

Query the Insights API

Make a POST request to PostHog's Insights endpoint with your chart configuration. Specify the event, metric type (dau for daily active users), and date range. The API returns aggregated counts per day.

javascript
const response = await fetch(
  'https://your-instance.posthog.com/api/projects/PROJECT_ID/insights/',
  {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${POSTHOG_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      'name': 'Unique Users',
      'insight': 'TRENDS',
      'events': [{ 'id': 'page_view', 'math': 'dau' }],
      'date_from': '2025-03-01',
      'date_to': '2025-03-31'
    })
  }
);
const data = await response.json();
Query daily active users via the Insights API

Parse results and sync to your system

The API returns a results array with timestamps and counts. Map over it and log to your database, send to a warehouse, or display in a custom dashboard. Use math: 'wau' for weekly active users or math: 'mau' for monthly.

javascript
const uniqueUserCounts = data.result.map(item => ({
  'date': item[0],
  'count': item[1]
}));

// Send to your data warehouse
await sendToDataWarehouse('unique_users', uniqueUserCounts);
Extract and sync unique user counts
Tip: Use math: 'dau' (daily), math: 'wau' (weekly), or math: 'mau' (monthly) to match your reporting cadence.

Common Pitfalls

  • Forgetting to set a stable distinct_id—anonymous IDs create duplicate user records.
  • Counting total events instead of unique users—a single user may trigger the same event multiple times.
  • Not merging anonymous users into authenticated users after login—creates inflated unique user counts.
  • Setting filters at visualization time instead of in event capture—you lose the raw data in PostHog.

Wrapping Up

You now have three ways to track unique users in PostHog: via event capture with distinct_id, via dashboard visualizations with Trends and Retention charts, and via the API for programmatic access. Start with the dashboard to identify trends, then export via API if you need to share metrics across your team. If you want to track and visualize these metrics automatically across PostHog, Amplitude, and Mixpanel in one place, Product Analyst can help.

Track these metrics automatically

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

Try Product Analyst — Free