posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

feat: allow override sampling

Open pauldambra opened this issue 1 year ago • 1 comments

Closes https://github.com/PostHog/posthog-js/issues/1065

allows calling startSessionRecording with an override config

passing {sampling: true} overrides sampling decision by setting the current session as sampled so that recording will start regardless of the sample rate

also adds ability to poll for events to fix the opt out cypress tests


while testing this i noticed that the sample rate is only stored in memory, and its presence is verified before applying sampling logic, so if a session was sampled and then the page reloaded, we'd not check that whether the session had been sampled on reload, and might re-make the decision (and so not sample the session)

so I switched to storing the sample rate in memory and added a cypress test to verify that the sampling decision survives a reload


2024-03-30 11 10 43

pauldambra avatar Mar 30 '24 11:03 pauldambra

Size Change: +2.53 kB (0%)

Total Size: 947 kB

Filename Size Change
dist/array.full.js 226 kB +636 B (0%)
dist/array.js 125 kB +632 B (+1%)
dist/es.js 125 kB +632 B (+1%)
dist/module.js 126 kB +632 B (+1%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 12.1 kB
dist/recorder-v2.js 106 kB
dist/recorder.js 106 kB
dist/surveys-module-previews.js 62 kB
dist/surveys.js 58.3 kB

compressed-size-action

github-actions[bot] avatar Mar 30 '24 11:03 github-actions[bot]

@pauldambra @marandaneto Hi, posthog user here. First time looking at this codebase. How does this library deal with breaking changes like this one? I feel like this should have been mentioned in the release notes.

armsnyder avatar Apr 10 '24 15:04 armsnyder

Hey @armsnyder I don't think this is a breaking change...

We deal with them by avoiding them 😊

Did it break for you?

pauldambra avatar Apr 10 '24 15:04 pauldambra

@pauldambra Good to hear haha. Yes, this caused a typescript build error:

Type error: Expected 1 arguments, but got 0.

> 67 |       posthog.startSessionRecording()
     |               ^

armsnyder avatar Apr 10 '24 16:04 armsnyder

Daaaaaammmmnnnnnn

OK, that's just me being bad at software

Sorry!

pauldambra avatar Apr 10 '24 16:04 pauldambra

No worries! Thanks for the work on the library!

armsnyder avatar Apr 10 '24 16:04 armsnyder

@pauldambra have a fix ready for this https://github.com/PostHog/posthog-js/pull/1129

daibhin avatar Apr 10 '24 16:04 daibhin

@armsnyder we're just publishing 1.121.1 which should fix this

Thanks for letting us know about this! 😍

pauldambra avatar Apr 10 '24 16:04 pauldambra