Skip to main content
This is so irritating. I want to enable session replay, but not have auto capture events since they are so annoying. I use the following sdks for two reasons:
 
For some reason session replay does not work if I use this:
<script src="https://cdn.amplitude.com/script/AMPLITUDE_API_KEY.js"></script>
 
Also, I have a different api key for staging, uat and prod. Therefore I would rather add in the api key at run time in the init function.

My current setup is:
<script src="https://cdn.amplitude.com/libs/analytics-browser-2.9.0-min.js.gz"></script>
<script src="https://cdn.amplitude.com/libs/plugin-session-replay-browser-1.4.0-min.js.gz"></script>
<script>
// These are public values! :)
const AMPLITUDE_API_KEYS = {
"prod http url": "redacted",
"uat http url": "redacted",
"stg http url": "redacted",
};
 
// We will blow up our usage if this is set too high.
const AMPLITUDE_SAMPLE_RATES = {
"prod sample rate": 0.1,
"uat sample rate": 1.0,
"stg sample rate": 1.0,
};
 
// Also, dont want it to run for Playwright E2E tests on any environment.
if (
window.location.hostname in AMPLITUDE_API_KEYS &&
!navigator.webdriver // Exclude automated browsers like Playwright
) {
const sessionReplayTracking = window.sessionReplay.plugin({
sampleRate: AMPLITUDE_SAMPLE_RATESAwindow.location.hostname],
privacyConfig: {
blockSelector: o
blah blah blah
],
},
});
 
window.amplitude.add(sessionReplayTracking);
window.amplitude.init(AMPLITUDE_API_KEYS_window.location.hostname], {
autocapture: false, //this won’t work ffs
});
}
</script>
 
But auto capture is still on. I tried going into settings and turning it off (on the side), but it didn’t fix it.

The docs are basically non existent for this SDK: “https://cdn.amplitude.com/libs/analytics-browser-2.9.0-min.js.gz”
 
Does anyone know how to make this thing work? Or should I just use posthog?

 

Hi ​@Felix McCuaig, this was sitting in our pending spam folder so the question never made it into the community (likely because of the swear words which I edited out). 

 

Thanks for flagging this. You can run Session Replay without Autocapture; the issue in your snippet is the config name for your SDK version. In analytics-browser 2.9.0 the switch is defaultTracking (not autocapture). Either upgrade to 2.10.0+ and use autocapture, or keep 2.9.0 and set defaultTracking to disable the auto events while still allowing Session Replay. (Migrate from Browser SDK 1.0 to 2.0Browser SDK 2 | Amplitude)

If you stay on 2.9.0, use the third init argument for options and keep sessions on so replays link to sessions:

script src=&quot;https://cdn.amplitude.com/libs/analytics-browser-2.9.0-min.js.gz&quot;</script> script src=&quot;https://cdn.amplitude.com/libs/plugin-session-replay-browser-1.4.0-min.js.gz&quot;</script> <script> const sessionReplayTracking = window.sessionReplay.plugin({ sampleRate: 0.1 }); window.amplitude.add(sessionReplayTracking); window.amplitude.init("API_KEY", undefined, { defaultTracking: { attribution: false, pageViews: false, sessions: true, formInteractions: false, fileDownloads: false, elementInteractions: false, }, }); </script>

 

On 2.10.0+ you can use autocapture and turn everything off with one line:

amplitude.init("API_KEY", { autocapture: false });

 

Both options are documented in the Browser SDK reference; Session Replay works with the Browser SDK and doesn’t require Autocapture, but it does rely on sessions (the plugin enables session tracking by default). (Browser SDK 2 | AmplitudeSession Replay Browser SDK Plugin).

 

Lastly, the “Data > Settings > Autocapture” UI toggle only affects SDKs that support remote config. Remote config support starts at 2.10.0; 2.9.0 won’t pick up those UI changes, which is why the setting didn’t help. (Browser SDK 2 | Amplitude)

 

Hope this unblocks you!