Basic integration

更新时间: 2026-05-27 12:15:34

1. Path settings

If you are already using the Umeng+ SDK, you must update the SDK file path to prevent conflicts:

  • If you have integrated the Umeng+ SDK and are now adding the QT SDK: Call QTConfigure.resetStorePath before any other QT or Umeng+ code, and before configuring the data reporting domain.

  • If you have integrated the QT SDK and are now adding the Umeng+ SDK: Call UMConfigure.resetStorePath before any other QT or Umeng+ code, and before configuring the data reporting domain.

Warning

To avoid conflicts, reset the path of the second SDK you initialize. For example, if you initialize the Umeng+ SDK first, call QTConfigure.resetStorePath. If you initialize the QT SDK first, call UMConfigure.resetStorePath.

Note: If you reset the QT SDK path, the storage keys for user-provided information (such as user accounts and application versions) will change. If your business logic depends on these fields, you must set them again. To prevent data loss, we strongly recommend configuring the path during the initial integration.

2. Domain settings

To set the data reporting domain for your private environment, call the QtConfigure.setCustomDomain() method before pre-initialization and before any other SDK method.

/**
 * Sets the primary and standby domains for uploading analytics logs. Call this method before pre-initializing or initializing the SDK. The SDK first attempts to report data to the primary domain. If this fails, it retries with the standby domain.
 * The primaryDomain parameter cannot be null or an empty string. If it is, the SDK's pre-initialization method throws an SdkDomainUndefined runtime exception.
 * @param standbyDomain You can pass null or an empty string for the standby domain. In this case, the SDK treats the standby domain as identical to the primary domain and will retry reporting to the primary domain upon failure.
 * The domain parameters must include the "https://" prefix.
 */
public static void setCustomDomain(String primaryDomain, String standbyDomain)

Parameter

Description

primaryDomain

The primary data reporting domain for log uploads.

standbyDomain

The standby data reporting domain for log uploads.

Example:

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        QtConfigure.setCustomDomain("xxxxxx", null); // Specify your data reporting domain.
        
        // Enable debug logging
        QtConfigure.setLogEnabled(true);

        QtConfigure.preInit(this, "xxxxxx", "Channel");// Specify your appkey.
        QtTrackAgent.disableActivityPageCollection();

// ...

3. Compliant initialization

3.1. Initialization methods

Initializing the SDK enables analytics tracking. To comply with regulations that prohibit collecting personal information before user consent, Quick Tracking requires the following initialization process:

  1. Ensure your application has a privacy policy and that you obtain user consent through a dialog on the application's first launch.

  2. You must inform users that you use the Quick Tracking SDK service. Add the following statement to your privacy policy: "Our product integrates the Quick Tracking SDK, which collects your OAID, GAID, MAC address, IMEI, Android ID, IDFA, IDFV, OPENUDID, GUID, SIM card IMSI, hardware serial number, MCC (Mobile Country Code), and MNC (Mobile Network Code) to provide statistical analysis services."

  3. Initialize the Quick Tracking SDK only after the user consents to your privacy policy. Follow the technical steps below.

  • SDK pre-initialization method

Call the pre-initialization method QtConfigure.preInit() in your Application.onCreate() method. This method does not collect device information or report data to the Quick Tracking backend.

// SDK pre-initialization method.
// The preInit method has minimal performance impact and does not affect the application's cold start user experience.
public static void preInit(Context context,String appkey,String channel)
  • Initialization after privacy consent

Once the user has granted consent, you must call the pre-initialization method QtConfigure.preInit() in the Application.onCreate() method for all subsequent application cold starts. You can then call the initialization method QtConfigure.init as needed. It can be called immediately after pre-initialization or deferred to a background thread, but this call is mandatory.

public static void init(Context context,String appkey,String channel,int deviceType,String pushSecret);

Parameter

Description

Notes

appkey

A unique identifier issued by Quick Tracking for your application.

  1. The appkey must match the one in the Quick Tracking console.

  2. This appkey is sent with every event log and is used to distinguish data from different applications.

channel

The distribution channel for the application.

This is the source for the "Upgrade Channel" data in the System Properties of the Quick Tracking analytics platform.

deviceType

QtConfigure.DEVICE_TYPE_PHONE

Use the default value QtConfigure.DEVICE_TYPE_PHONE.

pushSecret

Deprecated field. Leave this empty.

Deprecated field. Leave this empty.

Example:

public class MyApplication extends Application {

    @Override
    protected void onCreate() {
        super.onCreate();
        
        // This pre-initialization method must be called in the onCreate() method of your Application class.
        QtConfigure.preInit(this,"Your appkey","Your channel name");
        
        // After the user agrees to the privacy policy, you can initialize the Quick Tracking SDK.
        if(isflag==1)
        {
          QtConfigure.init(this,"Your appkey","Your channel name",QtConfigure.DEVICE_TYPE_PHONE, "");
        }
    }
}

3.2. Get an appkey

When you initialize the SDK, you must provide an appkey. The appkey is a unique ID that represents your application in Quick Tracking and is generated when you create an application. For instructions on how to find your appkey, see Application Management.

4. Logging

You can control the output of Quick Tracking logs by using the QtConfigure.setLogEnabled(boolean) method.

Note:

  • Disable SDK debug logging before releasing your application to production to avoid excessive logging.

By default, SDK logging is disabled. You must manually enable it to see log output.

/**
* Enables or disables logging for the SDK.
* Parameter: boolean. Default is false. Set to true to view logs.
*/
QtConfigure.setLogEnabled(true);

Note:

  • To view logs from the initialization process, you must enable logging before calling the initialization method.

  • Logs are categorized into four levels:

    • Error (Prints SDK integration or runtime error messages).

    • Warn (Prints SDK warning messages).

    • Info (Prints SDK informational messages).

    • Debug (Prints SDK debugging information).

5. Special cases

5.1. Handling forced termination

If your application terminates its process with methods like kill or exit, you must first call QtTrackAgent.onKillProcess to ensure that all analytics data is saved.

public static void onKillProcess(Context context);

Parameter

Description

context

The ApplicationContext of the current host process.

6. Custom data encryption

6.1. Custom encoding and decoding interface

The SDK provides the CryptoProvider interface for implementing custom encryption and decryption algorithms. You must implement the following two methods:

public interface CryptoProvider {
    byte[] encode(Map<String, String> header, byte[] input);
    byte[] decode(Map<String, String> header, byte[] input);
}

Method

Parameter Description

public byte[] encode(Map<String, String> header, byte[] input);

Parameters: header: A map for passing extra information (like the encryption algorithm and mode) to the decryption side. The SDK Base64-encodes these key-value pairs and sends them in the dc-args HTTP header. The server then passes this map to the decode method without modification. input: The raw data to be encrypted. Returns: The encrypted data.

public byte[] decode(Map<String, String> header, byte[] input);

Parameters: header: The extra encryption information passed from the encoder. The decoder implementation uses this information to determine details such as the algorithm and mode. input: The raw data to be decrypted. Returns: The decrypted data.

6.2. Custom provider registration

QtConfigure.registerCryptoProvider(Context appContext,  CryptoProvider customProvider);

Method

Parameter Description

registerCryptoProvider

Parameters: appContext: The application's ApplicationContext object. customProvider: An object that implements the CryptoProvider interface.

6.3. Code example

import com.quick.qt.commonsdk.sm.CryptoProvider;
import com.quick.qt.commonsdk.QtConfigure;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        
        QtConfigure.setCustomDomain("Your data reporting domain", null);

        QtConfigure.setLogEnabled(true); // Enable SDK debug logging

        QtConfigure.preInit(this, "Your appkey", "Your channel");

	  // Implement the encryption and decryption interface.
        CryptoProvider customProvider = new CryptoProvider() {
            final String key = "just_for_test";
            	public byte[] customEncode(final byte[] data, final byte[] key) {
            	    // Implement your custom logic.
            	    return null;
            	}
            	public byte[] customDecode(final byte[] data, final byte[] key) {
            	    // Implement your custom logic.
            	    return null;
            	}
            @Override
            public byte[] encode(Map<String, String> header, final byte[] input) {
                byte[] result = null;
                try {
                    if (header != null) {
                        // Example
                        header.put("arg1", "value1");
                        header.put("arg2", "value2");
                    }
                    if (input == null) {
                        // Log an error if the input is null to help with debugging.
                        return result;
                    }
                    result = customEncode(input, key.getBytes()); // You must implement customEncode.
                } catch (Exception e) {
                    Log.e("customProvider:encode: ", "exception: " + e.getMessage());
                }
                return result;
            }

            @Override
            public byte[] decode(Map<String, String> header, final byte[] input) {
                byte[] result = null;
                try {
                    if (header != null && header.size() > 0) {
                        Log.i("customProvider", "K-V from encode call.");
                        for (String key : header.keySet()) {
                            Log.i("customProvider", "decode: " + key + " = " + header.get(key));
                        }
                    }
                    result = customDecode(input, key.getBytes()); // You must implement customDecode.
                } catch (Exception e) {
                    Log.e("customProvider:decode: ", "exception: " + e.getMessage());
                }
                return result;
            }
        };


	  // Register the custom CryptoProvider object.
        final Context appContext = this.getApplicationContext();
        QtConfigure.registerCryptoProvider(appContext,  customProvider);

        // Call the initialization method only after the user has granted privacy authorization.
        // Note: To ensure compliance on the first cold start, delay calling QtConfigure.init 
        // until the user agrees to the privacy policy.
	    if (privacyAuthorizationComplete(appContext)) {
	  	   QtConfigure.init(appContext, "Your appkey", "Your channel", QtConfigure.DEVICE_TYPE_PHONE, null);
	    }
        
        // ...
       
    }
}

7. Data collection control

By default, the SDK enables data collection. You can control when data collection occurs with the following APIs (available in version 1.6.1.PX and later).

7.1. Enable data collection

enableSDK()

Example:

QtTrackAgent.enableSDK();

7.2. Disable data collection

disableSDK()

Example:

QtTrackAgent.disableSDK();

Note: To support your application's privacy workflow, the SDK does not cache the data collection status. Therefore, if you disable data collection on a cold start and want it to remain disabled on subsequent launches, your application must call the disableSDK API on each subsequent launch.

If you disable the SDK after a cold start and want data collection to remain disabled for all subsequent cold starts, you must explicitly make a call.

DisableSDK API function

上一篇: Integrate and configure SDK 下一篇: Tracking API
阿里云首页 全域采集与增长分析 相关技术圈