Skip to content

Quick Start

This guide provides the shortest integration path for version 0.3.0 or later. For complete installation and host integration, see App Access.

Standard uni-app

1. Install the Module

Copy the following directories from the same release package to your project. The version must be 0.3.0 or later:

uni_modules/
├── GC-JSPlugin
└── GC-UniPlugin

Do not install nativeplugins/GCUniPlugin.

2. Load the Bridge and Import APIs

Load setup.js once at the application entry point:

import '@/uni_modules/GC-UniPlugin/setup.js';

import {
    mobileAgent,
    rum,
    logger,
    tracer
} from '@/uni_modules/GC-UniPlugin';

import {
    gcErrorTracking,
    gcViewTracking,
    gcResourceTracking
} from '@/uni_modules/GC-JSPlugin';

3. Initialize

mobileAgent.sdkConfig({
    datakitUrl: 'YOUR_DATAKIT_URL',
    debug: true,
    env: 'prod'
});

rum.setConfig({
    androidAppId: 'YOUR_ANDROID_APP_ID',
    iOSAppId: 'YOUR_IOS_APP_ID',
    harmonyAppId: 'YOUR_HARMONY_APP_ID'
});

logger.setConfig({
    enableCustomLog: true,
    enableLinkRumData: true
});

tracer.setConfig({
    traceType: 'ddTrace',
    enableLinkRUMData: true
});

gcErrorTracking.startTracking();
gcResourceTracking.startTracking();

Only fill in the RUM App ID for the actual release platform. When using a public DataWay, replace datakitUrl with datawayUrl and clientToken.

4. Enable Automatic View Collection

For Vue 2, call before creating the root instance:

gcViewTracking.startTracking();

For Vue 3, pass the application instance returned by createSSRApp():

import App from './App';
import { createSSRApp } from 'vue';

export function createApp() {
    const app = createSSRApp(App);
    gcViewTracking.startTracking(app);
    return { app };
}

The recommended initialization order is:

mobileAgent.sdkConfig
  -> rum.setConfig
  -> logger.setConfig / tracer.setConfig
  -> GC-UniSessionReplay.setConfig (optional)
  -> gcErrorTracking / gcResourceTracking / gcActionTracking
  -> gcViewTracking

Host App + uni Mini Program

For the uni mini program project, only install GC-JSPlugin:

import {
    mobileAgent,
    rum,
    logger,
    tracer,
    gcErrorTracking,
    gcViewTracking,
    gcResourceTracking
} from '@/uni_modules/GC-JSPlugin';

The native SDK, RUM, Log, and Trace are initialized by the host app before opening the uni mini program. The uni mini program only starts the JS collector and calls runtime APIs, for example:

mobileAgent.bindRUMUserData({
    userId: 'USER_ID'
});

mobileAgent.appendBridgeContext({
    wgt_id: 'YOUR_WGT_ID'
});

gcErrorTracking.startTracking();
gcResourceTracking.startTracking();

If the iOS host has already enabled native resource auto-collection, call gcResourceTracking.startTracking({ enableIOS: false }) instead to avoid duplicate collection.

When the host app has not registered the corresponding modules, these calls safely degrade to no-ops, making it convenient to debug uni mini program pages on a standard base. The native trace must be verified on a host app that includes the host extension.

Next Steps