LTS Baidu Applet SDK
If you need to collect and analyze user information on Baidu, such as browser, browsing behavior, device, device exception, and network usage records, you can use this SDK to report logs to LTS.
To use this SDK, enable the anonymous write function of log streams. After this function is enabled, the reported logs are not authenticated and may generate dirty data. For details, see Managing Log Streams.

The Baidu SDK supports cross-cloud and local log reporting for whitelisted users in regions CN North-Beijing4, CN East-Shanghai1, and CN South-Guangzhou. To use it, create a service ticket.
Transport Protocol
HTTPS
Prerequisites
- You have obtained the name of the region where LTS is deployed.
- You have obtained a project ID of your Huawei Cloud account. For details, see API Credentials.
- You have obtained the IDs of the target log group and log stream in LTS.
Version Updates
Version |
Description |
---|---|
1.0.24 |
Added support for regions CN East-Shanghai1 and CN South-Guangzhou. |
1.0.23 |
Supported quick app reporting. |
1.0.21 |
|
1.0.19 |
Changed the time threshold range from 1–60 to 1–1800, and changed the default value from 30 to 3. |
1.0.18 |
|
1.0.15 |
Supported reporting logs to LTS through multiple log streams. |
Instructions
Add the reporting address to the domain name list of the Baidu developer platform. For details about the reporting address, see Parameters.
Installing the SDK
Run the npm i lts-mini-sdk command in the root directory of the applet to install the SDK. You can download the latest SDK from the open-source repository.
Sample Code
const miniSDK = require('lts-mini-sdk').default; // import miniSDK from 'lts-mini-sdk'; App({ onLaunch(options) { // Initialization const baidumini = new miniSDK({ // Reporting region region: string, // Huawei Cloud project ID projectId: string, // Log reporting address url: string, // LTS log group ID groupId: string, // LTS log stream ID streamId: string, // Log group to which the logs belong group: string, // Debug log level debug: string, // Platform of the current applet platform: string, // Records threshold cacheThreshold: number, // Time interval threshold timeInterval: number, }); // Immediately report a single record, with labels baidumini.reportImmediately({ 'name': 'xiaoming', 'age': 18 }, { 'key': 'value' }); // Immediately report a single record, without labels baidumini.reportImmediately([{ key: 'value', number: 1, array: [], json: { json: 'json' } }, { 'key': 'value' }]); // Cache and report multiple records, with labels baidumini.report([{ 'name': 'xiaohong', 'age': 18 }, { 'name': 'xiaobai', 'age': 20 }], { 'key': 'value }); // Cache and report multiple records, without labels baidumini.report([{ 'name': 'xiaohong', 'age': 18 }, { key: 'value', number: 1, array: [], json: { json: 'json' } }]); // Cache and report multiple records, with multiple labels (max. 50) baidumini.report([{ 'name': 'xiaohong', 'name': 'xiaolan' }], {'version': '1.0.0', 'render': 'mini', 'link': '/', from: 'baidu'}); } });
Parameters
- Parameters
Table 2 Parameters Field
Type
Mandatory
Default Value
Description
region
String
Yes
-
Region where LTS is located.
projectId
String
Yes
-
Project ID of the account. The value contains a maximum of 128 characters.
groupId
String
Yes
-
Log group ID. The value contains a maximum of 128 characters.
streamId
String
Yes
-
Log stream ID. The value contains a maximum of 128 characters.
url
String
No
-
Public network domain name for reporting. The value can contain a port number, for example, https://lts-access.cn-north-4.myhuaweicloud.com:443. If no URL is set, a link is automatically generated based on the region. The format is as follows: https://lts-access.{region}.myhuaweicloud.com. The domain name must be valid on the Baidu applet background (for details, see the server domain name setting on the applet official website). The value contains a maximum of 128 characters.
- When the SDK is used to report logs across clouds or locally, port 443 is used.
- When Huawei Cloud hosts report logs via the Huawei Cloud intranet, port 8102 is used.
debug
String
No
OFF
Output level of the console debugging information. The options are OFF, ERROR, WARN, INFO, and DEBUG, in ascending order. The highest level is DEBUG. If an invalid value is entered, the default value OFF is used. If this parameter is set to true, DEBUG logs are enabled. If this parameter is set to false, DEBUG logs are disabled.
cacheThreshold
int
No
30
By default, the cache threshold is 30 records. When the number of cached records reaches the threshold (range: 30 to 1,000), cached records are reported.
timeInterval
number
No
3
By default, records are reported every 3 seconds. When the threshold interval (range: 1 to 1,800) is reached, cached records are reported.
platform
String
No
baidu
Platform that supports data reporting. Options:
- baidu: Baidu applet
- wx: WeChat applet
- dd: DingTalk applet
- my: Alipay applet
- quick: Quick app
group
String
No
-
Log group ID.
- Parameters of the report method for reporting logs
Table 3 report parameters Field
Type
Mandatory
Default Value
Description
content
Object | Array<Object>
Yes
-
Object or object array to be reported. Each object can contain a maximum of 300 key-value pairs. The maximum length of the JSON string is 1024 × 30 characters. Excess characters will be truncated.
Each object in the array can contain a maximum of 300 key-value pairs. The maximum length of the JSON string is 1024 × 30 bytes. Excess characters will be truncated.
The log field name cannot contain double underscores (__).
labels
Object
No
-
Log labels. The outermost key-value pair can contain a maximum of 50 key-value pairs. The outermost key can contain a maximum of 64 characters including letters, digits, and underscores (_), and must start with a letter. The maximum length of the converted JSON string is 1024 × 30 characters. If the length exceeds the limit, the record will not be reported.
The log field name cannot contain double underscores (__).
- Parameters of the reportImmediately method for reporting logs immediately
Table 4 reportImmediately parameters Field
Type
Mandatory
Default Value
Description
content
Object | Array<Object>
No
-
Object or object array to be reported immediately. Each object can contain a maximum of 300 key-value pairs. The maximum length of the JSON string is 1024 × 30 characters. Excess characters will be truncated.
Each object in the array can contain a maximum of 300 key-value pairs. The maximum length of the JSON string is 1024 × 30 bytes. Excess characters will be truncated. If this parameter is left empty, cached data will be reported immediately. The log field name cannot contain double underscores (__).
labels
Object
No
-
Log labels. The outermost key-value pair can contain a maximum of 50 key-value pairs. The outermost key can contain a maximum of 64 characters including letters, digits, and underscores (_), and must start with a letter. The maximum length of the converted JSON string is 1024 × 30 characters. If the length exceeds the limit, the record will not be reported.
The log field name cannot contain double underscores (__).
Obtaining Parameters
- Regions
Table 5 Regions Name
Region
CN North-Beijing4
cn-north-4
CN East-Shanghai1
cn-east-3
CN South-Guangzhou
cn-south-1
- To obtain a log group's ID, choose Log Management in the navigation pane of the LTS console and hover over the target log group's name.
- To obtain a log stream's ID, click
next to the corresponding log group and hover over the target log stream's name.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot