feat: allow override sampling
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
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 |
@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.
Hey @armsnyder I don't think this is a breaking change...
We deal with them by avoiding them 😊
Did it break for you?
@pauldambra Good to hear haha. Yes, this caused a typescript build error:
Type error: Expected 1 arguments, but got 0.
> 67 | posthog.startSessionRecording()
| ^
Daaaaaammmmnnnnnn
OK, that's just me being bad at software
Sorry!
No worries! Thanks for the work on the library!
@pauldambra have a fix ready for this https://github.com/PostHog/posthog-js/pull/1129
@armsnyder we're just publishing 1.121.1 which should fix this
Thanks for letting us know about this! 😍