tencent cloud

피드백

Uploading Logs via Anonymous Write

마지막 업데이트 시간:2024-01-20 17:14:28
    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.
    1. Log in to the CLS console.
    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

    For detailed directions, see Uploading Logs via 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'
    Parameter
    Required
    Description
    ${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
    This method only uses common request headers. For more information, see Common Request Headers.
    Request syntax
    POST http://${host}/tracklog?topic_id=${topic_id} HTTP/1.1
    Parameter
    Required
    Note
    ${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"
    }
    
    문의하기

    고객의 업무에 전용 서비스를 제공해드립니다.

    기술 지원

    더 많은 도움이 필요하시면, 티켓을 통해 연락 바랍니다. 티켓 서비스는 연중무휴 24시간 제공됩니다.

    연중무휴 24시간 전화 지원