For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.
Configure custom session matching
このページはまだあなたの言語に翻訳されていません。 現在取り組んでいますので、後でもう一度確認してください。
Custom session matching connects replays to sessions that your Amplitude project groups by an event property, such as an order ID. Send that property's value to the replay SDK so an event-based search returns the recording of the same activity.
Use this setup when your project has an event-property session definition. If your project uses the default session_id, Amplitude session matching works automatically. If your pipeline sends no session IDs, configure time-based matching instead.
Prerequisites
Minimum SDK versions
- Browser SDK Plugin:
@amplitude/plugin-session-replay-browserversion 1.10.0 or later. - Browser Standalone SDK:
@amplitude/session-replay-browserversion 1.17.0 or later. - iOS (plugin and standalone): Session Replay for iOS version 0.11.2 or later.
- Android (plugin and standalone): Session Replay for Android version 0.26.4 or later.
Access and analytics data
- Admin or Manager privileges to edit your project's session definition.
- Analytics events that include a session-defining event property. Use the same property name and session ID value throughout each session.
- The same device ID in your analytics events and replay SDK.
Constraints
- The session replay ID has the format
<deviceId>/<sessionId>. Session Replay uses/as a delimiter, so neitherdeviceIdnor custom session ID values can contain/. - Accepted characters for both
deviceIdand custom session IDs:a-z A-Z 0-9 _ - . | @ : =. - If you need an additional character, contact support.
Configure the project and matching option
Configure the project before you update the replay SDK:
- Go to Settings > Projects and select the project that receives your analytics events.
- Select Session Definitions, then Custom Session Definition.
- Under Session property, choose the event property that holds your session ID. Enter the confirmation phrase and select Save. The session definition guide describes additional timeout and start or end event conditions.
- Go to Organization Settings > Session Replay and select Match Amplitude sessions. This matching option applies to all projects in your organization. Review the session matching options before changing it.
Configure the SDK for custom session definitions
Use the instructions for your platform. Pass the same session ID value to Amplitude and Session Replay, and update the replay SDK whenever your custom session changes.
Browser SDK plugin
Configure the plugin to read the session-defining event property:
- Install the plugin with the browser plugin quickstart.
- Add a
customSessionIdcallback to the plugin configuration. Replaceyour_custom_session_id_propertywith the event property you selected in Session Definitions. - Include that property on the analytics events in your custom session. The callback extracts the value from each event.
import * as amplitude from "@amplitude/analytics-browser";
import { sessionReplayPlugin } from "@amplitude/plugin-session-replay-browser";
const sessionReplayTracking = sessionReplayPlugin({
sampleRate: 1,
customSessionId: (event) => {
const props = event.event_properties;
if (!props) {
return;
}
const sessionId = props["your_custom_session_id_property"];
return sessionId;
},
});
amplitude.add(sessionReplayTracking);
amplitude.init(AMPLITUDE_API_KEY);
The example uses a sample rate of 1 for testing. After verification, restore your production sample rate.
Standalone SDK
The browser standalone SDK accepts the custom ID directly through sessionId:
- Install the SDK with the standalone quickstart.
- Read the current session ID from your application or analytics integration. Pass that value as
sessionIdand the analytics device ID asdeviceIdwhen you initialize Session Replay. - Send the same session ID as the event property selected in Session Definitions on your analytics events.
- Call
setSessionIdwith the new value whenever your custom session changes.
import * as sessionReplay from "@amplitude/session-replay-browser";
// Replace these values with IDs from your application or analytics integration.
const deviceId = "your_analytics_device_id";
const sessionId = "your_current_custom_session_id";
await sessionReplay.init(AMPLITUDE_API_KEY, {
deviceId,
sessionId,
sampleRate: 1,
}).promise;
// Call whenever your application starts a new custom session.
await sessionReplay.setSessionId("your_next_custom_session_id").promise;
The example uses a sample rate of 1 for testing. After verification, restore your production sample rate. Refer to Standalone SDK configuration for additional options.
Mobile SDKs
The iOS and Android SDKs accept a string session ID directly instead of a callback:
- Set
customSessionIdon iOS or callsetCustomSessionIdon Android with your current session ID. For initialization and update examples, use Custom session IDs on iOS or Custom session IDs on Android. - Send the same value as the session-defining event property to Amplitude.
- Update the replay SDK with the new value whenever your custom session changes.
Verify custom session matching
- Capture a test session with a known custom session ID.
- Check that the test analytics events include the session-defining property and the expected ID value.
- Find the test replay using an event from that session. Open the replay and confirm that it shows the expected activity.
- Start another custom session with a different ID and repeat the check. Confirm that the SDK sends the new value.
If the replay doesn't match, compare the session ID and device ID in the analytics events with the values sent to Session Replay. Check the selected project property and matching option.
これは役に立ちましたか?