Skip to content

Web Application Access


After completing the configuration on this page, the Browser RUM SDK automatically collects page views, resource requests, frontend errors, and user actions, and reports the data to Guance.

Choose an Access Path

First, select the entry point based on the application type to avoid duplicate View configuration or accessing browser APIs during server-side rendering.

Application Type Recommended Entry Description
Uses build tools like Webpack, Vite, Rollup NPM Access Recommended approach for easier version management and on-demand integration
No frontend build process CDN Asynchronous Loading Does not block page parsing, but may miss requests and errors before initialization
Must capture errors and requests from the earliest page stage CDN Synchronous Loading Initializes as early as possible, but may impact page load time
React, Vue, Angular single-page applications Frontend Framework Plugin Access Automatically manages Router View and framework errors
Next.js, Nuxt SSR Framework Access Distinguishes between server and browser environments to avoid duplicate Views
Electron Electron Application Access Initialize only in the renderer process

Prepare Access Information

  1. Go to RUM > Application List > Create Application > Web.
  2. Create the application and obtain the applicationId, env, version, and other configurations generated by the console.
  3. Choose the data reporting method:

  4. Public OpenWay: Obtain site and clientToken; no need to deploy DataKit.

  5. DataKit Direct Connection: Prepare datakitOrigin; DataKit must enable the RUM Collector and be configured to be publicly accessible with the IP geolocation database installed.
Do not configure both reporting methods simultaneously

Public OpenWay uses site and clientToken; DataKit direct connection uses datakitOrigin. Only keep the fields required for the current access method.

Reporting Methods

{
  applicationId: "<APPLICATION_ID>",
  datakitOrigin: "<DATAKIT_ORIGIN>"
}

{
  applicationId: "<APPLICATION_ID>",
  site: "<PUBLIC_OPENWAY_URL>",
  clientToken: "<CLIENT_TOKEN>"
}

Integrate the SDK

Access Method
Description
NPM Bundles the SDK code into the frontend project, making it easy to lock the version. May miss requests and errors before SDK initialization.
CDN Asynchronous Loading Asynchronously loads the SDK script via CDN without affecting page load performance. May miss request and error collection before initialization.
CDN Synchronous Loading Synchronously loads the SDK script via CDN, allowing complete collection of all errors and performance metrics. May affect page load performance.

NPM Access

Install and import the SDK in the frontend project:

npm install @cloudcare/browser-rum @cloudcare/browser-core

Initialize the SDK in the project:

import { datafluxRum } from "@cloudcare/browser-rum"

datafluxRum.init({
  applicationId: "<APPLICATION_ID>",
  site: "<PUBLIC_OPENWAY_URL>",
  clientToken: "<CLIENT_TOKEN>",
  service: "web-app",
  env: "production",
  version: "1.0.0",
  sessionSampleRate: 100,
  trackUserInteractions: true
})

CDN Synchronous Loading

Add the script in the HTML file:

<script
  src="https://static.guance.com/browser-sdk/v3/dataflux-rum.js"
  type="text/javascript"
></script>
<script>
  window.DATAFLUX_RUM &&
    window.DATAFLUX_RUM.init({
      applicationId: "<APPLICATION_ID>",
      site: "<PUBLIC_OPENWAY_URL>",
      clientToken: "<CLIENT_TOKEN>",
      service: "web-app",
      env: "production",
      version: "1.0.0",
      sessionSampleRate: 100,
      trackUserInteractions: true
    })
</script>

CDN Asynchronous Loading

Add the script in the HTML file:

<script>
  ;(function (h, o, u, n, d) {
    h = h[d] = h[d] || {
      q: [],
      onReady: function (c) {
        h.q.push(c)
      },
    }
    d = o.createElement(u)
    d.async = 1
    d.src = n
    n = o.getElementsByTagName(u)[0]
    n.parentNode.insertBefore(d, n)
  })(
    window,
    document,
    "script",
    "https://static.guance.com/browser-sdk/v3/dataflux-rum.js",
    "DATAFLUX_RUM"
  )
  DATAFLUX_RUM.onReady(function () {
    DATAFLUX_RUM.init({
      applicationId: "<APPLICATION_ID>",
      site: "<PUBLIC_OPENWAY_URL>",
      clientToken: "<CLIENT_TOKEN>",
      service: "web-app",
      env: "production",
      version: "1.0.0",
      sessionSampleRate: 100,
      trackUserInteractions: true
    })
  })
</script>

The examples above use Public OpenWay. When using DataKit direct connection, remove site and clientToken, and configure datakitOrigin instead.

Verify Access

  1. Open the page where the SDK has been integrated, and perform a page navigation, a button click, and an API request.
  2. In the browser developer tools Network tab, filter for /v1/write/rum and verify that a successful reporting request exists.
  3. Check the Console to ensure there are no initialization errors such as Application ID is not configured or datakitOrigin or site is not configured.
  4. Go to RUM > Application List, open the corresponding Web application, filter by service, env, version in the explorer, and confirm that View, Resource, or Action data exists.
View data indicates successful basic access

Error, Resource, and Action data will only appear when the corresponding events actually occur on the page. If no data is present, first check whether the current session falls within sessionSampleRate, then refer to the FAQ.

Common Optional Configurations

After confirming basic data is received, enable additional capabilities as needed:

Goal Configuration or API Documentation
Correlate frontend and backend traces allowedTracingUrls, traceType Trace Configuration
Control sampling rate sessionSampleRate, startSession() Sampling Configuration
Enable Session Replay startSessionReplayRecording() Web Session Replay
Automatically manage SPA Router Views plugins Frontend Framework Plugin Access
Capture WebGL/WebGL2 plugins, Canvas auto-capture Canvas Recording Guide
Identify logged-in users setUser() Custom User Identity
Add business fields or events Global Context, addAction(), addError() Custom Data and Events

Trace Configuration (Optional)

When using NPM + TypeScript, traceType must use the TraceType enum imported from the corresponding brand's browser-core package:

import { TraceType } from "@cloudcare/browser-core"
import { datafluxRum } from "@cloudcare/browser-rum"

datafluxRum.init({
  applicationId: "<APPLICATION_ID>",
  site: "<PUBLIC_OPENWAY_URL>",
  clientToken: "<CLIENT_TOKEN>",
  allowedTracingUrls: ["https://api.example.com"],
  traceType: TraceType.DDTRACE
})

The runtime value of TraceType.DDTRACE is still "ddtrace". CDN access has no module import; use the corresponding runtime string when explicitly configuring. After enabling traces, the API server must also allow the corresponding Trace headers. For details, refer to How APM Correlates with RUM.

If a regular session is not sampled but you still need to pass Trace headers to the backend, you can explicitly enable allowTraceHeaderWithoutSession:

datafluxRum.init({
  applicationId: "<APPLICATION_ID>",
  site: "<PUBLIC_OPENWAY_URL>",
  clientToken: "<CLIENT_TOKEN>",
  sessionSampleRate: 0,
  sessionOnErrorSampleRate: 0,
  allowedTracingUrls: ["https://api.example.com"],
  allowTraceHeaderWithoutSession: true
})

When enabled, the SDK will still inject Trace headers only for XHR and Fetch requests that match allowedTracingUrls. This configuration does not create or force-enable a RUM session, and does not report View, Error, Resource, or Action data for unsampled sessions. The API service must still allow the request headers corresponding to the selected traceType; cross-origin requests also require proper CORS configuration.

Parameter Configuration

Initialization Parameters

Parameter
Type
Required
Default
Description
applicationId String Yes The application ID created from Guance.
datakitOrigin String When using DataKit Direct Connection DataKit data reporting URL, format: protocol (including ://) + domain or IP + optional port, e.g., https://datakit.example.com.
clientToken String When using Public OpenWay Public OpenWay data reporting token, obtained from the Guance console.
site String When using Public OpenWay Public OpenWay data reporting URL, obtained from the Guance console.
env String No The current environment of the Web application, e.g., prod: production; gray: canary; pre: pre-release; common: daily; local: local.
version String No The version number of the Web application.
service String No The service name of the current application, defaults to browser, supports custom configuration.
sessionSampleRate Number No 100 Percentage of sessions sampled for metrics data collection:
100 for full collection; 0 for no collection.
sessionOnErrorSampleRate Number No 0 Error session compensation sampling rate: when a session is not sampled by sessionSampleRate, if an error occurs during the session, it is sampled at this rate. Such sessions start recording events when the error occurs and continue until the session ends. SDK version requirement >= 3.2.19.
sessionReplaySampleRate Number No 100 Session Replay data collection percentage:
100 for full collection; 0 for no collection.
sessionReplayOnErrorSampleRate Number No 0 Session Replay error session replay compensation sampling rate: when a session is not sampled by sessionReplaySampleRate, if an error occurs during the session, it is sampled at this rate. Such replays will record events up to one minute before the error and continue until the session ends. SDK version requirement >= 3.2.19.
trackSessionAcrossSubdomains Boolean No false Shares the cache across subdomains of the same domain.
usePartitionedCrossSiteSessionCookie Boolean No false Enables partitioned secure cross-site session cookies details
useSecureSessionCookie Boolean No false Uses a secure session cookie. This disables sending RUM events on insecure (non-HTTPS) connections.
traceType TraceType No TraceType.DDTRACE (runtime value ddtrace) Configures the distributed tracing tool type. NPM access uses the TraceType enum, CDN access uses the corresponding runtime string. Currently supports DDTRACE (ddtrace), ZIPKIN_MULTI_HEADER (zipkin), ZIPKIN_SINGLE_HEADER (zipkin_single_header), W3C_TRACEPARENT (w3c_traceparent), W3C_TRACEPARENT_64 (w3c_traceparent_64bit), SKYWALKING_V3 (skywalking_v3) and JAEGER (jaeger).

❗️
1. OpenTelemetry supports zipkin_single_header, w3c_traceparent, zipkin, jaeger 4 types.
2. This configuration depends on allowedTracingUrls.
3. When configuring the corresponding type, you need to set the corresponding Access-Control-Allow-Headers for the API service. For details, refer to How APM Correlates with RUM.
traceId128Bit Boolean No false Whether to generate traceID in 128-bit mode, corresponding to traceType, currently supports zipkin, jaeger.
allowedTracingUrls Array No [] List of request URL patterns allowed to inject Trace headers. Array items can be a full URL string, a regular expression, a matching function, or an object containing match and traceType. Example: ["https://api.example.com/xxx", /https:\/\/.*\.my-api-domain\.com\/xxx/, (url) => url.includes("/api/")].
allowTraceHeaderWithoutSession Boolean No false Whether to still inject Trace headers for XHR and Fetch requests that match allowedTracingUrls when the current RUM session is not sampled. Enabling this does not create a session and does not report RUM data for unsampled sessions.
allowedTracingOrigins Array No [] Deprecated, retained only for backward compatibility. New integrations should use allowedTracingUrls; when both are configured, allowedTracingUrls overrides this configuration.
trackUserInteractions Boolean No false Whether to enable user interaction collection.
trackViewsManually Boolean No false Whether to disable automatic View tracking by the SDK and manually start Views via startView(). The framework Router plugin automatically manages this configuration; business applications do not need to set it again. See details.
plugins Array No [] Register RUM plugins; must be passed during init(). Framework plugins can collect route views and framework errors for React, Vue, Angular, Next.js, and Nuxt. SDK version requirement >= 3.3.6. For details, see Frontend Framework Plugin Access. WebGL Replay is available from SDK 3.3.7, requires the RUM main package version >= 3.3.7, and it is recommended to use the same SDK release version for the plugin and the main package. For details, see Canvas Recording Guide.
enableExperimentalFeatures Array No [] Enable experimental features. Configure ["track_websockets"] to collect native WebSocket connection-level Resources. SDK version requirement >= 3.3.6. See details.
actionNameAttribute String No Version requirement: >3.1.2. Add a custom attribute to elements to specify the action name. For usage details, see tracking user actions.
beforeSend Function(event, context):Boolean No Version requirement: >3.1.2. Intercept and modify data before sending. See details.
storeContextsToLocal Boolean No Version requirement: >3.1.2. Whether to cache user custom data to local storage, e.g., custom data added via setUser, addGlobalContext APIs.
storeContextsKey String No Version requirement: >3.1.18. Defines the key for storing to local storage. Default is auto-generated if not provided. This parameter is mainly used to distinguish shared stores across different subpaths in the same domain.
compressIntakeRequests Boolean No Compress RUM data request payloads to reduce bandwidth usage when sending large amounts of data, and also reduce the number of requests. Compression is performed in a Web Worker thread. For CSP security policies, refer to CSP Security. SDK version requirement >= 3.2.0. DataKit version requirement >=1.60. Deployment plan version requirement >= 1.96.178.
workerUrl String No Session Replay and compressIntakeRequests data compression are performed in a Web Worker thread. By default, when CSP security is enabled, worker-src blob: must be allowed. This configuration allows specifying a custom hosted worker URL. For CSP security policies, refer to CSP Security. SDK version requirement >= 3.2.0.
remoteConfiguration Boolean No Whether to enable remote configuration for data collection. Default not enabled. The remote configuration feature allows dynamically modifying data collection configuration parameters without releasing a new version. For example, you can modify the sampling rate or enable/disable user interaction collection remotely. The remote configuration feature requires enabling environment variable settings in the Guance console. SDK version requirement >= 3.2.20. DataKit version requirement >=1.60. How to enable environment variables in the Guance console.
replayCanvasWorkerUrl string No Dedicated worker URL for canvas snapshot encoding, does not replace workerUrl. This configuration allows specifying a custom hosted worker URL. For CSP security policies, refer to CSP Security. SDK version requirement >= 3.3.0.
replayCanvasEnabled boolean No false Whether to enable canvas recording. If not enabled, canvas will not be captured. SDK version requirement >= 3.3.0.
replayCanvasMode 'manual' \| 'auto' No auto Canvas recording mode. manual requires manually calling snapshotCanvas(canvas); auto is automatic recording.
replayCanvasSampling number \| 'all' No 2 Only takes effect when replayCanvasMode: 'auto'. Positive numbers select the automatic snapshot path; it is recommended to start with 2; the value itself does not control Canvas 2D capture frequency. 'all' makes Canvas 2D attempt a higher-fidelity command capture, but complex scenes may still fall back to snapshot; the WebGL plugin always uses budgeted pixel snapshots.
replayCanvasAutoInterval number No 250 Target interval for automatic snapshot of each Canvas, in milliseconds. Multiple Canvases are fairly rotated; the actual rhythm is also subject to cooldown, backoff, page visibility, and global runtime budget constraints.
replayCanvasQuality 'low' \| 'medium' \| 'high' \| number No 0.4 Canvas snapshot encoding quality. String presets also adjust sampling and automatic scheduling budget; if you only want to change image quality, pass a number between 0 and 1.
replayCanvasAutoCooldown number No 250 Minimum cool-down time for automatic snapshot of the same Canvas, in milliseconds.
replayCanvasAutoUnchangedBackoff number No 3000 Interval for triggering the next full encoding check when the lightweight signature has not changed, in milliseconds; during this interval, the system will still probe for changes with a bounded, adaptive rhythm.
replayCanvasAutoFailureBackoff number No 5000 Back-off time after an automatic collection failure, in milliseconds.
replayCanvasAutoMaxPerRun number No 2 Maximum number of Canvases processed in a single automatic scheduling run.
replayCanvasFlushImmediately boolean No manual: true
auto: false
Whether to flush immediately after a Canvas frame is successfully recorded for replay.
silentMultipleInit boolean No Whether to silently ignore duplicate initialization.

When not using the low, medium, or high string presets, the Canvas automatic scheduling baseline is: sampling 2, target interval 250 ms per Canvas, cooldown 250 ms, unchanged backoff 3000 ms, failure backoff 5000 ms, maximum of 2 Canvases per round. The string presets replace these budgets and encoding quality simultaneously; multiple Canvases are also subject to fair rotation and global collection budget constraints. Explicit individual parameter values override the corresponding values from the preset. The complete preset matrix is available in the Canvas Recording Guide.

The above high-frequency scheduling baseline applies to Canvas 2D. When the WebGL plugin does not explicitly configure interval/cooldown, it continues to use a more conservative GPU read-back rhythm; explicit individual parameters override them separately.

site Parameter Handling

Node Name Address
CN Region 1 (Hangzhou) https://rum-openway.guance.com
CN Region 2 (Ningxia) https://aws-openway.guance.com
CN Region 4 (Guangzhou) https://cn4-openway.guance.com
CN Region 6 (Hong Kong) https://cn6-openway.guance.one
US Region 1 (Oregon) https://us1-openway.guance.com
EU Region 1 (Frankfurt) https://eu1-openway.guance.one
AP Region 1 (Singapore) https://ap1-openway.guance.one
Africa Region 1 (South Africa) https://za1-openway.guance.com
Indonesia Region 1 (Jakarta) https://id1-openway.guance.com

Runtime Session Control

RUM SDK 3.3.6 introduces startSession(). Calling this method immediately ends the current session and starts a new session according to the current sampling configuration, without waiting for the next user interaction:

datafluxRum.startSession()

You can also override the runtime sessionSampleRate:

datafluxRum.startSession({
  sessionSampleRate: 100,
})

The sampling rate must be between 0 and 100. This override value applies to the current and subsequent automatically renewed sessions. Both the full RUM package and the lean RUM package support this API. For detailed semantics and usage scenarios, see Restart Session at Runtime.

Enable Advanced Capabilities on Demand

Collect Only Error Session Events

Version Requirements

SDK version requirement >= 3.2.19.

When an error is triggered on the page, the SDK will automatically:

  • Continuous recording: From the moment the error triggers, the session's full lifecycle data is recorded.
  • Precise compensation: Through an independent sampling channel, ensuring no error scenarios are missed.

Configuration Example

window.DATAFLUX_RUM &&
  window.DATAFLUX_RUM.init({
    applicationId: "<APPLICATION_ID>",
    site: "<PUBLIC_OPENWAY_URL>",
    clientToken: "<CLIENT_TOKEN>",
    sessionSampleRate: 0,
    sessionOnErrorSampleRate: 100
  })

The above example uses Public OpenWay. When using DataKit direct connection, replace the reporting address fields according to the basic access example.

Data Compression

When collecting a large number of static resources (e.g., JS, CSS, images) and full sampling is enabled, the SDK may generate a significant amount of data after initialization, causing request accumulation and potentially impacting the application thread state.

Setting compressIntakeRequests: true enables the SDK to use deflate compression in a Web Worker to compress the reported data, reducing request payload sizes and the number of requests.

Configuration Example

window.DATAFLUX_RUM &&
  window.DATAFLUX_RUM.init({
    applicationId: "<APPLICATION_ID>",
    site: "<PUBLIC_OPENWAY_URL>",
    clientToken: "<CLIENT_TOKEN>",
    compressIntakeRequests: true
  })

Important Notes

  1. Data compression logic is executed in a Web Worker. If CSP security policies are enabled, you need to allow blob: in the worker-src directive. For more information, refer to the CSP Security Policy Documentation.
  2. The SDK supports specifying a custom hosted Worker URL via the workerUrl configuration option.
  3. The SDK version required for this feature is >= 3.2.

Custom Data and Events

The basic access page no longer reproduces all common APIs. Navigate to the corresponding page based on the business goal to get CDN, NPM, and full parameter examples:

  • Tracking User Actions: Automatically collect clicks, define Action names, add custom Actions.
  • Custom User Identity: Set the user after login, clear the user on logout or account switch.
  • Global Context: Add stable business dimensions to all subsequent RUM events.
  • Add Custom Action: Record business operations that cannot be expressed through page clicks.
  • Report Custom Error: Report exceptions that have been caught or actively identified by the business.

Web Session Replay

Prerequisites

Use the full RUM package that includes Session Replay; the lean RUM package does not include session replay capabilities.

Start Recording

After SDK initialization, call the startSessionReplayRecording() method to start session replay recording. You can choose to start it under specific conditions, such as after user login Start Session Recording.

Version Requirements

SDK version requirement >= 3.2.19.

When an error occurs on the page, the SDK will automatically:

  • Retroactive capture: Records the full page snapshot from the 1 minute before the error.
  • Continuous recording: Continues recording from the moment the error occurs until the session ends.
  • Intelligent compensation: Ensures error scenarios are not missed through an independent sampling channel.

Configuration Example

window.DATAFLUX_RUM &&
  window.DATAFLUX_RUM.init({
    applicationId: "<APPLICATION_ID>",
    site: "<PUBLIC_OPENWAY_URL>",
    clientToken: "<CLIENT_TOKEN>",
    sessionSampleRate: 100,
    sessionReplaySampleRate: 0,
    sessionReplayOnErrorSampleRate: 100
  })

window.DATAFLUX_RUM && window.DATAFLUX_RUM.startSessionReplayRecording()

Important Notes

  • Session Replay does not record the playback of iframes, videos, or audio; Canvas is not captured by default and requires separate configuration of replayCanvasEnabled. WebGL/WebGL2 is available from SDK 3.3.7, requires the RUM main package version >= 3.3.7, and also requires installing and registering a compatible browser-rum-webgl plugin; it is recommended to use the same SDK release version for the plugin and the main package. See Canvas Recording Guide for details.
  • To ensure normal access to static resources (e.g., fonts, images) during replay, you may need to configure CORS policies.
  • Ensure that CSS rules are accessible via the CSSStyleSheet interface to support CSS styles and mouse hover events.

Verify Recording Status

Call window.DATAFLUX_RUM.isRecording() to check if the current page is recording, and confirm in the Session Replay explorer that the corresponding session has produced replay data. In production, adjust sessionReplaySampleRate according to business requirements.

Feedback

Is this page helpful?