Capturing Session Replay URLs for External Logging
What's on this page
About Capturing Session Replay URLs for External Logging
In addition to viewing session replays within the Qualtrics platform, you may want to link specific user sessions directly to your logging systems (like Splunk or Datadog), error-tracking tools (like New Relic), or customer support tickets.
By leveraging a simple Qualtrics API, you can programmatically retrieve the unique session playback URL for a visitor's current session and pass it to your engineering team to streamline debugging and troubleshooting. This helps enable common use cases such as:
- Debugging intermittent site errors: Pass the URL to tools like Splunk, LogRocket, or New Relic to correlate server-side logs with visual client-side behavior.
- Customer support: Automatically include the replay link in tickets generated via CRMs like Zendesk and Salesforce.
Attention: Custom coding features are provided as-is and require programming knowledge to implement. Qualtrics Support does not offer assistance or consultation on custom coding. You can always try asking our community of dedicated users instead. If you'd like to know more about our custom coding services, please contact your Qualtrics Account Executive.
Prerequisites
Before using this API, ensure the following:
- Digital Experience Analytics is enabled for your organization.
- Session replay is active within your digital project.
- The Qualtrics project JavaScript code is correctly deployed on your website.
- Your engineering team has access to a Qualtrics user account with the “Access API” user permission and the “Session” sharing permission within your digital project.
Implementing the API
Please see our API documentation for technical details.
To capture the URL and send it to an external tool, you should wrap the call in a check to ensure the Qualtrics JavaScript (QSI) and the Session Replay (SR) modules have loaded.
Example: Logging to an Error Tracking Tool
If your site encounters a JavaScript error, you can attach the Session Replay URL to the error report so your engineers can see exactly what the user did leading up to the crash.
window.addEventListener('error', function() {
if (window.QSI && QSI.API) {
const replayUrl = QSI.API.SessionRecording.getSessionSync().playbackUrl;
// Example: Sending to a tool like Sentry or a custom logger
console.log("Error detected. View session replay here: " + replayUrl);
// myLoggingTool.captureMessage("User Error", { extra: { sessionUrl: replayUrl } });
}
});Example: Storing the URL in a Support Form
If a user submits a "Contact Us" or "Bug Report" form on your site, then you can hidden-field the playback URL to give the support agent immediate context. Note that if you’re using a Qualtrics survey for your support form, then the current page URL can be captured as embedded data with the survey response.
const form = document.querySelector('#support-form');
form.addEventListener('submit', function() {
if (window.QSI && QSI.API.SessionRecording.getSessionSync()) {
const replayUrl = QSI.API.SessionRecording.getSessionSync().playbackUrl;
document.querySelector('#hidden-replay-input').value = replayUrl || "No replay available";
}
});Example: Pushing the Session Information to Your Data Layer
If you’re using a third-party analytics platform, you may want to push the session ID and replay URLs to that system to help you easily correlate Qualtrics session replays across platforms.
// Wait for Qualtrics to load
window.addEventListener('qsi_js_loaded', async function() {
try {
// Wait for the session to be initialized and get session information
const session = await window.QSI.API.SessionRecording.getSession();
// Initialize dataLayer if it doesn't exist
window.dataLayer = window.dataLayer || [];
// Push session information to Google dataLayer
window.dataLayer.push({
'event': 'dxa_session_started',
'dxa_session_id': session.sessionId,
'dxa_playback_url': session.playbackUrl
});
} catch (error) {
console.error('Failed to get DXA session information:', error);
}
});Important Considerations
Timing
The QSI.API.SessionRecording.getSessionSync() API will return "null" if called immediately upon page load, before the session has a chance to start. It is best practice to call this API inside an event listener (like a button click or error trigger).
QSI.API.SessionRecording.getSession() handles waiting for the session to start, but keep in mind it may never resolve. For example, if your project is configured to wait for your page to call the start API upon the user giving consent, and the user never actually gives consent, getSession() will never complete.
Privacy and Permissions
- Access Control: Only Qualtrics users with the "Sessions" permission in the digital project will be able to view the session via the URL. If an unauthorized user clicks the link, they will be prompted to log into their Qualtrics account, and only be shown the session if their account has proper access.
- Masking: The playback viewed via this URL will still respect all data masking rules (PII protection) configured in your project settings.
- Sampling: If a user is sampled out for a recording based on your project's sampling rate, the API will not return a URL.
Troubleshooting
This section covers commonly encountered issues and what causes them:
| Problem | Potential Cause |
|---|---|
| API returns "null" | The user was not sampled for recording, or the recording has not started yet. |
| "QSI is not defined" error | The Qualtrics JavaScript code hasn't loaded. Ensure the script is on the page, and you are checking for window.QSI before calling the function. See Detecting When the API is Ready for more information. |
| Link leads to a "Not Found" page | The session may have expired due to retention limits, or the recording was discarded because it was too short. |
That's great! Thank you for your feedback!
Thank you for your feedback!