The Insight resource allows you to create and manage analytics insights for tracking events, funnels, retention, and other metrics in PostHog.
Example Usage#
Basic Trends Insight#
Signup Tracking#
Retention Analysis#
Insight on Dashboard#
Insight with Tags#
Funnel Analysis#
Resource Properties#
Required Arguments#
queryJson(string): Raw JSON serialized query payload accepted by PostHog (e.g.,InsightVizNodewith aTrendsQuery)
Optional Arguments#
name(string): Insight namedescription(string): Insight descriptiondashboardIds(number[]): List of dashboard IDs to add the insight tocreateInFolder(string): Folder where the insight is createdtags(string[]): List of tags to apply to the insightdeleted(boolean): Whether the insight is deleted (soft delete)derivedName(string): Insight derived name (auto-generated by PostHog when name is not set)
Attributes#
insightId: Numeric insight IDname: Insight namederivedName: Auto-generated insight name
Query Types#
PostHog supports several query types:
TrendsQuery#
Track event volumes over time:
FunnelsQuery#
Analyze conversion funnels:
RetentionQuery#
Measure user retention:
Best Practices#
1. Use Descriptive Names#
2. Add to Relevant Dashboards#
3. Use Tags for Organization#
Common Use Cases#
User Engagement Tracking#
Feature Adoption#
Conversion Tracking#
Troubleshooting#
Invalid Query JSON#
Issue: Error creating insight with invalid query
Solution:
- Ensure
queryJsonis a valid JSON string - Use
JSON.stringify()to convert objects to JSON strings - Validate query structure matches PostHog's query schema
Insight Not Showing Data#
Issue: Insight created but shows no data
Solution:
- Verify the event name exists in PostHog
- Check the date range includes data
- Confirm events are being captured
Dashboard Assignment Fails#
Issue: Cannot add insight to dashboard
Solution:
- Use numeric dashboard IDs (from PostHog)
- Ensure dashboard exists before creating insight
- Verify you have access to the dashboard