> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flashcat.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Collection

> Learn which page, action, request, error, and performance data the WeChat Mini Program RUM SDK collects automatically

After initialization, the WeChat Mini Program RUM SDK automatically collects user experience data through Mini Program runtime APIs. You can disable specific collection types through initialization parameters and use manual APIs to add business events.

## Collection Overview

| Data type           | Default state | Collection source                                                                                               | Event type |
| ------------------- | ------------- | --------------------------------------------------------------------------------------------------------------- | ---------- |
| Page views          | Enabled       | `Page` lifecycle hooks: `onLoad`, `onShow`, `onReady`, `onHide`, `onUnload`                                     | `view`     |
| User actions        | Enabled       | Page methods that receive an event object with a `type` field                                                   | `action`   |
| Network requests    | Enabled       | `wx.request`, `wx.uploadFile`, `wx.downloadFile`                                                                | `resource` |
| App errors          | Enabled       | `wx.onError`, `wx.onUnhandledRejection`, `wx.onPageNotFound`, `wx.onLazyLoadError`, and failed network requests | `error`    |
| Performance metrics | Enabled       | `wx.getPerformance` and page `setUpdatePerformanceListener`                                                     | `view`     |
| Custom events       | Manual        | `addCustomEvent()`                                                                                              | `custom`   |

## Common Event Attributes

Before sending each RUM event, the SDK enriches it with application, session, page, connectivity, user, and context information. These fields let the Explorer correlate events from the same user session, page view, and network state.

| Field                         | Description                                                                                  |
| ----------------------------- | -------------------------------------------------------------------------------------------- |
| `application.id`              | RUM application ID from the `applicationId` initialization parameter                         |
| `session.id`                  | Session ID generated by the SDK                                                              |
| `session.type`                | Always `user`                                                                                |
| `session.has_replay`          | Always `false`                                                                               |
| `session.sampled_for_replay`  | Always `false`                                                                               |
| `source`                      | Always `miniprogram`                                                                         |
| `view.id`                     | Page view ID associated with the current event                                               |
| `view.name` / `view.url`      | Page name associated with the current event, defaulting to the Mini Program page route       |
| `connectivity.status`         | Network connection status, either `connected` or `not_connected`                             |
| `connectivity.interfaces`     | Network interface, such as `wifi`, `cellular`, `none`, or `unknown`                          |
| `connectivity.effective_type` | Cellular network type, such as `2g`, `3g`, or `4g`                                           |
| `usr`                         | User information set through `setUser()`, or anonymous user information generated by the SDK |
| `context`                     | Global context set through `setGlobalContext()`                                              |

The SDK reads the initial network type through `wx.getNetworkType` and updates network state for later events through `wx.onNetworkStatusChange`.

## Page Views

When `trackPages` is enabled, the SDK wraps the global `Page` constructor and listens to page lifecycle hooks. Each page creates view events, and the default page name comes from the page instance `route`.

The SDK records the following page information:

| Field                    | Description                                                  |
| ------------------------ | ------------------------------------------------------------ |
| `view.id`                | Unique page ID generated by the SDK                          |
| `view.name` / `view.url` | Page route name, or `unknown` when unavailable               |
| `view.referrer`          | Previous page name                                           |
| `view.loading_type`      | Page loading type, either `initial_load` or `route_change`   |
| `view.loading_time`      | Time from `onLoad` to `onReady`                              |
| `view.time_spent`        | Accumulated time while the page is active in the foreground  |
| `view.onload_to_onshow`  | Time from `onLoad` to the first `onShow`                     |
| `view.onshow_to_onready` | Time from the first `onShow` to `onReady`                    |
| `view.action.count`      | Number of actions associated with the current view           |
| `view.error.count`       | Number of errors associated with the current view            |
| `view.resource.count`    | Number of resource requests associated with the current view |

The SDK updates the active page duration every 3 seconds. When a page moves to the background, is hidden, or unloads, the SDK sends a view update with the `hidden` or `terminated` state.

## User Actions

When `trackActions` is enabled, the SDK wraps functions in the page configuration. If a function receives a first argument that contains a string `type` field, the SDK records a user action.

Action events include the following information:

| Field                   | Description                                                                                                 |
| ----------------------- | ----------------------------------------------------------------------------------------------------------- |
| `action.type`           | Mini Program event type, such as `tap`                                                                      |
| `action.target.name`    | Read from `event.currentTarget.dataset.name`, `dataset.content`, or `dataset.type`; falls back to `unknown` |
| `_dd.action.position`   | Records `x` and `y` when the event contains coordinates                                                     |
| `action.loading_time`   | Time until page activity becomes idle after the action                                                      |
| `action.error.count`    | Number of errors produced during the action                                                                 |
| `action.resource.count` | Number of resource requests produced during the action                                                      |

<Tip>
  Set `data-name` on clickable components to make action names easier to identify, for example `<button data-name="submit_order">Submit order</button>`.
</Tip>

## Network Requests

When `trackRequests` is enabled, the SDK wraps `wx.request`, `wx.uploadFile`, and `wx.downloadFile`. SDK intake requests and calls marked as internal requests are skipped to avoid recursive collection.

Network requests create resource events:

| Field                                    | Description                                                                                               |
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `resource.type`                          | `xhr`, `upload`, or `download`                                                                            |
| `resource.url`                           | Request URL                                                                                               |
| `resource.method`                        | Request method. `wx.request` defaults to `GET`, uploads are always `POST`, and downloads are always `GET` |
| `resource.status_code`                   | HTTP status code when the request succeeds                                                                |
| `resource.duration`                      | Request duration                                                                                          |
| `resource.error_message`                 | Error message when the request fails                                                                      |
| `resource.trace_id` / `resource.span_id` | Trace identifiers generated when distributed tracing is enabled and sampled                               |

## Error Collection

When `trackErrors` is enabled, the SDK subscribes to Mini Program app errors, unhandled Promise rejections, page-not-found events, and subpackage lazy-load failures. Failed network requests are also recorded as errors.

| Source                    | SDK source       | Description                                                                            |
| ------------------------- | ---------------- | -------------------------------------------------------------------------------------- |
| `wx.onError`              | `app`            | Mini Program runtime errors                                                            |
| `wx.onUnhandledRejection` | `promise`        | Unhandled Promise rejections                                                           |
| `wx.onPageNotFound`       | `page-not-found` | The target page does not exist                                                         |
| `wx.onLazyLoadError`      | `lazy-load`      | Subpackage lazy-load failures                                                          |
| Failed network requests   | `network`        | For a failed request, the SDK creates an error event in addition to the resource event |
| `addError()`              | `custom`         | Business errors that you report manually                                               |

Error events include the error message, optional stack, and source. When manually reporting an error, pass `error.stack` as the third argument to `addError()`.

## Performance Metrics

When `trackPerformance` is enabled, the SDK reads Mini Program performance APIs. If the runtime supports the corresponding APIs, the SDK writes metrics to view events.

| Metric                           | Description                                                                                                               |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `view.app_launch`                | Mini Program startup duration from the `navigation` entry named `appLaunch`                                               |
| `view.evaluate_script`           | Main package script execution duration from the `script` entry named `evaluateScript`                                     |
| `view.first_render`              | First render duration from the `render` entry named `firstRender`                                                         |
| `view.first_render_detail`       | First render breakdown, including view layer ready, initial data send, initial data receive, render start, and render end |
| `view.performance.fcp.timestamp` | First Contentful Paint timestamp                                                                                          |
| `view.performance.lcp.timestamp` | Largest Contentful Paint timestamp                                                                                        |
| `view.setdata.count`             | Number of `setData` updates in the current view                                                                           |
| `view.setdata.duration`          | Accumulated `setData` update duration in the current view                                                                 |

If the current Mini Program base library does not support `wx.getPerformance` or `setUpdatePerformanceListener`, the SDK skips the corresponding metrics without affecting other data collection.

## Custom Events

Calling `addCustomEvent(name, context?)` creates a custom event. Use it to record business events that cannot be inferred automatically from page lifecycle hooks, actions, or requests.

| Field           | Description                 |
| --------------- | --------------------------- |
| `event.name`    | Custom event name           |
| `event.context` | Custom event context object |

```javascript pages/order/detail.js theme={null}
import { flashcatRum } from "@flashcatcloud/miniprogram-rum";

flashcatRum.addCustomEvent("order_status_changed", {
  orderId: "order-123",
  status: "paid"
});
```

## Event Correlation

The SDK associates non-view events with the page and session active at the event time:

* Page events establish the current view and periodically update time spent
* Action, resource, and error events increment counters on the current view
* If the current session has expired when an event occurs, the SDK creates a new session
* Historical view updates and delayed events prefer event time when looking up the page, which prevents attribution to the wrong page

## Disable Automatic Collection

Disable collection types you do not need during initialization:

```javascript app.js theme={null}
import { flashcatRum } from "@flashcatcloud/miniprogram-rum";

flashcatRum.init({
  applicationId: "<YOUR_APPLICATION_ID>",
  clientToken: "<YOUR_CLIENT_TOKEN>",
  trackActions: false,
  trackRequests: false,
  trackPerformance: false
});
```

Disabling an automatic collection type only affects its automatic listener. Manual APIs remain available. For example, after disabling `trackActions`, you can still call `addAction()` to report a custom action.

## Reporting Batches

The SDK adds collected RUM events to batches before sending them:

| Configuration              | Value                                                                |
| -------------------------- | -------------------------------------------------------------------- |
| Default flush interval     | `15000` milliseconds, configurable through `flushInterval`           |
| Maximum messages per batch | `50`                                                                 |
| Maximum batch size         | `64 KB`                                                              |
| Maximum message size       | `256 KB`                                                             |
| Background flush           | The SDK flushes the batch when the Mini Program triggers `onAppHide` |

Unsent payloads are persisted through Mini Program storage and resent the next time the batch reporting module starts. The SDK keeps up to `10` pending payloads with a total size up to `64 KB`, and discards payloads older than `24` hours.

## Related Pages

<CardGroup cols={3}>
  <Card title="SDK Integration" icon="plug" href="/en/rum/sdk/wechat-miniprogram/sdk-integration">
    Install and initialize the WeChat Mini Program RUM SDK.
  </Card>

  <Card title="Advanced Configuration" icon="sliders" href="/en/rum/sdk/wechat-miniprogram/advanced-config">
    Configure proxying, tracing, sessions, and manual instrumentation.
  </Card>

  <Card title="Compatibility" icon="shield-check" href="/en/rum/sdk/wechat-miniprogram/compatible">
    Learn about Mini Program base library, development tool, and platform API requirements.
  </Card>
</CardGroup>
