All Products
Search
Document Center

Quick Tracking:Java SDK

Last Updated:Mar 26, 2025

1. Integrate the Java SDK

Manually introduce the JAR package "quickaplus-log-collector-java-sdk-1.0.1-SNAPSHOT.jar". You can contact QT Q&A personnel to obtain

2 Basic Configurations (Required!)

Set the appkey, data collection endpoint, and authentication information

  1. Set the appkey

QtSdkConfig.setAppKey("Your appkey");

  1. Set the data collection endpoint

QtSdkConfig.setQlcEndpoint("Your data collection endpoint");

Note: You must add the suffix "/server" to the domain.

  1. Enter the authentication information

QtSdkConfig.setServiceId("Your ServiceID");
QtSdkConfig.setServiceSecret("Your ServiceSecret"); 

Obtain the location in the 「management console-track information- server tracking information」.

3. Global property settings

// Add a property.
QtGlobalPropertiesConfig.put("a", "1");
QtGlobalPropertiesConfig.put("b", "2");
// Delete a property.
QtGlobalPropertiesConfig.remove("a");
// Query all properties.
QtGlobalPropertiesConfig.getAll();
// Clear properties.
QtGlobalPropertiesConfig.clear();

4. Tracking Report

QtLog log = new QtLog.Builder()
        . eventId("order_success") // The event code. This parameter is required.
        . deviceId("dev-001") // Set the device ID (both the device ID and account ID are required)
        . userId("user-001") // Specify the account ID. You must specify one of the device ID and account ID.
        . pageName("pageName") // Set the page encoding (optional)
        . customProperty(new HashMap<>()) // Set event properties (optional)
        . systemProperty(new HashMap<>()) // Set system properties (optional)
    		. idTracking(new HashMap<>()) // Set the device identifier of the system property.
        . debugKey("dk-0001") // Set the tracking verification flag bit (optional), which must be deleted when you go online.
        . eventTimestamp(System.currentTimeMillis()) // Specify the timestamp of the client. This parameter is required.
        . serverTimestamp(System.currentTimeMillis()) // Set the server timestamp. This parameter is optional.
  			. uuid("xxxx") // Set the unique identifier of an event log. This parameter is used to generate a log_id. This parameter is supported in 1.0.1.
        . build(); // The log is built. 

  1. System properties only support the reporting of the following properties. When you submit a system property, you must enter the same key as the following, including case-sensitive keys.

Category

Developer Report Fields&QT System Property Fields

Feature

Full description

Application information

channel

String

Application Channel

app_version

String

The version of the application.

SDK

sdk_version

String

SDK Version

sdk_type

String

SDK type

System information

os

String

The supported operating system.

os_version

String

The version of the operating system.

Device Information

resolution

String

Screen Resolution

mac, oaid, openid, unionid, android_id, idfa, serial, imei, and idfv

String

The device identifier, which needs to be reported through 「idTracking(new HashMap<>())」. For more information, see the preceding demo.

device_brand

String

Device brand

device_model

String

Device models

Network and Operator

access

String

Network Type

access_subtype

String

carrier

String

ISP

Platform and scenario information

scene

String

Scene Value (mini program)

device_type

String

HTTP_header and UA

browser

String

Browser

ip

String

IP address

5 Logo Delivery

When sending logs, call the following API to send logs.

 QtLogSenderHelper.syncSendLog(log);

6 Demo

package com.alibaba.lingyang.quick.tracking.qlc.java.sdk.model;

import com.alibaba.lingyang.quick.tracking.qlc.java.sdk.config.QtGlobalPropertiesConfig;
import com.alibaba.lingyang.quick.tracking.qlc.java.sdk.config.QtSdkConfig;
import com.alibaba.lingyang.quick.tracking.qlc.java.sdk.sender.QtLogSenderHelper;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * Test sending logs.
 */
public class TestSendLog {
    /**
     * Test
     */
    @Test
    public void testSend() {
        // Configure
        QtSdkConfig.setServiceId("Your ServiceId");
        QtSdkConfig.setServiceSecret("Your ServiceSecret");
        QtSdkConfig.setAppKey("Your appkey");
        QtSdkConfig.setQlcEndpoint("Your domain name");
        QtSdkConfig.setOpenLog(true);
        QtSdkConfig.setCallback(ctx -> {
            System.out.println(ctx.getResponseCode());
            System.out.println(ctx.getResponseMessage());
            System.out.println(ctx.getSendSuccess());
            System.out.println(ctx.getSendData());
            System.out.println(ctx.getResponseData());
            System.out.println(ctx.getErrors());
        });

        // Add an attribute.
        QtGlobalPropertiesConfig.put("a", "1");
        QtGlobalPropertiesConfig.put("b", "2");
        // Delete a property.
        QtGlobalPropertiesConfig.remove("a");
        // Query all properties.
        QtGlobalPropertiesConfig.getAll();
        // Clear properties.
        QtGlobalPropertiesConfig.clear();

        Map<String,String> idTracking = new HashMap();
        idTracking.put("mac","id1");
        idTracking.put("oaid","id2");
        idTracking.put("android_id","id3");

        // Construct a log object.
        QtLog log = new QtLog.Builder()
                . eventId("order_success") // The event code. This parameter is required.
                . deviceId("dev-001") // Set the device ID (both the device ID and account ID are required)
                . userId("user-001") // Specify the account ID. You must specify one of the device ID and account ID.
                . pageName("pageName") // Set the page encoding (optional)
                . customProperty(new HashMap<>()) // Set event properties (optional)
                . systemProperty(new HashMap<>()) // Set system properties (optional)
              	. idTracking(new HashMap<>()) // Set the device identifier of the system property.
                . debugKey("dk-0001") // Set the tracking verification flag bit (optional), which must be deleted when you go online.
                . eventTimestamp(System.currentTimeMillis()) // Specify the timestamp of the client. This parameter is required.
                . serverTimestamp(System.currentTimeMillis()) // Set the server timestamp. This parameter is optional.
        // Send logs.
        QtLogSenderHelper.syncSendLog(log);
    }

}

7 Other configurations

  1. The scope of a service instance to be upgraded. By default, Service Configurations is selected.

Configure an alert contact.

Type

Required

Valid values

Description

serviceId

String

Yes

-

The AccessKey ID collected by the server.

serviceSecret

String

Yes

-

SK collected by the server

qlcEndpoint

String

Yes

-

Receive service address

appKey

String

Yes

-

appkey

openLog

Boolean

No

false

Specifies whether to enable logging.

httpConnectTimeoutMillisecond

Integer

No

null

The timeout period for sending an HTTP request (connect)

httpWriteTimeoutMillisecond

Integer

No

null

The timeout period for sending an HTTP request (write)

httpReadTimeoutMillisecond

Integer

No

null

The timeout period for sending an HTTP request (read)

senderType

QtSenderTypeEnum

No

SYNC

The sending type supports synchronous sending and asynchronous sending.

callback

Consumer<QtSendCallbackContext>

No

null

Configure a callback function

  1. Configure callbacks

Properties

Limit

Migration description

sendSuccess

Boolean

Whether the sending is successful

errors

List<String>

List of error messages that failed to be sent

qtLog

QtLog

QtLog object sent

responseData

String

Content of the returned data

responseCode

String

Code of the returned data

responseMessage

String

Message of the returned data

sendData

String

http actually sent data

Register the callback function demo

// Register the callback function.
QtSdkConfig.setCallback(ctx -> {
 System.out.println(ctx.getResponseCode());
 System.out.println(ctx.getResponseMessage());
 System.out.println(ctx.getSendSuccess());
 System.out.println(ctx.getSendData());
 System.out.println(ctx.getResponseData());
 System.out.println(ctx.getErrors());
});

  1. Generation of unique log id--log_id

By default, the SDK generates a uuid for each event log as the generation factor of the log unique id 「log_id」. If you want the 「log_id」 to be more unique, you can set the UUID. Perform the following operations:

QtLog log = new QtLog.Builder()
        .eventId("order_success")  
        .deviceId("dev-001")		
        .userId("user-001")		
        .pageName("pageName")
        .customProperty(new HashMap<>())
        .systemProperty(new HashMap<>())
    		.idTracking(new HashMap<>())
        . debugKey("dk-0001")// Set the tracking verification flag bit (optional), which must be deleted when you go online.
        .eventTimestamp(System.currentTimeMillis())
  			. uuid("xxxx") // Set the unique identifier of an event log. This parameter is used to generate a log_id. This parameter is supported in 1.0.1.
        .build();