posthog
posthog copied to clipboard
feat(insights): Compare to arbitrary prior periods of time
Problem
The "compare to previous period" function currently only allows you to compare to the period immediately preceding what is shown on the graph.
Changes
Change the compare selector to let the user select an arbitrary time in the past to compare with
Works with trends and stickiness
The old functionality is still available as "period":
Does this work well for both Cloud and self-hosted?
Yes
How did you test this code?
Tested in dev. Wrote tests for the python date class that handles the logic.
đ¸ UI snapshots have been updated
122 snapshot changes in total. 0 added, 122 modified, 0 deleted:
chromium: 0 added, 66 modified, 0 deleted (diff for shard 2)webkit: 0 added, 56 modified, 0 deleted (diff for shard 2)
Triggered by this commit.
Size Change: +355 B (+0.03%)
Total Size: 1.06 MB
âšī¸ View Unchanged
| Filename | Size | Change |
|---|---|---|
frontend/dist/toolbar.js |
1.06 MB | +355 B (+0.03%) |
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
@thmsobrmlr Thanks for the heads up! I made those changes and wrote more thorough tests for the trends query, actors query, and stickiness query.
I saw your PR here with notes about future fixes for actors: https://github.com/PostHog/posthog/pull/22132 I'm happy to help chip away at any outstanding issues - let's sync up tomorrow at the standup or afterwards on what issues I could help resolve.
As for this PR, here's an example of the actors query working. The insight below has a 2 day compare set up.
You can then see that the actors query for current May 15th returns the same data as previous May 17th
It looks like there's another PR out there implementing some of the same stuff: https://github.com/PostHog/posthog/pull/22267
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
122 snapshot changes in total. 0 added, 122 modified, 0 deleted:
chromium: 0 added, 66 modified, 0 deleted (diff for shard 2)webkit: 0 added, 56 modified, 0 deleted (diff for shard 2)
Triggered by this commit.
đ¸ UI snapshots have been updated
37 snapshot changes in total. 0 added, 37 modified, 0 deleted:
chromium: 0 added, 23 modified, 0 deleted (diff for shard 2)webkit: 0 added, 14 modified, 0 deleted (diff for shard 2)
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
chromium: 0 added, 2 modified, 0 deleted (diff for shard 1, diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
chromium: 0 added, 2 modified, 0 deleted (diff for shard 1, diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
3 snapshot changes in total. 0 added, 3 modified, 0 deleted:
chromium: 0 added, 3 modified, 0 deleted (diff for shard 1, diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
Is this up for re-review? @aspicer Lemme know with a review request
đ¸ UI snapshots have been updated
2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
3 snapshot changes in total. 0 added, 3 modified, 0 deleted:
chromium: 0 added, 3 modified, 0 deleted (diff for shard 1, diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
đ¸ UI snapshots have been updated
2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)webkit: 0 added, 0 modified, 0 deleted
Triggered by this commit.
@thmsobrmlr @Twixes can i get a new look at this PR? it should be good to go with design and backend changes.
I have
- Replaced the UI with @Twixes's dropdown selection.
- Moved compare and compare_to onto a compareFilter and refactored accordingly
- Updated web analytics to use the new format
- Changed the front-end "all time" selector to remove compare, which the backend already does when you save
- Updated tests to include the new format
I have tested this in dev and also tested to ensure that current saved insights keep their "compare" flag when you switch from master to this branch.
Thanks, let me know if you have questions
https://github.com/PostHog/posthog/assets/1855120/fb890186-8a6d-4fb7-b893-7e4628c3795b