All Products
Search
Document Center

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

Last Updated:Sep 02, 2024

You can use the web tracking feature to collect and analyze the following user information from browsers and mini programs: browser details, browsing behavior, purchase behavior, and dwell time. To upload user behavior information to a Logstore of Simple Log Service, you need to only make minor changes to the service code. For example, you can add trace pixels to frontend pages or integrate web tracking SDK for JavaScript.

Introduction to the web tracking feature

  • The web tracking feature is used to track user behavior by adding specific code snippets to web pages. You can use the web tracking feature to collect information about interaction between users and websites. The information includes accessed pages, dwell time on the pages, and geographical locations.

    The web tracking feature embeds an invisible, 1 x 1 pixel image into a web page. When you access the page, the browser initiates a GET request to the web server, and the server automatically sends parameters in the request URL to Simple Log Service for storage. The parameters are equivalent to user logs in this case. This type of request usually contains user-related information, such as IP addresses, browser types, and operating systems.

  • You can use the web tracking feature to track user behavior in browsers and mini programs and upload the behavior data to Simple Log Service. Then, you can analyze user behavior in an efficient manner. You can use the web tracking feature to collect the following user information from browsers, iOS apps, and Android apps:

    • The browsers, operating systems, and resolutions that are used.

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

    • The dwell time on an app and active users.

Step 1: Turn on WebTracking for a Logstore

Important

If you turn on WebTracking for a Logstore, the write permissions on the Logstore are granted to anonymous users from the Internet. This may generate dirty data because valid authentication is not performed. We recommend that you use Security Token Service (STS) to collect logs. In this case, you do not need to turn on WebTracking for the Logstore. For more information, see the Use the web tracking feature and STS to collect logs section of this topic.

  • Simple Log Service console

    1. Log on to the Simple Log Service console.

    2. In the Projects section, click the project that you want to manage.

    3. On the Log Storage > Logstores tab, find the Logstore for which you want to turn on WebTracking and choose 图标 > Modify.

    4. On the Logstore Attributes page, click Modify in the upper-right corner.

    5. Turn on WebTracking and click Save.

  • API

    • Call the UpdateLogStore operation to turn on WebTracking. You must set the enable_tracking parameter to true.

Step 2: Collect logs

  • Client SDK: Web tracking SDK for JavaScript is integrated in the code to upload logs of custom types to a Logstore. The logs are related to form submission, page submission, and exception reports.

  • HTTP GET request: The frontend code of a website sends a GET request to collect logs in a simple manner.

  • HTML img tag: The src attribute of the HTML<img> tag is used to initiate requests to a web server. A request URL references a GIF image. In this case, JavaScript environments and configuration of cross-domain access are not required.

  • API operation: If the amount of requested data is large, you can call API operations by sending POST requests to upload data.

Client SDK

image

For more information about how to initialize the web tracking SDK and upload logs, see Use web tracking SDK for JavaScript to collect website logs and Use web tracking SDK for JavaScript to collect mini program logs.

HTTP GET request

image

Run the following command in the curl tool to send an HTTP request and upload logs. Configure parameters based on your business requirements.

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 where your project resides. For more information, see Endpoints.

${logstore}

Yes

The name of the Logstore.

APIVersion=0.6.0

Yes

The reserved field.

__topic__=yourtopic

No

The topic of the logs to upload.

key1=val1&key2=val2

Yes

The key-value pairs to upload. You can specify multiple key-value pairs. Make sure that the value size is less than 16 KB.

HTML img tag

Add the following tags to the frontend pages of your website.

Important
  • When the track_ua.gif image is used, the web server uploads not only custom parameters in requests but also the UserAgent and Referer headers of requests as log fields.

  • To collect the Referer header of requests on HTTPS pages, make sure that the URLs in the following <img> tags use the HTTPS protocol.

<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'/>
image
  1. A user visits a website that contains an <img> tag.

  2. The browser identifies the <img> tag and attempts to load the image referenced in the URL specified for the src attribute of the <img> tag. In this case, the browser sends an HTTP GET request to Simple Log Service to load the image.

  3. Simple Log Service parses key1, key2, value1, and value2 in the URL and stores the keys and values. APIVersion is a reserved field and is not included in logs.

  4. Simple Log Service returns an invisible image to the browser.

API operation

Call the PutWebtracking operation to upload logs. For more information, see PutWebtracking.

image

Use the web tracking feature and STS to collect logs

If you turn on WebTracking for a Logstore, the write permissions on the Logstore are granted to anonymous users from the Internet. This may generate dirty data because valid authentication is not performed. If you use STS to collect logs, you do not need to turn on WebTracking for the Logstore. For more information about the how to initialize the STS plug-in of web tracking SDK for JavaScript and use the plug-in to upload logs, see Use the STS plug-in of web tracking SDK for JavaScript to upload logs.

image