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.
<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_RATES[window.location.hostname],
privacyConfig: {
blockSelector: [
blah blah blah
],
},
});
window.amplitude.add(sessionReplayTracking);
window.amplitude.init(AMPLITUDE_API_KEYS[window.location.hostname], {
autocapture: false, //this won’t work ffs
});
}
</script>
Does anyone know how to make this thing work? Or should I just use posthog?