Skip to main content

Mini programs & mini games

Last updated 10/05/2026
tip

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

Note

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​

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

  • 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 use
    • appShow: Auto-tracks the mini program being launched or entering the foreground from the background
    • appHide: 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 path
    • pageShare: 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

Note

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

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"
}
});
Was this page helpful?