All Products
Search
Document Center

Simple Log Service:Use the web tracking feature to collect logs

Last Updated:Oct 09, 2023

Simple Log Service provides the web tracking feature that you can use to collect logs from the HTML, HTML5, iOS, and Android platforms. You can also customize dimensions and metrics to collect logs. This topic describes how to use the web tracking feature to collect logs.

Background information

The web tracking feature of Simple Log Service is used to track user behavior in web applications and upload the behavior data to Simple Log Service. This allows you to analyze user behavior in an efficient manner. You can use the web tracking feature to collect user information from browsers, iOS apps, or Android apps. The information includes:

  • Browsers, operating systems, and resolutions that are used by users.

  • The browsing behavior, such as clicks and purchases on a website.

  • The amount of time that users spend on an app and whether the users are active.

Usage notes

  • After you enable the web tracking feature for a Logstore, the write permissions on the Logstore are granted to anonymous users from the Internet. This may generate dirty data because authentication may not be performed.

  • The body of each GET request cannot exceed 16 KB in size.

  • You can write a maximum of 10 MB of log data at a time by sending a POST request. For more information, see PutLogs.

Enable the web tracking feature

  1. Log on to the Simple Log Service console.

  2. In the Projects section, click the project in which you want to enable web tracking for a Logstore.

  3. On the Log Storage > Logstores tab, find the Logstore that you want to manage and choose 图标 > Modify.

  4. In the upper-right corner of the Logstore Attributes page, click Modify.

  5. Turn on WebTracking and click Save.

You can also call an API operation to enable the web tracking feature. For more information, see UpdateLogStore.

Collection methods

After you enable the web tracking feature for a Logstore, you can upload logs to the Logstore by using the following methods:

Client SDK

HTTP GET requests

Run the following command to upload logs. Replace the values of the parameters based on your business scenario. The following table describes the parameters.

curl --request GET 'http://${project}.${host}/logstores/${logstore}/track?APIVersion=0.6.0&key1=val1&key2=val2'

Parameter

Required

Description

${project}

Yes

The name of the project.

${host}

Yes

The Simple Log Service endpoint for the region. For more information, see Endpoints.

${logstore}

Yes

The name of the Logstore.

APIVersion=0.6.0

Yes

A reserved parameter.

__topic__=yourtopic

No

The topic of the log that you want to upload.

key1=val1&key2=val2

Yes

The key-value pairs that you want to upload to Simple Log Service.

Make sure that the data size is less than 16 KB.

HTML <img> tags

<img src='http://${project}.${host}/logstores/${logstore}/track.gif?APIVersion=0.6.0&key1=val1&key2=val2'/>
<img src='http://${project}.${host}/logstores/${logstore}/track_ua.gif?APIVersion=0.6.0&key1=val1&key2=val2'/>

The track_ua.gif file contains the custom parameters that you want to upload to Simple Log Service. If you use this method to upload logs, Simple Log Service records the custom parameters and the User-Agent and Referer HTTP headers as log fields.

Note

To collect the Referer HTTPS header, make sure that the URL in the preceding <img> tag uses the HTTPS protocol.

API operations

If the volume of requested data is large, you can call the API operations by sending POST requests. For more information, see PutWebtracking.