Skip to content

UniApp Mini Program JavaScript SDK Remote Configuration

This document describes the remote configuration, forced sampling, and Session behaviors of UniApp Mini Program JavaScript SDK version 2.2.19 and above.

This document applies to the rum-uniapp JavaScript SDK, not the GCUniPlugin-* native modules described in other pages.

Enable Remote Configuration

Set remoteConfiguration: true during initialization. The SDK will start immediately with local configuration; the remote configuration request will not block the first screen collection. After the request returns, supported configuration items are updated at runtime.

Older versions used the misspelling remoteConfigration. Version 2.2.19 still supports this parameter, but new projects should use remoteConfiguration.

const { datafluxRum } = require('@cloudcare/rum-uniapp')

const rumConfig = {
  applicationId: 'appid_xxxxxxx',
  site: 'https://rum-openway.guance.com',
  clientToken: 'client_token_xxxxx',
  service: 'uniapp-demo',
  env: 'production',
  version: '1.0.0',
  sessionSampleRate: 20,
  remoteConfiguration: true,
  remoteConfigurationFetchTimeout: 3000,
}

// Vue2
datafluxRum.init(Vue, rumConfig)

// Vue3 project change to:
// datafluxRum.initVue3(rumConfig)
Parameter Type Default Description
sessionSampleRate number 100 Compatible alias for sampleRate, range 0 to 100. When both are set, sampleRate takes precedence
remoteConfiguration boolean false Whether to asynchronously fetch and apply remote configuration
remoteConfigration boolean false Old spelling compatibility, not recommended for new projects
remoteConfigurationFetchTimeout number 3000 Remote configuration request timeout in milliseconds; if the request fails or times out, local configuration continues to be used

After enabling, the SDK requests the following URL:

{datakitOrigin|datakitUrl|site}/v1/env_variable?app_id={applicationId}

When using the public DataWay, the request also carries clientToken. The corresponding domain must be added to the mini platform's request whitelist.

Configuration Delivery Format

Remote configuration keys use the following format:

R.{applicationId}.{configuration name}

For example:

{
  "R.appid_xxxxxxx.sessionSampleRate": 20,
  "R.appid_xxxxxxx.vip_id": "[\"user-1\", \"user-2\"]"
}

The SDK removes the R.{applicationId}. prefix. The business retrieves the configuration via getRemoteConfiguration():

{
  "sessionSampleRate": 20,
  "vip_id": "[\"user-1\", \"user-2\"]"
}

Currently supported for remote update:

sampleRate
sessionSampleRate
service
env
version
trackInteractions
traceType
traceId128Bit
allowedTracingOrigins

sessionSampleRate is applied as sampleRate. Custom fields like vip_id do not automatically change SDK behavior; the business code must read and handle them.

Get Remote Configuration

Call getRemoteConfiguration(callback) after init() or initVue3():

datafluxRum.getRemoteConfiguration(function (remoteConfig) {
  console.log('remote config:', remoteConfig)
})
  • If the request is not completed, the callback waits for the current request to finish.
  • If the request is already completed, the callback immediately receives the cached result without making a new request.
  • Each callback receives an independent copy; modifying the returned object does not affect the SDK internal configuration.
  • If remote configuration is not enabled, the request fails, times out, or the returned content cannot be parsed, the callback receives an empty object {}.

Force Collect Current Session

setForcedSession() is used to force collect the current Session. Even if the local or remote sampling rate is not met, RUM data after the call will still be reported with:

session_is_forced=true

The following example forces collection based on VIP user list delivered remotely:

const currentUserId = 'user-1'

datafluxRum.setUser({ id: currentUserId })
datafluxRum.getRemoteConfiguration(function (remoteConfig) {
  let vipIds = remoteConfig && remoteConfig.vip_id

  if (typeof vipIds === 'string') {
    try {
      vipIds = JSON.parse(vipIds)
    } catch (error) {
      vipIds = []
    }
  }

  if (Array.isArray(vipIds) && vipIds.map(String).indexOf(currentUserId) !== -1) {
    datafluxRum.setForcedSession()
    datafluxRum.addRumGlobalContext('vip_force_collect', true)
  }
})

setForcedSession() only affects data after the call; it does not re-send previously discarded data. The forced state applies only to the current Session; after the Session expires, the latest sampling rate is recalculated.

Session and Runtime Behavior

  • Sessions are saved independently per applicationId. Different RUM applications do not share Session IDs or sampling results.
  • A new Session is created after 15 consecutive minutes of inactivity; the maximum duration of a single Session is 4 hours.
  • Page entry, click, touch, input, and declared page scroll extend the Session. Disabling trackInteractions only stops automatic Action collection, without affecting Session activity recognition.
  • Data before the remote configuration returns is processed according to local configuration and is not retrospectively recalculated.
  • For a newly created Session in this initialization that has not been forcibly sampled, the sampling result can be recalculated after the remote sampling rate returns; Sessions restored from storage retain their original sampling decision.
  • When the SDK proxies uni.request and uni.downloadFile, it preserves the original return value and Promise behavior of business calls.

Feedback

Is this page helpful? ×