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: different default and max idle period #1558

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

pauldambra
Copy link
Member

@pauldambra pauldambra commented Nov 26, 2024

allow configuring an idle timeout larger than the default

see https://posthog.slack.com/archives/C07RUA1TBT3/p1732619524510359

the motivation for the user here is that their product might be used by someone before they leave for the day, and then once they return, and those two interactions are logically one session. the second might follow-on from the first.

Copy link

vercel bot commented Nov 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Nov 26, 2024 4:50pm

Copy link

github-actions bot commented Nov 26, 2024

Size Change: +2.26 kB (+0.07%)

Total Size: 3.15 MB

Filename Size Change
dist/array.full.es5.js 255 kB +225 B (+0.09%)
dist/array.full.js 359 kB +225 B (+0.06%)
dist/array.full.no-external.js 358 kB +225 B (+0.06%)
dist/array.js 173 kB +225 B (+0.13%)
dist/array.no-external.js 172 kB +225 B (+0.13%)
dist/customizations.full.js 12.1 kB +10 B (+0.08%)
dist/main.js 173 kB +225 B (+0.13%)
dist/module.full.js 359 kB +225 B (+0.06%)
dist/module.full.no-external.js 358 kB +225 B (+0.06%)
dist/module.js 173 kB +225 B (+0.13%)
dist/module.no-external.js 172 kB +225 B (+0.13%)
ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 206 kB
dist/dead-clicks-autocapture.js 14.3 kB
dist/exception-autocapture.js 9.37 kB
dist/external-scripts-loader.js 2.29 kB
dist/recorder-v2.js 115 kB
dist/recorder.js 115 kB
dist/surveys-preview.js 57.6 kB
dist/surveys.js 63.2 kB
dist/tracing-headers.js 1.75 kB
dist/web-vitals.js 10.3 kB

compressed-size-action

@@ -427,7 +427,7 @@ export class PostHog {
this._retryQueue = new RetryQueue(this)
this.__request_queue = []

this.sessionManager = new SessionIdManager(this.config, this.persistence)
this.sessionManager = new SessionIdManager(this)
Copy link
Member Author

Choose a reason for hiding this comment

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

chose to pass in the posthog instance rather than pass in this.register

Comment on lines +14 to +17
export const DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS = 30 * 60 // 30 minutes
export const MAX_SESSION_IDLE_TIMEOUT_SECONDS = 10 * 60 * 60 // 10 hours
const MIN_SESSION_IDLE_TIMEOUT_SECONDS = 60 // 1 minute
const SESSION_LENGTH_LIMIT_MILLISECONDS = 24 * 3600 * 1000 // 24 hours
Copy link
Member Author

Choose a reason for hiding this comment

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

renamed these since they have different units
added DEFAULT and MAX as separate values

Copy link
Member Author

Choose a reason for hiding this comment

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

picked ten hours as the new max but 🤷

Copy link
Member

Choose a reason for hiding this comment

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

Fine w/ me, the sessions table queries assume 24 hours and some queries might break with sessions longer than that, but anything up to and including 24 hours is fine.

MIN_SESSION_IDLE_TIMEOUT_SECONDS,
MAX_SESSION_IDLE_TIMEOUT_SECONDS,
'session_idle_timeout_seconds',
DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS
Copy link
Member Author

Choose a reason for hiding this comment

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

now the clampToRange function needs to take an arg that tells it what value to use if the provided value is invalid, previously it would use its max, but in this case we want DEFAULT not MAX

so,

  • desired > max -> max
  • desired < min -> min
  • desired in range -> desired
  • desired is invalid -> default (not max)

@pauldambra pauldambra requested a review from robbie-c November 26, 2024 16:50
@pauldambra
Copy link
Member Author

tagging @robbie-c too in case this would be bad for sessions table

@pauldambra pauldambra changed the title chore: different default and max idle period feat: different default and max idle period Nov 26, 2024
@pauldambra pauldambra added the bump minor Bump minor version when this PR gets merged label Nov 26, 2024
@pauldambra pauldambra merged commit 9de949e into main Nov 28, 2024
18 checks passed
@pauldambra pauldambra deleted the chore/different-max-and-default-idle-period branch November 28, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants