How to identify and track users on PostHog

intermediate 8 min read Updated 2026-03-18
Quick Answer

Identify and track users in PostHog by implementing the identify() method with unique user IDs and properties, then capture events using capture() methods. This allows you to link anonymous sessions to known users and track their behavior across sessions.

Prerequisites

  • PostHog account with project setup
  • Basic JavaScript or SDK knowledge
  • Website or application with PostHog installed
  • Understanding of user identification concepts

Step-by-Step Instructions

1

Install and Initialize PostHog

First, ensure PostHog is properly installed in your application. For web applications, add the PostHog snippet to your HTML or install via npm:

npm install posthog-js

Initialize PostHog with your project API key:

import posthog from 'posthog-js'
posthog.init('your-api-key', { api_host: 'https://app.posthog.com' })
Replace 'your-api-key' with your actual project API key found in PostHog settings
2

Identify Users with Unique IDs

Use the identify() method to associate a unique identifier with the current user. Call this method when a user logs in or when you have identifying information:

posthog.identify('user123', {
  email: 'user@example.com',
  name: 'John Doe',
  plan: 'premium'
})

The first parameter is the unique user ID, and the second parameter contains user properties.
Use consistent user IDs across all your systems (database ID, email, or custom identifier)
3

Set User Properties

Add or update user properties using setPersonProperties() to enrich user profiles with demographic, behavioral, or account information:

posthog.setPersonProperties({
  company: 'Acme Corp',
  role: 'admin',
  signup_date: '2026-01-15',
  trial_expires: '2026-02-15'
})

These properties will be associated with the identified user and available for analysis.
Update user properties whenever relevant information changes, such as plan upgrades or profile updates
4

Track Custom Events

Capture specific user actions using the capture() method to track behaviors and interactions:

posthog.capture('button_clicked', {
  button_name: 'signup',
  page: 'homepage',
  timestamp: new Date().toISOString()
})

Include relevant event properties to provide context for analysis and segmentation.
Use descriptive event names and consistent property naming conventions across your application
5

Handle User Sessions and Aliases

When users have multiple identifiers (like anonymous ID before login), use alias() to link them:

posthog.alias('user123')

This connects the current anonymous session with the permanent user ID. Call this immediately after identifying a user for the first time to maintain session continuity.
Only call alias() once per user to avoid creating duplicate user profiles
6

Verify Tracking in PostHog Dashboard

Navigate to ActivityLive Events in your PostHog dashboard to see real-time event data. Check that:
  • User identification events appear with correct IDs
  • Custom events show with proper properties
  • User properties are updated in person profiles

Go to People to view individual user profiles and verify data accuracy.
Use the browser developer tools console to debug PostHog calls during development
7

Configure Event Tracking for Key Actions

Set up tracking for critical user journeys and business metrics. Common events to track include:
  • User registration and login
  • Feature usage and interactions
  • Purchase or subscription events
  • Page views and navigation

Implement these systematically across your application using consistent naming and properties.
Create a tracking plan document to maintain consistency across your team and application features

Common Issues & Troubleshooting

Users not appearing in PostHog dashboard

Verify your API key is correct and check the browser network tab for failed PostHog requests. Ensure posthog.init() is called before any tracking methods.

Duplicate user profiles being created

Check that you're using consistent user IDs and only calling alias() once per user. Avoid identifying with different IDs for the same user.

Events not showing user properties

Ensure identify() is called before capturing events. User properties are only associated after identification occurs.

Missing event data or properties

Verify event names and properties are strings or simple data types. Check for JavaScript errors that might prevent PostHog calls from executing.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official PostHog website before purchasing.