Skip to main content

Auto-tracking

Last updated 08/27/2026

Enable the events you want to auto-track in the config you use to create the instance, and the SDK automatically collects certain mini game behaviors. The following events currently support auto-tracking:

The auto-collected data currently supported includes:

  1. The event when the mini game returns to the foreground
  2. The mini game goes to the background, and the duration of this visit (from launch to going to the background) is recorded

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: "YOUR_APPID",
server_url: "YOUR_SERVER_URL",
autoTrack: {
appLaunch: true, // Auto-track ta_mg_launch
appShow: true, // Auto-track ta_mg_show
appHide: true, // Auto-track ta_mg_hide
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 initialization
  • appShow: Auto-tracks the mini game being launched or entering the foreground from the background
  • appHide: Auto-tracks the mini game going from the foreground to the background
  • properties: Custom properties for auto-tracked events (supports appShow/appHide)
  • callback: Auto-tracking callback (supports appShow/appHide)

2. Auto-tracked events in detail​

2.1 Mini game launch​

Mini game launch is triggered when the mini game is launched or brought back from the background to the foreground. Event details:

  • Event name: ta_mg_show
  • Auto-tracked properties:
  • #scene: the scene value, taken from the scene values provided by WeChat

Because mini game 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.2 Mini game hide​

Mini game hide is triggered when the mini game goes to the background, and it records the duration of this use. Event details:

  • Event name: ta_mg_hide

  • Auto-tracked properties:

    • #scene: the scene value, taken from the scene values provided by WeChat
    • #duration: numeric, the duration from this launch (ta_mg_show) to the hide

The mini game 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.

Was this page helpful?