Skip to main content

Hey folks, I’m running into an issue where I can’t correctly conditionally add/remove the session replay plug in. The replays either don’t get generated or when it does, the replay is stuck at the loading spinner. 

This is the snippet where I initialize the Amplitude client in my React App.

  React.useEffect(() => {
amplitude.init(AMPLITUDE_API_KEY, {
autocapture: {
pageViews: false,
formInteractions: false,
},
});

if (internalUser) {
const sessionTrackingPlugin = sessionReplayPlugin();

amplitude.add(sessionTrackingPlugin);
}


amplitude.track(`PageView`, {
url: `${document.location.origin}${document.location.pathname}`,
path: `${document.location.pathname}`,
queryParams: fromPairs(
Array.from(new URLSearchParams(window.location.search).entries())
),
});
}, internalUser]);

I’m using the latest version of the `BrowserSDK` and the `sessionReplayPlugin`

Hi Deweyn,

Thanks for writing to Amplitude Community, happy to help!

Based on the code snippet you've provided, it seems like you're correctly initializing the Amplitude client and conditionally adding the session replay plugin. However, there are a few things you might want to check:

1. Session Replay Settings: Ensure that the sample rate is set to a value greater than 0. If you set the sample rate below `1`, Amplitude may not capture the specific session in question. You can find more details here: https://amplitude.com/docs/data/amplitude-wordpress-plugin#session-replay
2. Content Security Policy: Check for any error messages in the JavaScript console that contain the text `Content Security Policy`. If there are any, you'll need to update your site's content security policy to allow connection to Amplitude's APIs.
3. Blocked JavaScript: Browser extensions or network security policy may block the Session Replay SDK. Check your browser's developer tools to see if requests fail, and if so, add an exception for the blocked domains.

Here is an additional resource to help with troubleshooting Session Replay: https://amplitude.com/docs/session-replay/session-replay-standalone-sdk#troubleshooting

I hope this information is helpful. Let me know if you have any other questions or need further clarification.

Best,
Yosimy


P.S. Checkout upcoming events and user meetups on our events page.

Hi @Yosimy.Cortes,

Thanks for the reply! I’ve figured out my issue. I needed to add the session replay plugin prior to init and made sure I had autocapture’s `session` and `pageViews` enabled.

 

Now replays are coming in correctly.

 

Thanks for the help!

Deweyn


Hi Deweyn,

Thank you for letting us know what the issue was! I'm glad to hear that you were able to resolve it and it is working as expected now.

Please let us know if you have any other questions.

Have a great day!

Best,
Yosimy


P.S. Checkout upcoming events and user meetups on our events page.

Reply