Skip to main content

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:
  1. Get your Project API Key from Project Settings
  2. Note your Project ID
  3. Get your PostHog instance URL (e.g., https://app.posthog.com)

2. Connect to PostHog


3. Run Your First Query

Authentication Setup

PostHog Cloud

  1. Get API Key
    • Go to your PostHog project settings
    • Navigate to “Project API Key”
    • Copy your Project API Key
  2. Find Project ID
    • In PostHog, go to Project Settings
    • Copy the Project ID (numeric value)

Self-Hosted PostHog

  1. Get Your Instance URL
  2. Configure Connection

Query Types

The PostHog integration supports three types of queries: 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

Common Columns

Events Table
Event Properties
Person Properties

Date/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

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”
Solution: Verify your Project API Key is correct and has proper permissions. 2. “Project not found”
Solution: Check that your Project ID is correct and accessible with your API key. 3. “HogQL syntax error”
4. “Property not found”

Debugging Tips

  1. Start Simple: Begin with basic queries and add complexity gradually
  2. Check Date Ranges: Ensure your date filters return data
  3. Validate Properties: Use DESCRIBE events to see available properties
  4. Test with Limits: Use LIMIT 10 for initial testing
  5. Check API Responses: Look at raw JSON responses for debugging

Performance Optimization

  1. Use Specific Date Ranges to reduce data scanned
  2. Filter Early with WHERE clauses before aggregation
  3. Limit Results with LIMIT clauses
  4. Index on Properties that you query frequently
  5. Use Sampling for large datasets when approximate results are acceptable

Connection Issues

Advanced Usage

Custom Event Properties

Cohort Analysis

Real-time Dashboards


Getting Help

Start analyzing your product data with SyneHQ today! 🦔✨