PostHog / PostHog/posthog

feature request(annotations): support SQL/HogQL insights, with X-axis alignment when bucketed by a date property

Open
#59,446 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement feature/annotations team/product-analytics
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:

  1. Render annotations on SQL/HogQL date-axis insights (DataVisualization line/bar charts). Today they're only rendered on Trends LineGraph.
  2. 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 annotation date_marker against 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 timestamp parameter 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:

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.