-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add goal lines to trends + smarter default alerts #28461
feat: Add goal lines to trends + smarter default alerts #28461
Conversation
@mariusandra Pinging you because you're the kea resident. If you look at my video you'll see we're querying every time I change a value in the goal line input (including the label name). Any suggestion on how we could delay updating the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR adds goal lines functionality to trends insights and improves alert creation by inheriting threshold values from goal lines. Here's a concise summary of the key changes:
- Added new goal lines UI component in
DisplayTab.tsx
with label visibility controls and value inputs - Implemented goal line visualization in
LineGraph.tsx
using chart.js annotations with hover interactions - Enhanced alert creation logic in
alertFormLogic.ts
to use smallest goal line value as default threshold - Added new
goalLinesLogic.ts
to manage goal line state and operations - Integrated goal lines with existing trends insights and web vitals functionality
Key points to note:
- Added proper type handling and validation for goal line values
- Implemented synchronized state between goal lines and chart settings
- Enhanced alert modal to access insight data through
insightLogicProps
- Added support for goal line display on both left and right Y-axes
- Improved visual styling with consistent line-height for series glyphs
11 file(s) reviewed, 11 comment(s)
Edit PR Review Bot Settings | Greptile
f02641f
to
0b9016e
Compare
📸 UI snapshots have been updated62 snapshot changes in total. 0 added, 62 modified, 0 deleted:
Triggered by this commit. |
Size Change: 0 B Total Size: 1.21 MB ℹ️ View Unchanged
|
I think the quickest win you can do is to update the value In the olden days, I had a dream, where a query would look like this: const query: InsightVizNode = {
kind: NodeKind.InsightVizNode,
source: {
kind: NodeKind.TrendsQuery,
series: [
{
event: '$pageview',
name: '$pageview',
kind: NodeKind.EventsNode,
math: BaseMathType.UniqueUsers,
},
],
breakdownFilter: {
breakdown: `$feature/${featureFlag.key}`,
breakdown_type: 'event',
},
},
} and in there, the Thus this code: actions.updateQuerySource({
trendsFilter: {
...querySource?.trendsFilter,
goalLines: values.goalLines,
},
} as Partial<TrendsQuery>) would become: actions.updateQuery({
goalLines: values.goalLines,
...query
} as Partial<TrendsVizNode>) However I believe such a distinction is not made today... and I'm not sure if there's anything in place to say "shouldn't reload". |
Tried that, but it doesn't work because our
Oh, absolutely. The catch here is that the backend needs the |
I'll let @PostHog/team-product-analytics handle this, but if it gets to weds without a review I'll take another look :) |
d992149
to
c0747c1
Compare
📸 UI snapshots have been updated8 snapshot changes in total. 0 added, 8 modified, 0 deleted:
Triggered by this commit. |
You can add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @rafaeelaudibert !
Changes look good to me code wise, aside from a question I put inline. I'm only a bit worried about further complicating the insights UI, as people are already overwhelmed by it now. Also it moves the chart further down and it's now completely below the fold on a laptop. What about moving the goal lines to a button next to the alerts one?
IMO we could even move both into the "..."-menu at the top in a separate section. We wanted to have alerts more accessible in the beginning to help feature adoption though.
) | ||
|
||
editorFilterGroups = [ | ||
const editorFilterGroups: InsightEditorFilterGroup[] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? Having the distinction between left/right filters shows the intent of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just removing the unnecessary let
, but I can revert this, it doesn't impact anything besides my OCD urge to change it :)
Ah, that's great. It's not easy to find, but it definitely does the job. I'll keep it without debouncing for now.
Ah, interesting. It appears to the left for me because of my screen size I suppose? I'll see what I can do here, might simplify the UI a little. I don't want to put it at the top because this is customizing the query, while Alerts is something extraneous to the query, so it makes sense to live somewhere else. |
@thmsobrmlr https://github.com/PostHog/posthog/blob/master/frontend/src/scenes/insights/utils/queryUtils.ts#L129 mentions we need to keep the backend in sync with that code. It's linking to the wrong place, but I'll assume it's meant to link to this: It's not up-to-date anymore, would you like me to fix it, or is it intended? |
3e4717f
to
b2ca5a5
Compare
@thmsobrmlr I've hidden the goal lines + some existing settings behind a dropdown. You can see that in the new snapshots - or test locally, of course. Do you think this is mergeable now? |
9333ad7
to
dc9bbdd
Compare
📸 UI snapshots have been updated106 snapshot changes in total. 0 added, 106 modified, 0 deleted:
Triggered by this commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the filters section from the older version is better. I understand hiding the advanced options behind a dropdown but what's the rationale for including it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does it mean to have a goal line on a Number?
query={query} | ||
setQuery={setQuery as (node: InsightQueryNode) => void} | ||
/> | ||
<div className="flex flex-1 gap-2 flex-row space-between"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah - I commented on this screenshot.
What's the rationale for this change? In the screenshot examples it forces the label for InsightTestAccountFilter onto two lines which IMO looks weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saving some real estate space. It'll only wrap into two lines in smaller screens and it's still more space than we had before. Thomas' major complaint was that we were using too much space and the chart was under the fold for modern small laptops so this was my attempt to improve that slightly. Happy to revert if you aren't happy with the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will defer to @thmsobrmlr and @PostHog/team-product-analytics on this :)
📸 UI snapshots have been updated48 snapshot changes in total. 0 added, 48 modified, 0 deleted:
Triggered by this commit. |
Let's make it two colors to improve visibility
These already existed and were being used by Web Vitals, but they're now available to be edited in the UI
It's common that people will create goal lines as an indication of whether they're above the value they want to be. Because of that, when setting up a new alert from the insights page we'll now use the smallest goal line as the default value for the alert
In some smaller laptops the chart is under the fold which isn't ideal. I've moved a lot of the options under an "advanced options" dropdown. I've included the new goal lines but also some existing settings that don't need to be toggled often. I've revamped the types as well because this is was extremely outdated. There's no more concept of left/right, nor anything to do with count.
I had a feature flag locally that messed up my visualization. I've now removed it and I can clearly see I messed up in my most recent commit
70e28b4
to
194c665
Compare
📸 UI snapshots have been updated3 snapshot changes in total. 0 added, 3 modified, 0 deleted:
Triggered by this commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @rafaeelaudibert! Lot's of improvements in here.
There is one thing blocking this from merging: The flag for determining wether the GoalLines
filter should be displayed doesn't work reliably. For example the filter isn't present for a new insight. This is because the flag doesn't take defaults into account. I trust you to fix this though and am handing out a ✅ already.
Ah, interesting. It appears to the left for me because of my screen size I suppose? I'll see what I can do here, might simplify the UI a little. I don't want to put it at the top because this is customizing the query, while Alerts is something extraneous to the query, so it makes sense to live somewhere else.
Oh, I see! You seem to have feature flag insight-horizontal-controls
enabled, likely due to syncing all feature flags. That flag is an experiment and currently not rolled out to users - they'll see the version with the controls on top (just funnels are horizontal by default). The horizontal layout is also used for very small (mobile) screen sizes.
@thmsobrmlr
master
/frontend/src/scenes/insights/utils/queryUtils.ts#L129 mentions we need to keep the backend in sync with that code. It's linking to the wrong place, but I'll assume it's meant to link to this:It's not up-to-date anymore, would you like me to fix it, or is it intended?
Yup, they seem to have gotten out of sync. Feel free to fix it, or also just merge this PR and I'll do that separately.
What's the rationale for this change? In the screenshot examples it forces the label for InsightTestAccountFilter onto two lines which IMO looks weird.
I think the filters look better in the left-to-right layout (most insights), but don't look good for the funnels insight. Would be good to have the original layout there. Not a blocker for merging though.
@@ -28,9 +28,9 @@ export function WebVitalsProgressBar({ value, metric }: WebVitalsProgressBarProp | |||
// eslint-disable-next-line react/forbid-dom-props | |||
style={{ | |||
width: `${goodWidth}%`, | |||
backgroundColor: band === 'good' ? WEB_VITALS_COLORS.good : undefined, | |||
backgroundColor: band === 'good' ? `${WEB_VITALS_COLORS.good} !important` : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure why these changes are included in this PR, but I trust you to verify whether they are intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that was a fly-by
Didn't see that automatic merging is enabled @rafaeelaudibert and don't think the issues I mentioned warrant a revert. Would be great if you can follow up with a fix though. |
@thmsobrmlr Oh yikes, my bad with the automerge. I'll follow up with the small fixes :). Thank you! |
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Problem
When creating an insight from Web Vitals we are copying the thresholds over but they are not editable. Similarly, we'd love if people could easily set up alerts for web vitals with sane values.
Changes
https://www.loom.com/share/442e793b77694b8bb66e871bfb084c24?sid=5e7a71bc-5161-473a-b36f-1f4ba113e76f
Does this work well for both Cloud and self-hosted?
Yes, sir
How did you test this code?
Manually