CLS allows you to collect logs from the HTML, HTML5, Weixin Mini Programs, iOS, and Android clients.
Use cases
Anonymous write applies to user information collection from browsers, Weixin Mini Programs, iOS apps, and Android apps. The information includes:
Browsers, operating systems, and resolutions used by users.
Users' browsing behavior, such as clicks and purchases, on a website.
The time users spend in an app and whether they are active.
Directions
Step 1. Enable Anonymous write
Note:
Enabling Anonymous write grants anonymous internet users the write access to the target log topic. This may generate dirty data because authentication is not performed.
2. Click Log Topic on the left sidebar. On the log topic management page, click Create Log Topic, or click Edit for an existing log topic.
3. In the pop-up window, toggle on Anonymous write to enable anonymous write.
Step 2. Upload logs
After enabling Anonymous write, you can upload logs to a log topic using the following methods.
Method 1: Use browser JavaScript SDK
Method 2: Use Weixin Mini Programs JavaScript SDK
Method 3: Use an HTTP GET request
Use the following command to upload logs. Replace parameters according to your needs.
curl --request GET 'http://{host}/track?topic_id={topic_id}&key1=val1&key2=val2'
|
${host} | Yes | The endpoint of the region where CLS resides. For more information, see Available Regions. |
${topic_id} | Yes | topic id |
key1=val1&key2=val2 | Yes | The key-value pairs you want to upload to CLS. Ensure that the data is less than 16 KB. |
Method 4: Use HTML img tag
Note:
The track.gif
file contains the custom parameters that you want to upload. If you use this method, CLS records the custom parameters as well as the User-Agent HTTP header as log fields.
<img src='http://${host}/track.gif?topic_id={topic_id}&key1=val1&key2=val2'/>
Method 5: Use an HTTP POST request
If you need to upload a large amount of data, you can use the POST method.
Notes
This method applies to collection of webpage or client logs.
When using Web Tracking to collect logs, only one log can be written to a single request.
You can merge multiple logs into a single request.
This method cannot be used to write log data to multiple log topics.
Request headers
Request syntax
POST http://${host}/tracklog?topic_id=${topic_id} HTTP/1.1
|
${host} | Yes | The endpoint of the region where CLS resides. For more information, see Available Regions. |
${topic_id} | Yes | topic id |
Example
POST /tracklog?topic_id={topic_id} HTTP/1.1
Host:ap-guangzhou.cls.tencentcs.com
Content-Type:application/json
{
"logs": [{
"contents": {
"key1": "value1",
"key2": "value2"
},
"time": 123456789
}],
"source": "127.0.0.1"
}
Apakah halaman ini membantu?