Mini programs & mini games
Before you integrate the SDK, read Pre-integration preparation.
If you develop mini games with a game engine, see the integration plans for common game engines: Egret Engine, LayaAir, and CocosCreator.
Latest version: v3.8.1 Download (mini program) Download (mini game)
Update time: 2026-09-29
Downloads: Source code
This document applies to v3.0.0 and later. For earlier versions, see Mini Program & Mini Game Integration Guide (V2), Mini program SDK download (v2.2.4), and Mini game SDK download (v2.2.4)
The Mini Program & Mini Game SDK provides a standard set of APIs for reporting data on common mini program platforms, quick apps, and mini game platforms. The currently supported platforms and their corresponding files are as follows:
Mini programs:
- WeChat mini program: tdanalytics.wx.min.js
- Baidu mini program: tdanalytics.swan.min.js
- Douyin mini program: tdanalytics.tt.min.js
- Alipay mini program: tdanalytics.my.min.js
- DingTalk mini program: tdanalytics.dd.min.js
- Kuaishou mini program: tdanalytics.ks.min.js
- Quick app: tdanalytics.quick.min.js
- QQ mini program: tdanalytics.qq.min.js
- JD mini program: tdanalytics.jd.min.js
- 360 mini program: tdanalytics.qh.min.js
Mini games:
- WeChat mini game: tdanalytics.mg.wx.min.js
- QQ mini game: tdanalytics.mg.qq.min.js
- Douyin mini game: tdanalytics.mg.tt.min.js
- Baidu mini game: tdanalytics.mg.swan.min.js
- bilibili mini game: tdanalytics.mg.bl.min.js
- Huawei quick game: tdanalytics.mg.huawei.min.js
- OPPO quick game: tdanalytics.mg.oppo.min.js
- vivo quick game: tdanalytics.mg.vivo.min.js
- Meizu quick game: tdanalytics.mg.mz.min.js
- HONOR quick game: tdanalytics.mg.honor.min.js
- Xiaomi quick game: tdanalytics.mg.xiaomi.min.js
- Taobao mini game: tdanalytics.mg.tb.min.js
- Kuaishou mini game: tdanalytics.mg.ks.min.js
- Alipay mini game: tdanalytics.mg.my.min.js
- Meituan mini game: tdanalytics.mg.mt.min.js
- JD mini game: tdanalytics.mg.jd.min.js
- H5 mini game
- UC mini game
- Facebook mini game
1. Integrate the SDK
- Mini program
- Quick app
- Mini game
Download the mini program SDK, and import the corresponding SDK file in app.js (WeChat mini program is used as an example):
var TDAnalytics = require("./tdanalytics.wx.min.js");
After you import the SDK, you can create an SDK instance and start reporting data:
// AE SDK configuration object
var config = {
appId: "YOU-APP-ID", // Project APP ID
serverUrl: "https://youserverurl.com", // Data reporting URL
autoTrack: {
appLaunch: true, // Auto-track ta_mp_launch
appShow: true, // Auto-track ta_mp_show
appHide: true, // Auto-track ta_mp_hide
pageShow: true, // Auto-track ta_mp_view
pageShare: true // Auto-track ta_mp_share
}
};
// Initialize
TDAnalytics.init(config);
The parameters of the AE configuration object are as follows:
-
appId: The APP ID of your project. Required. You can find it on the Project Settings page in AE -
serverUrl: The data reporting URL. Required- If you use the cloud service, enter: https://global-receiver-ta.thinkingdata.cn
- If you use an on-premises deployment, confirm the reporting URL with your operations team
-
enableBatch: Caches data locally first and then sends it in batches. Defaults to false -
autoTrack: Optional. Specifies whether to enable auto-tracking. Each element represents one of the following auto-tracked events. All of them are disabled by default:appLaunch: Auto-tracks mini program initialization. It is triggered only once per useappShow: Auto-tracks the mini program being launched or entering the foreground from the backgroundappHide: Auto-tracks the mini program going from the foreground to the background, and records the duration of this visit (from launch to going to the background)pageShow: Auto-tracks a mini program page being displayed or switched to the foreground, and records the page path and the referrer pathpageShare: Auto-tracks mini program sharing (forwarding), and records the page from which it is shared
For details about auto-tracked events, see the Auto-tracked events section
Download the mini program SDK, and in app.ux, import the corresponding SDK
file tdanalytics.quick.min.js:
var TDAnalytics = require("./tdanalytics.quick.min.js");
Then you can create an SDK instance and start reporting data:
// AE SDK configuration object
var config = {
appId: "YOU-APP-ID", // Project APP ID
serverUrl: "https://youserverurl.com", // Data reporting URL
persistenceComplete(ta) {
// Callback invoked when asynchronous storage initialization completes. You can perform cache-related deletions here
//TDAnalytics.clearSuperProperties();
}
};
// Initialize
TDAnalytics.init(config);
The parameters of the AE configuration object are as follows:
-
appId: The APP ID of your project. Required. You can find it on the Project Settings page in AE -
serverUrl: The data reporting URL. Required- If you use the cloud service, enter: https://global-receiver-ta.thinkingdata.cn
- If you use an on-premises deployment, confirm the reporting URL with your operations team
-
persistenceComplete: Optional. Quick apps read the cache asynchronously, so querying or deleting cache-related fields before the cache has been read may produce unexpected results. To make sure that cache queries and deletions during initialization are performed correctly, perform these operations in the
persistenceComplete callback. Cache-related data includes the user IDs (#account_id and #distinct_id), the device ID, super properties, and so on.
More about persistenceComplete:
To address SDK state issues caused by asynchronous calls, we set a Ready state for each instance. An instance is considered Ready when all of the following conditions are met:
- System information has been obtained: we call the platform's
getSystemInfo()to obtain system information - Cached information has been read: quick apps read the cache asynchronously
- The user has called
TDAnalytics.init()
Before an instance enters the Ready state, we cache all reported data. After the instance is initialized, the cache is cleared, which keeps the state correct.
Pay special attention to the following at the different stages of asynchronous cache reading:
- Before the cached information is read, you can set super properties and log in users.
- When the cache has been read, we overwrite the previously cached values with the new values.
- If you call functions that delete or read previously cached information before the cache has been read, the data actually in the cache cannot be read or deleted.
For point 3 above, you can pass in a callback function (persistenceComplete) during initialization to ensure the calling order.
Note: Quick apps do not support auto-tracked events yet
Download the mini game SDK, and import the corresponding SDK file in game.js (WeChat mini game is used as an example):
var TDAnalytics = require("./tdanalytics.mg.wx.min.js");
// AE SDK configuration object
var config = {
appId: "YOUR_APPID", // Project APP ID
serverUrl: "YOUR_SERVER_URL", // Reporting URL
autoTrack: {
appShow: true, // Auto-track ta_mg_show
appHide: true // Auto-track ta_mg_hide
}
};
// Initialize
TDAnalytics.init(config);
The parameters of the AE configuration object are as follows:
-
appId: The APP ID of your project. Required. You can find it on the Project Settings page in AE -
serverUrl: The data reporting URL. Required- If you use the cloud service, enter: https://global-receiver-ta.thinkingdata.cn
- If you use an on-premises deployment, confirm the reporting URL with your operations team
-
autoTrack: Optional. Specifies whether to enable auto-tracking. Each element represents one of the following auto-tracked events. All of them are disabled by default:appShow: Auto-tracks the mini game being launched or entering the foreground from the backgroundappHide: Auto-tracks the mini game going from the foreground to the background, and records the duration of this visit (from launch to going to the background)
Before you report data, add the data transfer URL to the request list of server domain names in the development settings of the WeChat Official Accounts Platform or other platforms.
2. Common features
Before you use the common features, we recommend that you read the user identification rules. By default, the SDK generates a random number as the distinct ID and stores it locally. Before a user logs in, the distinct ID is used as the user's identifier. Note: The distinct ID changes when the user clears the cache or switches devices.
2.1 Set the account ID
When a user logs in, you can call login to set the user's account ID. The AE platform uses the account ID as the identifier, and the account ID you set is kept until logout is called. Calling login multiple times overwrites the previous account ID
// The unique login identifier of the user, which corresponds to #account_id in the reported data. In this case, the value of #account_id is TA
TDAnalytics.login("TA");
This method does not upload a login event
2.2 Set super properties
Super properties are properties that every event carries. You can call setSuperProperties to set super properties. We recommend setting super properties before you send events. Some important properties, such as a user's membership level and source channel, need to be set in every event; in this case, you can set them as super properties.
var superProperties = {
channel : "ta",
age : 1,
isSuccess : true,
birthday : new Date(),
object : { key : "value" },
object_arr : [ { key : "value" } ],
arr : [ "value" ]
};
TDAnalytics.setSuperProperties(superProperties);
Super properties are saved in the cache, so you don't need to call this every time the app starts. If you call setSuperProperties to upload a super property that was set before, the new value overwrites the previous one.
- Key is the name of the property and is of the string type. It must start with a letter, can contain only digits, letters, and underscores "_", and can be up to 50 characters long. Keys are not case-sensitive; AE converts all letters to lowercase
- Value is the value of the property. Supported types are string, number, Boolean, time, object, object group, and array
Event properties and user properties have the same requirements as super properties
2.3 Send events
You can call track to upload events. We recommend setting event properties and the conditions for sending them according to the tracking plan you prepared earlier. The following example tracks a user purchasing a product:
TDAnalytics.track({
eventName: "product_buy", // Event name
properties: {
product_name: "Product Name"
} //Event properties
});
The event name is of the string type. It must start with a letter, can contain digits, letters, and underscores "_", and can be up to 50 characters long.
2.4 Set user properties
For general user properties, you can call userSet to set them. Properties uploaded through this API overwrite the existing property values. If the user property did not exist before, it is created with the same type as the value passed in. The following example sets the user name:
//username is TA at this point
TDAnalytics.userSet({
properties: {
username: "TA"
}
});
//username is AE at this point
TDAnalytics.userSet({
properties: {
username: "AE"
}
});
3. Best practices
The following sample code includes all of the operations above. We recommend using them in the following order
- Mini program
- Quick app
- Mini game
After you import the SDK, you can create an SDK instance and start reporting data:
var TDAnalytics = require("./tdanalytics.wx.min.js");
var config = {
appId: "YOU-APP-ID", // Project APP ID
serverUrl: "https://youserverurl.com", // Data reporting URL
autoTrack: {
appLaunch: true, // Auto-track ta_mp_launch
appShow: true, // Auto-track ta_mp_show
appHide: true, // Auto-track ta_mp_hide
pageShow: true, // Auto-track ta_mp_view
pageShare: true // Auto-track ta_mp_share
}
};
// Initialize
TDAnalytics.init(config);
// The unique login identifier of the user, which corresponds to #account_id in the reported data. In this case, the value of #account_id is TA
TDAnalytics.login("TA");
//Set super properties
var superProperties = {
channel : "ta", //String
age : 1,//Number
isSuccess : true,//Boolean
birthday : new Date(),//Time
object : { key : "value" },//Object
object_arr : [ { key : "value" } ],//Object group
arr : [ "value" ]//Array
};
TDAnalytics.setSuperProperties(superProperties);
//Send an event
TDAnalytics.track({
eventName: "product_buy", // Event name
properties: {
product_name: "Product Name"
} //Event properties
});
//Set user properties
TDAnalytics.userSet({
properties: {
username: "AE"
}
});
Import the corresponding SDK (tdanalytics.quick.min.js) in app.ux
Then you can create an SDK instance and start reporting data:
var TDAnalytics = require("./tdanalytics.quick.min.js");
// AE SDK configuration object
var config = {
appId: "YOU-APP-ID", // Project APP ID
serverUrl: "https://youserverurl.com", // Data reporting URL
persistenceComplete(ta) {
// Callback invoked when asynchronous storage initialization completes. You can perform cache-related deletions here
//TDAnalytics.clearSuperProperties();
}
};
// Initialize
TDAnalytics.init(config);
// The unique login identifier of the user, which corresponds to #account_id in the reported data. In this case, the value of #account_id is TA
TDAnalytics.login("TA");
//Set super properties
var superProperties = {
channel : "ta", //String
age : 1,//Number
isSuccess : true,//Boolean
birthday : new Date(),//Time
object : { key : "value" },//Object
object_arr : [ { key : "value" } ],//Object group
arr : [ "value" ]//Array
};
TDAnalytics.setSuperProperties(superProperties);
//Send an event
TDAnalytics.track({
eventName: "product_buy", // Event name
properties: {
product_name: "Product Name"
} //Event properties
});
//Set user properties
TDAnalytics.userSet({
properties: {
username: "AE"
}
});
Import the corresponding SDK file in game.js (WeChat mini game is used as an example). After you import the SDK, you can create an SDK instance and start reporting data:
var TDAnalytics = require("./tdanalytics.mg.wx.min.js");
var config = {
appId: "YOUR_APPID", // Project APP ID
serverUrl: "YOUR_SERVER_URL", // Reporting URL
autoTrack: {
appShow: true, // Auto-track ta_mg_show
appHide: true // Auto-track ta_mg_hide
}
};
//Initialize
TDAnalytics.init(config);
// The unique login identifier of the user, which corresponds to #account_id in the reported data. In this case, the value of #account_id is TA
TDAnalytics.login("TA");
//Set super properties
var superProperties = {
channel : "ta", //String
age : 1,//Number
isSuccess : true,//Boolean
birthday : new Date(),//Time
object : { key : "value" },//Object
object_arr : [ { key : "value" } ],//Object group
arr : [ "value" ]//Array
};
TDAnalytics.setSuperProperties(superProperties);
//Send an event
TDAnalytics.track({
eventName: "product_buy", // Event name
properties: {
product_name: "Product Name"
} //Event properties
});
//Set user properties
TDAnalytics.userSet({
properties: {
username: "AE"
}
});

