Overview
The PostHog integration allows you to query your PostHog analytics data using multiple approaches: HogQL (PostHog’s SQL dialect), REST API calls, and the PostHog Query API. This integration makes it easy to analyze product analytics data alongside other databases in your data stack.
Quick Start
1. Get Your PostHog Credentials
From your PostHog instance:
- Get your Project API Key from Project Settings
- Note your Project ID
- Get your PostHog instance URL (e.g., https://app.posthog.com)
2. Connect to PostHog
3. Run Your First Query
Authentication Setup
PostHog Cloud
- Get API Key
- Go to your PostHog project settings
- Navigate to “Project API Key”
- Copy your Project API Key
- Find Project ID
- In PostHog, go to Project Settings
- Copy the Project ID (numeric value)
Self-Hosted PostHog
-
Get Your Instance URL
-
Configure Connection
Query Types
The PostHog integration supports three types of queries:1. HogQL Queries (Recommended)
PostHog’s SQL dialect for querying event data:2. REST API Calls
Direct API endpoint calls:3. Query API Calls
Structured query requests:HogQL Reference
HogQL is PostHog’s SQL dialect optimized for event analytics.Basic Syntax
Key Tables
Table | Description |
---|---|
events | All tracked events with properties |
persons | User/person records with properties |
sessions | Session-level data |
recordings | Session recording metadata |
Common Columns
Events TableDate/Time Functions
Aggregation Functions
REST API Usage
Event Queries
Insights API
Persons API
Query API Usage
The Query API provides structured querying capabilities.Events Query
Trends Query
Funnel Query
Query Examples
Event Analytics
User Analytics
Product Analytics
Performance Analytics
Marketing Analytics
REST API Examples
Query API Examples
Best Practices
1. Query Performance
2. Property Access
3. Aggregations
4. API Usage
5. Error Handling
Troubleshooting
Common Errors
1. “Invalid API Key”Debugging Tips
- Start Simple: Begin with basic queries and add complexity gradually
- Check Date Ranges: Ensure your date filters return data
- Validate Properties: Use
DESCRIBE events
to see available properties - Test with Limits: Use
LIMIT 10
for initial testing - Check API Responses: Look at raw JSON responses for debugging
Performance Optimization
- Use Specific Date Ranges to reduce data scanned
- Filter Early with WHERE clauses before aggregation
- Limit Results with LIMIT clauses
- Index on Properties that you query frequently
- Use Sampling for large datasets when approximate results are acceptable
Connection Issues
Advanced Usage
Custom Event Properties
Cohort Analysis
Real-time Dashboards
Getting Help
- PostHog Documentation: PostHog Docs
- HogQL Reference: HogQL Guide
- API Reference: PostHog API Docs
- Community: PostHog Slack