WeChat SDK Access
Prerequisites
- Before using the WeChat SDK, you need to register a HUAWEI ID and enable APM.
- To ensure that WeChat logs can be reported, add the report address to the domain name list of the WeChat developer platform as a valid domain name.
Transport Protocol
HTTPS
Version Updates
Version |
Update Description |
---|---|
2.0.7 |
Supported sampling rate settings. |
2.0.5 |
Added the uid and tag fields and the setUid and setTag methods. |
2.0.4 |
Fixed the issue that the SDK overwrites the function scope of the applet. |
2.0.1 |
Added the README help document. |
2.0.0 |
This is the first release of the applet SDK. |
Configuring the Report Address
Add the APM report address https://apm-web.region.myhuaweicloud.com to the domain name list of the applet developer platform.
Currently, this function is supported in the AP-Singapore region only. The report address is https://apm-web.ap-southeast-3.myhuaweicloud.com.
Procedure
- On the Web Monitoring page, click Connect Website.
- Select WeChat, select an application, enter a site name, and click Create Website.
- Install the SDK. Run the npm i apm-mini-sdk command in the root directory of the project to pull the SDK software package.
- Enable the SDK. The code will be automatically embedded in the applet. You can execute the code anywhere in the project (app.js is recommended). The SDK can be imported using a file or npm.
- Integrating the SDK using npm
- Ensure that the project has the package.json file. If it does not exist, run the npm init command in the root directory of the project to create one:
- Run the SDK installation command to install the SDK software package:
- Use the developer tool to build the npm library file of the current project. If the apm-mini-sdk file exists in the miniprogram_npm folder, the import is successful.
4. Copy the code for tracking from the page to the app.js file.
- Integrating the SDK by importing files
- Find the app.js file (node_modules > apm-mini-sdk > app.js) in the SDK folder, copy it from node_module to the root directory, and rename it.
- Copy the code for tracking from the page to the app.js file.
Table 2 Configuration parameters Parameter
Mandatory
Default Value
Description
appId
Yes
-
Website ID. Each site has its own app ID.
apiRepo
No
true
Auto API reporting.
Reports API call details and success rate.
thirdApi
No
true
Third-party API reporting.
Reports third-party API information.
hashMode
No
true
Auto hash mode parsing.
Processes the content following # as a part of a URL. If this option is disabled, # is regarded as an anchor.
JsErrorClear
No
true
JS error tracing.
Listens on and reports all JS errors. This will change the service paths displayed on your browser.
smartJsErr
No
true
JS errors mitigation.
Stops reporting a JS error after 100 times.
webResource
No
false
Page resource reporting.
Collects loading performance. Only WeChat can collect First Paint (FP) information. Other mini programs do not support page resource reporting. If required, use the custom reporting function.
traceType
No
apm
Open tracing.
Tracing: Traces the frontend and backend using OpenTelemetry. If this option is disabled, APM tracing will be used instead. To view the tracing effect, choose API Requests, go to the URL details page, and click Analyze.
uid
No
-
Custom ID (string), which is added in version 1.0.46.
tag
No
-
Custom tag (string), which is added in version 1.0.46.
sampleRate
No
1
Sampling rate. Range: 0–1. For example, if this parameter is set to 0.5, the sampling rate is 50%. This parameter can be configured in SDK 2.0.7 or later.
- Find the app.js file (node_modules > apm-mini-sdk > app.js) in the SDK folder, copy it from node_module to the root directory, and rename it.
- Integrating the SDK using npm
- (Optional) Configure custom statistics reporting.
Method
Description
agent.log(key: String, value: String)
key: event name (string). Max.: 2,048 characters.
value: event content. Valid JSON objects such as String, Array, HashMap, and Number are supported. Max.: 30,720 characters.
- (Optional) Dynamically set the UID.
Method
Description
agent.setUid(uid: String)
uid (string): max. 2,048 characters.
- (Optional) Dynamically set the tag.
Method
Description
agent.setTag(tag: String)
tag (string): max. 2,048 characters.
- Customize the reporting of loading performance data. If the parameters under PerformanceData have values and the sum of these values is greater than 0, data will be reported.
agent.addPerformanceData(data: PerformanceData)
Table 3 PerformanceData parameters Parameter
Type
Mandatory
Default Value
Description
loadTime
Number
No
0
Load time
fcp
Number
No
0
First Contentful Paint (FCP)
fp
Number
No
0
First Paint (FP)
domtti
Number
No
0
Time to Interactive (TTI)
cls
Number
No
0
Cumulative Layout Shift (CLS)
inp
Number
No
0
Interaction to Next Paint (INP)
lcp
Number
No
0
Largest Contentful Paint (LCP)
Data Reporting Policy
- Basic user data and custom statistics are reported immediately when a user accesses the page.
- Page performance data is triggered to report after the page is loaded.
- Other types of data (such as API data and JS error data) are reported every minute.
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