> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/growth/analytics/user-behavior.md).

# 用户行为记录

`分析`是用于记录和分析用户行为的对象。可以收集进入页面、点击按钮、组件曝光等事件，用于服务改进和用户流程分析。

{% hint style="info" %}
**请确认前置要求**

* SDK 版本 **`v1.0.3`** 必须不低于该版本。
* 在沙盒或 QR 测试环境中不会收集事件，仅在正式环境中收集。
* 服务上线 **次日（+1天）** 从控制台 **分析 > 事件** 可以在该界面查看数据。
  {% endhint %}

[日志（事件）指南](https://developers-apps-in-toss.toss.im/guide/analytics/logging)。

***

**签名**

```typescript
Analytics: {
    readonly init: typeof init;
    readonly Screen: typeof LoggingScreen;
    readonly Press: import("react").ForwardRefExoticComponent<import(".").LoggingPressProps & import("react").RefAttributes<unknown>>;
    readonly Impression: typeof LoggingImpression;
    readonly Area: typeof LoggingArea;
}
```

**属性**

* inittypeof init

  是用于在启动分析功能时应用设置的函数。应用初始化时必须调用一次。
* Presstypeof LoggingPress

  是用于记录按钮或可点击组件点击事件的组件。
* Impressiontypeof LoggingImpression

  是用于判断用户是否实际看到了屏幕上的特定组件，并记录日志的组件。
* Areatypeof LoggingArea

  是可将多个组件合并为一个区域进行分析的组件。

***

### 初始化分析功能

**`Analytics.init`**

`Analytics.init`是用于在启动分析功能时应用设置的函数。 `Analytics.Press`, `Analytics.Impression`, `Analytics.Area`在使用前必须调用。

**签名**

```typescript
declare function init(options: AnalyticsConfig): void;
```

**参数**

* **options** · 必需 · `AnalyticsConfig`

  是用于分析功能的配置对象。

***

### 记录点击事件

**`Analytics.Press`**

`Analytics.Press`是用于在用户按下元素时记录点击事件的组件。用于包裹按钮点击、购买操作等会发生用户交互的地方。

{% hint style="info" %}
**点击事件仅在正式环境中收集**

在沙盒或 QR 测试环境中，点击事件不会真正累积。在控制台中可以查看数据的时间点是 **上线次日（+1天）** 。
{% endhint %}

**签名**

```typescript
LoggingPress: import('react').ForwardRefExoticComponent<LoggingPressProps & import('react').RefAttributes<unknown>>;
```

**示例**

```tsx
import { Analytics } from '@apps-in-toss/framework';
import { Button } from 'react-native';

// 会自动收集可点击元素的点击事件。
function TrackElements() {
  return (
    <Analytics.Press>
      <Button label="Press Me" />
    </Analytics.Press>
  );
}
```

***

### 记录曝光事件

**`Analytics.Impression`**

`Analytics.Impression`是用于检测元素是否显示在视口中，并记录曝光事件的组件。用于跟踪位于滚动下方的商品、横幅、卡片等的曝光情况。

**签名**

```typescript
function LoggingImpression({
  enabled,
  impression: impressionType,
  ...props
}: LoggingImpressionProps): import('react/jsx-runtime').JSX.Element;
```

**示例**

```tsx
import { Analytics } from '@apps-in-toss/framework';

// 会自动收集区域内的曝光信息。
function TrackElements() {
  return (
    <Analytics.Impression>
      <Text>Hello</Text>
    </Analytics.Impression>
  );
}
```

***

### 按区域单位记录

**`Analytics.Area`**

`Analytics.Area`是将多个组件合并为一个区域，同时记录曝光和点击事件的组件。可以在指定区域曝光或被点击时汇总为一条日志。

**签名**

```typescript
function LoggingArea({
  children,
  params: _params,
  ...props
}: LoggingAreaProps): import('react/jsx-runtime').JSX.Element;
```

**示例**

```tsx
import { Analytics } from '@apps-in-toss/framework';
import { View, Text } from 'react-native';

// 会自动收集区域内的曝光或点击信息。
function TrackElements() {
  return (
    <Analytics.Area>
      <View>
        <Text>Hello</Text>
        <Text>World!</Text>
      </View>
    </Analytics.Area>
  );
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/growth/analytics/user-behavior.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
