uni-app Multi-platform SDK
The HealthGuard uni-app SDK (@health-guard/sdk-uniapp) covers H5, WeChat, Alipay, Douyin mini-programs, and native App runtimes with a single integration. It automatically detects the runtime and adapts the capture logic.
Installation
bash
npm install @health-guard/sdk-uniappBasic Usage
ts
import { createUniAppClient } from '@health-guard/sdk-uniapp';
const client = createUniAppClient({
appKey: 'your-app-key',
endpoint: 'https://your-server.com/api/events/batch',
autoCapture: true
});Platform Auto-detection
The SDK sets the platform field automatically based on the runtime:
| Runtime | platform value |
|---|---|
| H5 | uniapp-h5 |
| WeChat Mini Program | uniapp-wechat |
| Alipay Mini Program | uniapp-alipay |
| Douyin / Toutiao Mini Program | uniapp-douyin |
| App | uniapp-app |
| Unknown | uniapp |
Configuration
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
appKey | string | Yes | - | Unique app identifier |
endpoint | string | Yes | - | Collector endpoint URL |
release | string | No | - | App version |
environment | string | No | - | Environment: development / test / production |
userId | string | No | - | Business user identifier |
autoCapture | boolean | object | No | false | Auto-capture errors, requests, and unhandled rejections |
flushIntervalMs | number | No | 5000 | Batch flush interval in milliseconds |
maxBatchSize | number | No | 10 | Max events per batch |
transportFailureRetryDelayMs | number | No | 30000 | Backoff delay before retrying a failed transport (ms) |
autoCapture Options
When autoCapture is true, all auto-capture features are enabled:
js
autoCapture: {
errors: true, // JS runtime errors
unhandledRejections: true, // Unhandled promise rejections
fetch: true, // H5 fetch (H5 only)
xhr: true, // H5 XMLHttpRequest (H5 only)
request: true // uni.request (mini-program / App only)
}Manual API
captureException(error)
Manually report an error:
js
try {
riskyOperation();
} catch (err) {
client.captureException(err);
}captureHttp(input)
Manually report an HTTP request:
js
client.captureHttp({
method: 'POST',
url: '/api/order',
status: 500,
duration: 240,
success: false,
errorMessage: 'Internal Server Error'
});capturePerformance(input)
Manually report a performance metric:
js
client.capturePerformance({
name: 'custom-metric',
value: 120,
rating: 'good'
});addBreadcrumb(breadcrumb)
Add a breadcrumb:
js
client.addBreadcrumb({
type: 'navigation',
message: 'User navigated to /pages/order/detail',
data: { from: '/pages/index/index' }
});flush()
Immediately flush the queue and send all pending events (including events requeued after a transport failure):
js
await client.flush();Privacy & Sanitization
- URL query parameters such as
authorization,password,token,secret, andcookieare filtered by default. - Request and response bodies are not collected.
- Uses the business-provided
userIdor an anonymous ID; no real identity data is collected.