Harmonyos Next deployment
Environment requirements
Minimum support: API 12 Release
Install SDK
Enter the project root directory and execute the following command
ohpm install @tingyun/sdk-core
Install the specified version SDK command example
ohpm install @tingyun/sdk-core@1.2.0
Confirm that the project is compatible with the bytecode format HAR package
The SDK HAR package is in bytecode format, and you need to set useNormalizedOHMUrl
in the project-level build-profile.json5
to true
{
"app": {
"products": [
{
"buildOption": {
"strictMode": {
"useNormalizedOHMUrl": true
}
}
}
]
}
}
Permission configuration
Permission name | Purpose | Required |
---|---|---|
ohos.permission.INTERNET | SDK sends data. Cannot start without SDK configuration | Yes |
ohos.permission.GET_NETWORK_INFO | Get network connection information. After configuration, you can get network type and connection method information | No |
ohos.permission.STORE_PERSISTENT_DATA | Storage device ID. After configuration, SDK can obtain device ID more accurately | No |
Initialize SDK
Initialize SDK in the onCreate
method of entry type module AbilityStage
import tingyun from '@tingyun/sdk-core'
import axios from '@ohos/axios'
export default class MyAbilityStage extends AbilityStage {
onCreate(): void {
tingyun.init({
// redirect server address, obtained on the console settings page
redirectHost: '<Redirect server address>',
// appKey, obtained on the console settings page
appKey: '<AppKey>',
// context
context: this.context,
// If axios is used, the axios object can be passed in to collect the network request sent by axios
axios: axios
})
}
}
Set user ID (optional)
import tingyun from '@tingyun/sdk-core'
// Set user ID
tingyun.setUserId('<userId>')
Verify data reporting
After embedding, start the APP, open the Log -> HiLog menu in the IDE, select the corresponding APP, view the log, search for the log with the tag Tingyun
, if there is a log with the keyword init success
, it means that the data reporting is successful
SDK configuration options
import common from '@ohos.app.ability.common'
export enum LogLevel {
DEBUG,
INFO,
WARN,
ERROR,
NONE
}
export type RecordRule = {
// The domain name/URL configuration for this parameter needs to be collected. The target URL will be collected only if it is included in this configuration. If this rule is not configured, it will take effect on all URLs
url?: string
// Get all request headers, empty by default
reqHeaders?: string[]
// Request body configuration, empty by default
reqBody?: string[]
// Get all return headers, empty by default
resHeaders?: string[]
// Return body configuration, empty by default
resBody?: string[]
}
export type NetworkConfig = {
// Network request collection switch, false by default
enabled?: boolean
// Cross-application tracking switch, false by default
trackingEnabled?: boolean
// Collection header body switch, false by default
recordEnabled?: boolean
// Collection data whitelist
recordConfig?: RecordRule[]
// Collection data blacklist
recordBlockConfig?: RecordRule[]
// Collection body truncation length, unit KB
bodyMaxSize?: number
// Third-party apm request header support
apms?: string[]
// trace propagators
propagators?: string[]
}
export type CrashConfig = {
// Crash collection switch, default true
enabled?: boolean
// js crash collection switch, default true
jsCrashEnabled?: boolean
// cpp crash collection switch, default true
cppCrashEnabled?: boolean
}
export type FreezeConfig = {
// Freeze monitoring switch, default false
enabled?: boolean
}
export type LaunchWaitingPolicy = {
cold?: {
// Waiting time for launching time-consuming events, default 30000ms
launchEvent?: number
// Waiting time for ability life cycle, default 10000ms
ability?: number
// Waiting time for page life cycle, default 15000ms
page?: number
},
hot?: {
// Waiting time for launching time-consuming events, default 15000ms
Default is 15000ms
launchEvent?: number
// Waiting time for launching time-consuming events, default is 10000ms
ability?: number
}
}
export type UserExperienceConfig = {
// General switch, default is false
enabled?: boolean
// Start monitoring switch, default is true
launchEnabled?: boolean
// Page monitoring switch, default is true
pageEnabled?: boolean
// Operation monitoring switch, default is true
userActionEnabled?: boolean
// Custom launch time end point switch, default is false
customLaunchEnd?: boolean
// Full trace collection switch, default is false
traceEnabled?: boolean
// Slow operation threshold, default is 3000ms
slowUserActionThreshold?: number
// Slow start threshold, default is 3000ms
slowLaunchThreshold?: number
// Hot start threshold, default is 30s
hotStartThreshold?: number
// Slow interactive threshold, default 1000ms
slowPageLoadThreshold?: number
// Slow first screen threshold, default 3000ms
slowPageDurationThreshold?: number
// Start time-consuming calculation waiting strategy
launchWaitingPolicy?: LaunchWaitingPolicy
// The proportion of error requests judged as operation errors, default is 100
actionFailureThreshold?: number
}
export type UserActionConfig = {
// General switch, default false
enabled?: boolean
}
export type WebviewConfig = {
// General switch, default false
enabled?: boolean
// Web sdk injection switch, default true
webSdkEnabled?: boolean
// Inject jsProxy switch, default true
jsProxyEnabled?: boolean
// JS snippet injection switch, default true
jsSnippetEnabled?: boolean
}
/**
* Application configuration
*/
export type InitConfig = {
// redirect server address
redirectHost: string
// application appKey
appKey: string
// context
context: common.Context
// log level, default LogLevel.INFO
logLevel?: LogLevel
// whether to use http to send data, default false, use https to send
httpEnabled?: boolean
// axios object, need to be passed in when axios needs to be intercepted
axios?: any
// maximum stack depth, default 20
stackDepth?: number
// whether to use historical data protocol for reporting (need to be set to true for Tingyun 3.8.0.0 and below platforms), default is false
legacyDataProtocol?: boolean
// build ID
buildId?: string
// whether some logic inside init uses asynchronous initialization, default is false
asyncInit?: boolean
// network request collection configuration
network?: NetworkConfig
// Crash monitoring configuration
crash?: CrashConfig
// AppFreeze monitoring configuration
freeze?: FreezeConfig
// User experience configuration
ue?: UserExperienceConfig
// User behavior analysis configuration
ua?: UserActionConfig
// Webview configuration
webview?: WebviewConfig
}
Description:
- The configuration passed in by init is the initial configuration of the SDK. After the SDK communicates with the server, the configuration sent by the server will be given priority.