全部產品
Search
文件中心

Quick Tracking:Java SDK

更新時間:Sep 17, 2025

整合Java SDK

手動引入jar包「quickaplus-log-collector-java-sdk-1.0.1-SNAPSHOT.jar」,可聯絡QT答疑人員擷取。

基礎配置(必填)

重要

務必設定appkey、收數網域名稱和鑒權資訊。

1. 設定appkey

QtSdkConfig.setAppKey("您的appkey"); 

2. 設定收數網域名稱

QtSdkConfig.setQlcEndpoint("您的收數網域名稱");
說明

使用Java SDK進行上報,收數會自動拼接 /server,代碼中無需再去拼接

3. 鑒權資訊填寫

QtSdkConfig.setServiceId("您的ServiceID");
QtSdkConfig.setServiceSecret("您的ServiceSecret");

擷取位置在「管理主控台--採集資訊--服務端埋點資訊」中。

全域屬性設定

// 添加屬性
QtGlobalPropertiesConfig.put("a", "1");
QtGlobalPropertiesConfig.put("b", "2");
// 刪除屬性
QtGlobalPropertiesConfig.remove("a");
// 擷取所有屬性
QtGlobalPropertiesConfig.getAll();
// 清空屬性
QtGlobalPropertiesConfig.clear();

埋點上報

QtLog log = new QtLog.Builder()
        .eventId("order_success")  //事件編碼(必填)
        .deviceId("dev-001")		//設定裝置ID(裝置ID和帳號ID必填一個)
        .userId("user-001")		//設定帳號ID(裝置ID和帳號ID必填一個)
        .pageName("pageName")	//設定頁面編碼(選填)
        .customProperty(new HashMap<>())		//設定事件屬性(選填)
        .systemProperty(new HashMap<>())		//設定系統屬性(選填)
    		.idTracking(new HashMap<>())		//設定系統屬性的裝置標識
        .debugKey("dk-0001")		//設定埋點驗證標誌位(選填),上線時必須刪除
        .eventTimestamp(System.currentTimeMillis())		//設定用戶端時間戳記(必填)
        .serverTimestamp(System.currentTimeMillis())  //設定服務端時間戳記(可選)
  			.uuid("xxxx") //設定事件記錄唯一標識,用於產生log_id(1.0.1版本支援)
        .build();		//日誌構建完成

系統屬性僅支援下述屬性上報,上報時需要填寫和下述key保持一致,包括大小寫。

類別

開發人員上報欄位&QT系統屬性欄位

類型

描述

應用資訊

channel

String

應用渠道

app_version

String

應用版本

SDK資訊

sdk_version

String

SDK版本

sdk_type

String

SDK類型

系統資訊

os

String

作業系統

os_version

String

作業系統版本

裝置資訊

resolution

String

螢幕解析度

mac、oaid、openid、unionid、android_id、idfa、serial、imei、idfv

String

裝置標識,需要通過「idTracking(new HashMap<>())」上報,具體見上述demo

device_brand

String

裝置品牌

device_model

String

裝置機型

網路及電訊廠商

access

String

網路類型

access_subtype

String

carrier

String

電訊廠商

平台及情境資訊

scene

String

情境值(小程式)

device_type

String

http_header和ua中提取

browser

String

瀏覽器

ip

String

IP地址

日誌發送

日誌發送時,調用下述API發送。

 QtLogSenderHelper.syncSendLog(log);

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.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * 測試發送日誌
 */
public class TestSendLog {
    /**
     * 測試
     */
    @Test
    public void testSend() throws UnsupportedEncodingException {
        // 配置
        QtSdkConfig.setServiceId("z1212121AOCgtG");
        QtSdkConfig.setServiceSecret("f111111HvkuYu0111111QghlWMpIiU9D");
        QtSdkConfig.setAppKey("123123123");
        QtSdkConfig.setQlcEndpoint("https://log-api.xxxxxxx.com");
        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());
        });

        // 添加全域屬性
        QtGlobalPropertiesConfig.put("a", "1");
        QtGlobalPropertiesConfig.put("b", "2");
        // 刪除全域屬性
        QtGlobalPropertiesConfig.remove("a");
        // 擷取所有全域屬性
        QtGlobalPropertiesConfig.getAll();
        // 清空全域屬性
        QtGlobalPropertiesConfig.clear();

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

        String a = "中文";
        String s = new String(a.getBytes("utf8"),"gbk");

        // 自訂屬性或使用者屬性
        Map<String,Object> customProperty = new HashMap<>();
        customProperty.put("a","1");
        customProperty.put("b",2);

        // 系統屬性
        Map<String,Object> systemProperty = new HashMap<>();
        systemProperty.put("a","1");
        systemProperty.put("b",2);

        // 構造日誌對象
        QtLog log = new QtLog.Builder()
                .eventId("$$_uer_profile") //事件編碼(必填),如果傳使用者屬性事件則編碼為$$_user_profile
                .deviceId("dev-001") //設定裝置ID(裝置ID和帳號ID必填一個)
                .userId("user-001") //設定帳號ID(裝置ID和帳號ID必填一個,$$_user_profile事件時必填)
                .uuid("xxxx") //(選填)
                .pageName("pageName") //設定頁面編碼(選填)
                .idTracking(idTracking) //設定系統屬性的裝置標識(選填)
                .customProperty(customProperty) //設定事件屬性或使用者屬性(選填)
                .systemProperty(systemProperty)//設定系統屬性(選填)
                .serverTimestamp(1111L)
                .debugKey(a)
                .eventTimestamp(System.currentTimeMillis())
                .build();
        // 發送日誌
        QtLogSenderHelper.syncSendLog(log);
    }

其他配置

  1. 服務配置

    配置

    類型

    是否必填

    預設值

    說明

    serviceId

    String

    -

    服務端採集的ak

    serviceSecret

    String

    -

    服務端採集的sk

    qlcEndpoint

    String

    -

    收數服務地址

    appKey

    String

    -

    appkey

    openLog

    Boolean

    false

    是否開啟日誌

    httpConnectTimeoutMillisecond

    Integer

    null

    發送HTTP請求的逾時時間(connect)

    httpWriteTimeoutMillisecond

    Integer

    null

    發送HTTP請求的逾時時間(write)

    httpReadTimeoutMillisecond

    Integer

    null

    發送HTTP請求的逾時時間(read)

    senderType

    QtSenderTypeEnum

    SYNC

    發送類型支援同步發送和非同步發送

    callback

    Consumer<QtSendCallbackContext>

    null

    回呼函數

  2. 回調配置

    屬性

    類型

    說明

    sendSuccess

    Boolean

    是否發送成功

    errors

    List<String>

    發送失敗的錯誤資訊列表

    qtLog

    QtLog

    發送的QtLog對象

    responseData

    String

    返回資料的內容

    responseCode

    String

    返回資料的code

    responseMessage

    String

    返回資料的Message

    sendData

    String

    http實際發送的資料

    註冊回呼函數demo

    // 註冊回呼函數
    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());
    });
  3. 日誌唯一id——log_id的產生

    預設SDK會為每一個事件記錄產生uuid,作為日誌唯一id「log_id」的產生因子。如果您希望該「log_id」的唯一性更加強,可以自己設定uuid。方式如下:

    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")//設定埋點驗證標誌位(選填),上線時必須刪除
            .eventTimestamp(System.currentTimeMillis())
      			.uuid("xxxx") //設定事件記錄唯一標識,用於產生log_id(1.0.1版本支援)
            .build();