Auto-tracking
Since v1.2.0, we provide auto-tracking. Enable the events you want to auto-track in the config you use to create the instance, and the SDK automatically collects certain mini program behaviors. The following events currently support auto-tracking:
The auto-collected data currently supported includes:
- Mini program initialization, triggered only once per use
- Mini program launch, including launching and returning from the background to the foreground
- The mini program goes to the background, and the duration of this visit (from launch to going to the background) is recorded
- A mini program page is displayed or switched to the foreground, and the page path and referrer path are recorded automatically
- The mini program is shared (forwarded), and the page at the time of sharing is recorded automatically
- A mini program page is unloaded, and the event is triggered automatically when the page is unloaded (supported in v3.2.0 and later)
- A mini program page is added to favorites, and the event is triggered automatically when the page is added to favorites (supported in v3.2.0 and later)
- A mini program page element is clicked, and the event is triggered automatically when a page element is clicked (supported in v3.2.0 and later)
The following sections describe how each type of data is collected
1. Enable auto-tracked events
In config, each element of the autoTrack parameter is the switch for one auto-tracked event. Set it to true to enable auto-tracking:
var config = {
appid: "YOU-APP-ID",
server_url: "https://youserverurl.com",
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
pageLeave: true,// Auto-track ta_page_leave
mpFavorite: true,// Auto-track ta_add_favorite
mpClick: true,// Auto-track ta_mp_click
properties: { // Custom properties for auto-tracked events
staticKey: 'staticValue'
},
callback: (eventType:any) => { // Auto-tracking callback
if (eventType === 'appShow') {
return { appShowKey: 'appShowValue' };
} else if (eventType === 'appHide') {
return { appHideKey: 'appHideValue' };
} else {
return {};
}
}
}
};
appLaunch: Auto-tracks mini program initializationappShow: 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 backgroundpageShow: Auto-tracks a mini program page being displayed or switched to the foregroundpageShare: Auto-tracks mini program sharing (forwarding)pageLeave: Auto-tracks mini program page unloadingmpFavorite: Auto-tracks pages being added to favoritesmpClick: Auto-tracks page element clicksproperties: Custom properties for auto-tracked events (supports appShow/appHide)callback: Auto-tracking callback (supports appShow/appHide)
Because of differences in runtime environments and structure, different platforms support different auto-tracked events, as listed below:
| Platform | appLaunch | appShow | appHide | pageShow | pageShare | pageLeave | mpFavorite | mpClick |
|---|---|---|---|---|---|---|---|---|
| Mini program | √ | √ | √ | √ | √ | √ | √ | √ |
| Mini game | √ | √ | √ |
2. Auto-tracked events in detail
2.1 Mini program initialization
Mini program initialization is triggered when the mini program is opened for the first time, or when the user kills the process and opens it again. It is triggered only once during the lifecycle of the process. Event details:
-
Event name: ta_mp_launch
-
Auto-tracked properties:
#scene: the scene value, taken from the scene values provided by WeChat#start_reason: the launch source of the app. The content is a JSON string, which is the parameter obtained from thegetLaunchOptionsSyncAPI
With the mini program initialization event, you can calculate the number of uses per day and the average number of uses per user, and group by scene value to view how users from different scene values use the mini program.
2.2 Mini program launch
Mini program launch is triggered when the mini program is launched or brought back from the background to the foreground. Event details:
-
Event name: ta_mp_show
-
Auto-tracked properties:
#scene: the scene value, taken from the scene values provided by WeChat#url_path: the page path, that is, the path of the page displayed when the mini program is launched#start_reason: the launch source of the app. The content is a JSON string, which is the parameter obtained from thegetLaunchOptionsSyncAPI
Because mini program launch is affected by switching between the foreground and background (which produces many records), it is not well suited for direct analysis. However, it can mark one use by the user in a behavior path and serve as the initial behavior of the user's behavior path
2.3 Mini program hide
Mini program hide is triggered when the mini program goes to the background, and it records the duration of this use. Event details:
-
Event name: ta_mp_hide
-
Auto-tracked properties:
#scene: the scene value, taken from the scene values provided by WeChat#duration: numeric, the duration from this launch (ta_mp_show) to the hide
The mini program hide event records the usage duration (in seconds), so you can directly calculate users' total usage duration and the average duration per user, or divide it by the number of initializations to calculate the duration of a single use.
2.4 Mini program page view
Mini program page view is triggered when a mini program page is opened, or when a page is displayed as the mini program returns from the background to the foreground. It records the page path and the referrer path. Event details:
-
Event name: ta_mp_view
-
Auto-tracked properties:
#scene: the scene value, taken from the scene values provided by WeChat#url_path: the page path, that is, the path of the displayed page#referrer: the referrer path, that is, the path of the page shown before the displayed page (the path before navigation). If the page is the home page displayed when the mini program is launched, the value is "直接打开"
With the mini program page view event, you can calculate the PV and UV of each page and the paths users take through the mini program.
2.5 Mini program page sharing
Mini program page sharing is triggered when a share button is clicked (including the share button in the navigation bar in the upper-right corner and share buttons on the page). Event details:
-
Event name: ta_mp_share
-
Auto-tracked properties:
#scene: the scene value, taken from the scene values provided by WeChat#url_path: the page path, that is, the path of the page from which it is shared
The mini program page sharing event is suitable for analyzing page share rates and can help you optimize page sharing.
2.6 Mini program page unload
Triggered when a mini program page is unloaded (for example, when the user goes to another page). Event details:
-
Event name: ta_page_leave
-
Auto-tracked properties:
#duration: the time spent on the page#url_path: the page path, that is, the path of the page when it is unloaded
2.7 Mini program page favorite
Triggered when a mini program page is added to favorites. Event details:
- Event name: ta_add_favorite
- Auto-tracked properties:
#url_path: the page path, that is, the path of the page when it is unloaded
2.8 Mini program page element click
Triggered when an element on a mini program page is clicked. Event details:
-
Event name: ta_mp_click
-
Auto-tracked properties:
#element_id: element ID#element_type: element type#element_content: element content#element_name: element name

