TLS supports the WebTracking feature, which collects log data from various mobile platforms, including HTML, iOS, Android, and other platforms, through the WebTracking interface provided by OpenAPI. This document describes the steps for enabling the WebTracking feature for a log topic and collecting log data and sending it to the server.
Background information
In lightweight event tracking scenarios, it is usually necessary to quickly complete event tracking setup and data reporting tasks. For example, in certain marketing activities, efficient methods are required to collect and report user behavior and browsing data, including the user's device and browser information, records of browsing behavior, dwell time on specific content, and many other types of data. WebTracking technology, also known as Tracking Pixel, allows you to embed a 0-pixel image on a page. This image is invisible to users by default. When the page is accessed and the image is loaded, a GET request is sent to the server, and the parameters are passed to the server at that time.
TLS provides a lightweight log collection solution through the WebTracking feature, uploading data to the TLS server via HTTP GET requests. It supports tracking using browser, JavaScript, and image tags, making it suitable for various scenarios that do not require any authentication, such as static web pages, ad delivery, promotional materials, and mobile data collection.
When writing log data through the WebTracking interface, TLS adds the following reserved fields to the original log by default:
Notice
- After enabling WebTracking for a log topic, data written via the WebTracks API does not require authentication. This grants anonymous write access to the public network, but it may cause dirty data.
- When calling the WebTracks API via a GET request, uploading body content larger than 16 KiB is not supported.
- When calling the WebTracks interface via a POST request, the maximum amount of log data that can be written each time is 5 MiB. For more information, see WebTracks.
Step 1: Enable the WebTracking feature
You can enable the WebTracking feature for a specified log topic via the console. Logs can be collected through WebTracking only after the feature has been successfully enabled.
- Select the region where torch log service is located from the top navigation bar.
- On the left navigation bar, select Resource Management > Project.
- On the Project page, locate the specified project and click the project name.
- In the Log Topic area, locate the specified log topic, and in the corresponding Operation column, click Edit.
- , turn on the WebTracking switch, and click OK.
Step 2: Collect logs via WebTracking
After enabling WebTracking, you can upload logs to the specified log topic using the following methods.
Browser JavaScript SDK methods
The TLS browser JavaScript SDK provides methods such as send() for uploading log data. You can see Browser JavaScript SDK to install the necessary dependencies, and call the API to initiate a request. In addition, TLS provides sample projects for the browser JavaScript SDK on GitHub for your reference. HTML img tag methods
You can embed a 0-pixel image on the page using the img tag. This image is invisible to users by default. When the page is accessed and the image is loaded, a GET request is sent to the server, and the data in <img> is sent to the log topic specified by TLS.
For example, embed the following img tag in the page:
Note:
- ${host} is the public service address of TLS, for service addresses in each region, please refer to Service address.
- WebtrackUa.gif is a fixed name. In addition to uploading custom parameters, this image also uploads the access terminal name (UserAgent) and page source (referer) from the HTTP Header as log fields to TLS.
- Supports the HTTPS protocol, that is, the WebTracking link in the img tag can be specified as HTTPS, and in this case, it is also possible to collect referrer information from HTTPS pages.
HTTP GET request method
You can call the WebTracks API using an HTTP GET request to upload log data to the specified log topic.
Http POST request method
To upload a large amount of data in a request, use the POST method to call the WebTracks API. For more information, see WebTracks.