Skip to content
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: Added cumulative stickiness #28642

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Sriram-bk
Copy link
Contributor

@Sriram-bk Sriram-bk commented Feb 12, 2025

Problem

This PR allows users to view stickiness cumulatively over a period of time.

Changes

Non-Cumulative

Screenshot 2025-02-14 at 11 26 57 AM

Cumulative

Screenshot 2025-02-14 at 11 27 23 AM

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

Added unit tests and tested the visual changes locally.

@Sriram-bk Sriram-bk changed the title Added cumulative stickiness feat: Added cumulative stickiness Feb 12, 2025
Copy link
Contributor

github-actions bot commented Feb 12, 2025

Size Change: -5 B (0%)

Total Size: 1.21 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.21 MB -5 B (0%)

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

14 snapshot changes in total. 0 added, 14 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@Sriram-bk Sriram-bk force-pushed the sri/feat/add-cumulative-stickiness branch from 2b05d96 to 7c82e06 Compare February 13, 2025 17:25
@Sriram-bk Sriram-bk force-pushed the sri/feat/add-cumulative-stickiness branch from a604d6c to a426298 Compare February 14, 2025 16:23
@Sriram-bk Sriram-bk requested a review from thmsobrmlr February 14, 2025 16:23
@Sriram-bk Sriram-bk marked this pull request as ready for review February 14, 2025 16:23
@posthog-bot
Copy link
Contributor

Hey @Sriram-bk! 👋
This pull request seems to contain no description. Please add useful context, rationale, and/or any other information that will help make sense of this change now and in the distant Mars-based future.

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 cumulative stickiness functionality to PostHog, allowing users to view how many users were active for at least N days rather than exactly N days.

Key changes:

  • Added new StickinessComputationMode enum with NonCumulative (default) and Cumulative options in schema
  • Created CumulativeStickinessFilter component with clear tooltips explaining the computation modes
  • Modified StickinessQueryRunner to calculate cumulative values by summing data points from current index to end when in cumulative mode
  • Added comprehensive test coverage for cumulative stickiness including hourly intervals, property filtering, and edge cases
  • Updated actor query logic to use greater-than-or-equal comparison instead of exact match when in cumulative mode

9 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +17 to +21
onChange={(value) => {
updateInsightFilter({
computedAs: value,
})
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding type safety for the value parameter in onChange. TypeScript could infer it from StickinessComputationModes

Comment on lines +1181 to +1184
export const StickinessComputationModes = {
NonCumulative: 'non_cumulative',
Cumulative: 'cumulative',
} as const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using an enum instead of a const object for better type safety and IDE support

Comment on lines +291 to +294
for i in range(len(data)):
total_for_days = sum(data[i:])
cumulative_data.append(total_for_days)
data = cumulative_data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: potential off-by-one error in cumulative calculation - verify that i:end slicing gives correct totals for edge cases

@posthog-bot
Copy link
Contributor

📸 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.

👉 Review this PR's diff of snapshots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants