feature request(annotations): support SQL/HogQL insights, with X-axis alignment when bucketed by a date property
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 39.9k
- Forks
- 3.4k
- Avg merge
- 6h 51m
- Merged PRs (30d)
- 232
Description
Is your feature request related to a problem?
Customers using a SQL or HogQL insight to plot data bucketed by a date property (e.g. delivery_date set on the event payload, then GROUP BY toStartOfDay(properties.delivery_date)) cannot use annotations to mark significant moments on the chart. SQL/HogQL insights currently don't render annotations at all: AnnotationsOverlay is only used by the Trends LineGraph component, not by the DataVisualization charts used for SQL/HogQL insights.
This is felt acutely when the customer's analytical workflow inherently uses a property date (delivery date, order date, signup cohort date) rather than the event ingestion timestamp.
Describe the solution you'd like
Two parts:
- Render annotations on SQL/HogQL date-axis insights (DataVisualization line/bar charts). Today they're only rendered on Trends
LineGraph. - When the X-axis is a date property (not
events.timestamp), annotations should align with the property values rather than ingestion time. This likely means matching annotationdate_markeragainst the X-axis date values produced by the SQL query, not against the timestamp-derived buckets currently used.
Describe alternatives you've considered
- Adding the date logic into the SQL query as a separate series so the markers are visible inline. Workable but defeats the point of having annotations as first-class.
- Using the SDK
timestampparameter to backdate events to the property date. Possible only if every event has a one-to-one mapping with the property; not realistic when the property is set or updated after ingestion, or when the same event has multiple meaningful dates.
Additional context
Relevant code:
AnnotationsOverlayis invoked from TrendsLineGraphonly: https://github.com/PostHog/posthog/blob/master/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx#L1310- No usage of
AnnotationsOverlayanywhere underfrontend/src/queries/(the home of SQL/HogQL DataVisualization) Annotation.date_markeris a single DateTimeField: https://github.com/PostHog/posthog/blob/master/posthog/models/annotation.py- Trends overlay logic positions annotations by matching
date_markeragainst the chart'sdates[]array: https://github.com/PostHog/posthog/blob/master/frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.ts
Reported in https://posthoghelp.zendesk.com/agent/tickets/57991 (moved to PostHog: https://us.posthog.com/project/2/support/tickets/59328)
Debug info
- PostHog Cloud, Debug information: [please copy/paste from https://us.posthog.com/settings/project-details#variables]
- PostHog Hobby self-hosted with
docker compose, version/commit: [please provide] - PostHog self-hosted with Kubernetes (deprecated, see
Sunsetting Kubernetes support), version/commit: [please provide]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx and frontend/src/lib/components/AnnotationsOverlay/annotationsOverlayLogic.ts to understand the existing Trends overlay and date matching. Then inspect the SQL/HogQL DataVisualization entry points under frontend/src/queries/ and the annotation model in posthog/models/annotation.py. Done means date-axis SQL/HogQL charts render annotations and align date-property markers with the query's X-axis values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, react, sql, typescript
- Domain
- analytics, data-visualization, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 46/100