Skip to content

SDK Initialization

This document covers the initialization of the UniApp SDK and its runtime foundational capabilities.

Basic Configuration

<script>
var ftModule = uni.requireNativePlugin("GCUniPlugin-MobileAgent");

export default {
    onLaunch: function() {
        ftModule.sdkConfig({
            datakitUrl: 'your datakitUrl',
            debug: true,
            env: 'common',
            globalContext: {
                custom_key: 'custom value'
            }
        });
    }
}
</script>
Parameter Name Parameter Type Required Parameter Description
datakitUrl string Yes The reporting URL address for the local environment deployment (Datakit), e.g., http://10.0.0.1:9529. Note: Choose either datakitUrl or datawayUrl
datawayUrl string Yes The reporting URL address for the public network DataWay. Note: Choose either datakitUrl or datawayUrl
clientToken string Yes Authentication token, must be used together with datawayUrl
debug boolean No Whether to print Debug logs, default is false
env string No Environment name, default is prod. It is recommended to use a single word, e.g., test
service string No Belonging business or service name, defaults: df_rum_ios, df_rum_android
globalContext object No Global tags attached during initialization
offlinePakcage boolean No Android only. Whether to use offline packaging or uni mini-programs, default is false. See App Access FAQ for details
autoSync boolean No Whether to automatically sync collected data to the server, default is YES. When set to NO, use flushSyncData to manage synchronization manually
syncPageSize number No Sets the number of entries per sync request, range [5,), default is 10
syncSleepTime number No Sets the sync interval time, range [0,5000], default is not set
enableDataIntegerCompatible boolean No Recommended to enable when coexisting with Web data; enabled by default after version 0.2.1
compressIntakeRequests boolean No Whether to deflate compress sync data, default is off, supported in SDK version 0.2.0 and above
enableLimitWithDbSize boolean No Whether to enable DB capacity limit, default is off. When enabled, logCacheLimitCount and rumCacheLimitCount become ineffective
dbCacheLimit number No DB cache limit size, range [30MB,), default is 100MB, unit is byte
dbDiscardStrategy string No DB data discard strategy: discard discards new data (default), discardOldest discards old data
dataModifier object No Single-field data masking modification, see Data Collection Masking for details
lineDataModifier object No Single-line data masking modification, see Data Collection Masking for details

User Information Binding and Unbinding

var ftModule = uni.requireNativePlugin("GCUniPlugin-MobileAgent");

ftModule.bindRUMUserData({
    userId: 'Test userId',
    userName: 'Test name',
    userEmail: '[email protected]',
    extra: {
        age: '20'
    }
});

ftModule.unbindRUMUserData();

API - bindRUMUserData

Field Type Required Description
userId string Yes User ID
userName string No User Name
userEmail string No User Email
extra object No Additional user information

API - unbindRUMUserData

Unbinds the current user.

Runtime Capabilities

Shut Down SDK

var ftModule = uni.requireNativePlugin("GCUniPlugin-MobileAgent");
ftModule.shutDown();

API - shutDown

Shuts down the SDK.

Clear SDK Cached Data

var ftModule = uni.requireNativePlugin("GCUniPlugin-MobileAgent");
ftModule.clearAllData();

API - clearAllData

Clears all data that has not yet been uploaded to the server.

Actively Sync Data

var ftModule = uni.requireNativePlugin("GCUniPlugin-MobileAgent");
ftModule.flushSyncData();

API - flushSyncData

When sdkConfig.autoSync is configured as true, no additional action is needed; the SDK will sync automatically.

When sdkConfig.autoSync is configured as false, you need to actively call this method to trigger data synchronization.