Function overview
User experience demands are rising and market competition is fierce. Business teams need to understand how users interact with their applications to optimize page design, content layout, and interaction flows. The goal is to improve the product experience and user conversion rates. Session Replay and Heatmap features provide visual and aggregated user behavior analytics. They help you quickly identify interaction barriers, optimize page layouts, and improve the user experience based on real user data.
Session Replay
Session Replay records all user operations on a page, including the following:
-
DOM changes
-
User interactions, such as clicks, inputs, and scrolls
-
Network requests
-
Page performance metrics
After a session is recorded, you can replay the complete user session in the monitoring platform. This helps you:
-
Quickly locate issues: Replay user actions to reproduce error scenarios.
-
Optimize the user experience: Observe real user paths to identify interaction problems.
-
Increase conversion rates: Analyze user behavior to optimize key flows.
Heatmap
The Heatmap feature collects user click data and generates a visual heatmap. This helps you:
-
Understand user focus: See which areas users click most often.
-
Identify dead clicks: Find areas that users click but that do not provide a response.
-
Optimize page layout: Adjust the position of page elements based on the click heatmap.
-
Improve the user experience: Reduce accidental clicks and increase operational efficiency.
Quick start
Prerequisites
You have integrated the Real User Monitoring (RUM) software development kit (SDK). The SDK version must be 0.1.5 or later. For more information, see Integrate Web & H5 applications.
Enable Session Replay
The simplest way to enable this feature is as follows:
armsRum.init({
endpoint: "your endpoint",
replay: true, // Enable session replay
});
Enable Heatmap
The Heatmap feature depends on Session Replay, which provides the background page for the heatmap. You must enable Session Replay, but no specific sample rate is required. You must also configure the trackUserInteractions option for the action data collector:
armsRum.init({
endpoint: "your endpoint",
replay: true, // Enable session replay
collectors: {
action: {
enable: true,
trackUserInteractions: true, // Enable heatmap data collection
}
}
});
Complete configuration example
You can enable both Session Replay and heatmaps:
armsRum.init({
endpoint: "https://your-endpoint.com/rum/web/v2",
// Session Replay configuration
replay: {
enable: true,
sampling: 20, // Session replay sample rate. 20 means 20% of sessions are recorded.
privacy: {
level: 'user-input', // Mask only user input.
}
},
// Heatmap configuration
collectors: {
action: {
enable: true,
trackUserInteractions: true, // Enable heatmap analysis
sampling: 100, // 100% sample rate
}
},
// Session configuration
sessionConfig: {
sampleRate: 1, // Session sampling configuration. The default sample rate is 100%.
storage: 'localStorage',
}
});
Session Replay configuration
Configuration items
You can configure this feature using the replay configuration item. This item supports both simple enablement and detailed configuration.
|
Parameter |
Type |
Description |
Required |
Default |
|
|
boolean |
Specifies whether to enable the session replay feature. |
No |
|
|
|
number |
The sample rate. Valid values: 0 to 100. This value is a percentage. For example, 20 means 20% of sessions are recorded. |
No |
|
|
|
string |
The storage location for replay data. Specifies the API to store recorded data. |
No |
Automatically generated based on the |
|
|
object |
Privacy protection configuration. |
No |
|
Privacy configuration
Before you enable Session Replay, you must perform a formal privacy impact assessment. Plan your privacy protection configuration to control how sensitive information is masked in recordings. RUM provides several privacy protection levels.
|
Parameter |
Type |
Description |
Required |
Default |
|
|
string |
The privacy protection level. Valid values: - - - - |
No |
|
allowlistedparameter is an array that specifies the whitelist configuration. This parameter takes effect when thelevelis set to'allowlisted'. It specifies the element selectors or a list of elements to record.
You can control the recording behavior by adding specific CSS classes:
-
rum-block: Prevents the element and its children from being recorded. A placeholder element of the same size is displayed during replay. -
rum-ignore: Prevents the input events of the element from being recorded. -
rum-mask: Masks the text content of the element and its children.
<!-- This area will not be recorded -->
<div class="rum-block">
This content will not be recorded
</div>
<!-- Prevents recording of input events for this element -->
<input class="rum-ignore" />
<!-- Masks sensitive information -->
<div class="rum-mask">
Sensitive information will be masked
</div>
Configuration examples
Example 1: Simple enablement (default configuration)
armsRum.init({
endpoint: "your endpoint",
replay: true
});
Example 2: Set the sample rate
armsRum.init({
endpoint: "your endpoint",
replay: {
enable: true,
sampling: 20, // 20% of sessions are recorded to reduce storage costs.
}
});
Example 3: Privacy protection - Mask all text
armsRum.init({
endpoint: "your endpoint",
replay: {
enable: true,
privacy: {
level: 'mask' // Masks all text content and input fields.
}
}
});
Example 4: Privacy protection - Mask only user input
armsRum.init({
endpoint: "your endpoint",
replay: {
enable: true,
privacy: {
level: 'user-input' // Masks only user input, such as passwords and input fields.
}
}
});
Example 5: Privacy protection - Whitelist mode
armsRum.init({
endpoint: "your endpoint",
replay: {
enable: true,
privacy: {
level: 'allowlisted',
allowlisted: ['.main-content', '#app', '.product-card'] // Records only these elements.
}
}
});
How it works
-
When recording starts: Session Replay starts recording at the following times:
-
When a session is initialized
-
After the page finishes loading (
DOMContentLoaded)
-
-
Data upload: Recorded data is uploaded as follows:
-
When the page is hidden (
visibilitychange) -
When the page is frozen (
freeze) -
Before the page unloads (
beforeunload) -
When the route changes (
pv)
-
-
Recording limits:
-
The maximum recording length for a single session is 1 hour (3600 seconds).
-
Recording stops automatically after the maximum length is reached.
-
-
Sampling control:
-
The sample rate is controlled at the session level. A replay is sampled only if its corresponding session is sampled.
-
You can configure this using
replay.sampling. -
The sampling decision is made when the session is initialized and remains unchanged for the entire session.
-
Heatmap configuration
Configuration items
You can configure the Heatmap feature using the collectors.action data collector. You must enable the trackUserInteractions option.
|
Parameter |
Type |
Description |
Required |
Default |
|
|
boolean |
Specifies whether to enable click event collection. |
No |
|
|
|
boolean |
Specifies whether to track user interactions for heatmap analysis. If set to |
No |
|
|
|
number |
The sample rate. Valid values: 0 to 100. This value is a percentage. |
No |
|
Configuration details
-
trackUserInteractions: false(default):-
Collects click events only for interactive elements, such as `button`, `a`, `input`, `select`, `option`, and `textarea`.
-
The collected data includes basic information, such as the element name, XPath, and duration.
-
This is suitable for scenarios that require only basic click statistics.
-
-
trackUserInteractions: true:-
Collects click events for all elements, including non-interactive elements.
-
The collected data includes:
-
Position information: The X and Y coordinates of the click relative to the document and the element.
-
Target element information: The element selector, width, height, whether it is an interactive element, and whether the interaction is trusted.
-
Viewport information: The width and height of the page viewport.
-
-
This is suitable for scenarios that require heatmap generation.
-
Configuration examples
Example 1: Enable Heatmap (recommended configuration)
armsRum.init({
endpoint: "your endpoint",
collectors: {
action: {
enable: true,
trackUserInteractions: true, // Enable heatmap analysis
sampling: 100, // 100% sample rate
}
}
});
Example 2: Collect only basic click events (Heatmap disabled)
armsRum.init({
endpoint: "your endpoint",
collectors: {
action: {
enable: true,
trackUserInteractions: false, // Disable heatmap
sampling: 100,
}
}
});
Collected data fields
When trackUserInteractions: true, the collected click event contains the following fields:
position (Position information)
{
x: 123, // Click X coordinate (relative to the document)
y: 456, // Click Y coordinate (relative to the document)
ex: 50, // Relative X coordinate within the element
ey: 30 // Relative Y coordinate within the element
}
target (Target element information)
{
selector: "#root > div > button:nth-child(15)", // Element selector
width: 120, // Element width (in pixels)
height: 40, // Element height (in pixels)
reaction: 1, // Specifies whether the element is interactive (0 = non-interactive, 1 = interactive)
trust: 1 // Specifies whether the interaction is trusted (0 = not trusted, 1 = trusted)
}
viewport (Viewport information)
{
width: 1920, // Viewport width (in pixels)
height: 1080 // Viewport height (in pixels)
}
How it works
-
Event listener: The SDK listens for the
clickevent on the page during the capture phase. -
Element detection:
-
If
trackUserInteractions: false, only clicks on interactive elements are collected. -
If
trackUserInteractions: true, clicks on all elements are collected.
-
-
Data collection:
-
Calculates the click position relative to the document and the element.
-
Retrieves element information, such as the selector, size, and interactivity.
-
Determines the trustworthiness of the interaction based on element size, visibility, and other factors.
-
-
Data reporting: The collected data is reported to the monitoring platform along with other RUM events.
Scenarios
Common scenarios for Session Replay
1. Reproduce and debug errors
Scenario: A user reports an error but cannot describe the steps to reproduce it.
Solution:
-
Enable Session Replay and set a reasonable sample rate, such as 20%.
-
When an error occurs, you can use the session ID to find the corresponding session replay.
-
Replay the user's actions to quickly identify the cause of the problem.
2. Optimize user experience
Scenario: You want to analyze user paths in key flows to optimize conversion rates.
Solution:
-
Increase the sample rate for key pages, such as the purchase flow.
-
Replay user sessions to observe user habits.
-
Find interaction barriers and optimize the page layout and interactions.
3. Support customer service
Scenario: Customer service needs to understand the specific problem a user is facing.
Solution:
-
Find the corresponding session replay using the user ID or session ID.
-
Replay the user's actions to quickly understand the context of the problem.
-
Provide a more accurate solution.
Scenarios for Heatmap
1. Optimize page layout
Scenario: You want to understand the most frequently clicked areas to optimize the page layout.
Solution:
-
Enable heatmap data collection.
-
View the click heatmap in the monitoring platform.
-
Adjust the position of important elements based on the heatmap.
2. Analyze dead clicks
Scenario: You want to find areas that users click but get no response (dead clicks).
Solution:
-
Use the
target.reactionfield to identify clicks on non-interactive elements. -
Analyze the distribution and frequency of dead clicks.
-
Optimize the page to reduce dead clicks.
3. Optimize for mobile devices
Scenario: The rate of accidental clicks is high for mobile users, and you need to optimize the click areas.
Solution:
-
Use the heatmap to view the click distribution on mobile devices.
-
Identify hot spot areas for accidental clicks.
-
Adjust the size and position of elements to reduce accidental clicks.
Best practices
Best practices for Session Replay
1. Set the sample rate
-
Production environment: Set the sample rate to 10% to 20% to balance cost and coverage.
-
Staging environment: Set the sample rate to 100% to help with troubleshooting.
-
Key pages: Increase the sample rate for pages that are critical to conversion rates.
const isProduction = process.env.NODE_ENV === 'production';
armsRum.init({
endpoint: "your endpoint",
replay: {
enable: true,
sampling: isProduction ? 20 : 100, // 20% for production, 100% for staging
}
});
2. Privacy protection
-
Sensitive information: For pages that contain sensitive information, use the
'mask'or'user-input'level. -
Public pages: For public pages, you can use the
'allow'level to obtain more complete replays. -
Compliance requirements: Set the privacy level based on your compliance requirements.
3. Optimize storage costs
-
Set a reasonable sample rate based on your needs.
-
For non-critical pages, you can lower the sample rate or disable recording.
-
Periodically clear expired recording data. The default retention period is 30 days.
4. Performance considerations
-
Session Replay can affect page performance. We recommend that you use it only on key pages.
-
Monitor the volume of recorded data to avoid affecting the reporting performance.
Best practices for Heatmap
1. Set the sample rate
-
Analysis phase: Use a 100% sample rate to obtain complete data.
-
Stable operation: You can lower the rate to 50% to 80% to reduce data volume.
-
High-traffic pages: You can lower the sample rate as needed.
armsRum.init({
endpoint: "your endpoint",
collectors: {
action: {
enable: true,
trackUserInteractions: true,
sampling: 80, // 80% sample rate
}
}
});
2. Combine with business analysis
-
Analyze heatmaps with other dimensions, such as page paths and user properties.
-
Focus on the click heatmaps of key conversion paths.
-
Periodically analyze changes in heatmaps to optimize the page layout.
3. Mobile optimization
-
The rate of accidental clicks is high on mobile devices. Therefore, you should focus on dead clicks.
-
Use the
target.trustfield to identify trusted clicks. -
Optimize the size of click areas for mobile elements.
FAQ
FAQ about Session Replay
Does enabling Session Replay affect page performance?
SessionReplay primarily affects page performance in the following ways:
-
Memory usage: Recorded data consumes some memory.
-
CPU usage: Listening for DOM changes consumes CPU resources.
-
Network transfer: Uploading recorded data can affect network performance.
Recommendations:
-
Set a reasonable sample rate to avoid recording all sessions.
-
You can disable recording on non-critical pages.
-
Monitor page performance metrics to ensure the impact is acceptable.
How can I control the volume of recorded data?
You can control the volume of recorded data in the following ways:
-
Lower the sample rate: Reduce the number of recorded sessions.
-
Set the privacy level: Use the
'mask'or'user-input'level to reduce the amount of recorded content. -
Limit the recording length: A single session can be recorded for a maximum of 1 hour.
-
Filter unwanted elements: Use the
allowlistedmode to record only key areas.
Q3: Is recording for Canvas and IFrame elements supported?
A: No, it is not. For compliance and performance reasons, recording for Canvas and IFrame elements is not currently supported. These areas appear as blank spaces during replay.
Q4: How does the sample rate work?
A: The sampling decision is made when a session is initialized and remains unchanged for the entire session. For example:
-
If the main RUM session sample rate is 20% and the replay sample rate is 20%, the effective sample rate for Session Replay is 4% (20% × 20%).
-
If the replay sample rate is set to 20%, 20% of sessions are recorded.
-
The sampling decision is based on a hash of the session ID. This ensures that the decision is consistent for the same session.
-
Once a session is selected for recording, it is recorded for its entire duration.
FAQ about Heatmap
Q1: When is heatmap data reported?
A: Heatmap data is reported with other RUM events. Data is reported at the following times:
-
When
reportConfig.maxEventCountis reached, data is reported in a batch. -
When the
reportConfig.flushTimeinterval is reached. -
Before the page is unloaded.
Q2: What information does heatmap data contain?
A: When trackUserInteractions: true, heatmap data includes:
-
Position information: The X and Y coordinates of the click (document coordinates and coordinates within the element).
-
Element information: The selector, size, and whether the element is interactive.
-
Interaction information: Whether the interaction is trusted.
-
Viewport information: The width and height of the page viewport.
Q3: How can I determine if a click is valid?
A: You can use the following fields:
-
target.reaction:1indicates an interactive element, and0indicates a non-interactive element. -
target.trust:1indicates a trusted interaction, and0indicates a possible accidental click.
A dead click is usually indicated by reaction: 0 or trust: 0.