> 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).

# 用户行为记录

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

{% 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.
