应用内事件

了解与应用内事件相关的基本概念和术语。

应用内事件提供关于用户如何与您的应用程序互动的深入分析。AppsFlyer SDK使您能够轻松地记录这些互动。

应用内事件SDK指南

事件剖析

应用内事件由2部分组成:

  • 事件名称:唯一事件标识符。这通常是营销人员在控制面板中查看事件的方式。
  • 事件值:由被称为事件参数的键值对组成的对象。事件参数提供有关发生事件的额外情景和信息。

事件名称和事件参数可以是预定义,也可以是自定义

👍

建议

Quickly define and generate in-app events code for all major platforms using our in-app event generator tool.

事件常量

在SDK中,预定义的事件和参数作为常量公开。

发送事件时,建议使用常量,不要使用原始字符串:

  • 它减少引入命名差异的机会。
  • 对基础事件/参数名称的更改对您来说是透明的,而且需要的维护更少。

Technically, predefined event names/parameters are strings prefixed with af_.

自定义事件和事件参数

自定义事件名称和参数是用户定义的,通常描述特定于您应用程序的业务逻辑以及您的用户与应用程序互动的场景。

🚧

注意事项

To avoid confusion with predefined events, don't prefix custom event names with af_.

Valid custom event names

自定义事件名称应遵循以下规则:

  • Be up to 100 characters long.
  • 支持非英文字符。

Valid custom event parameters

自定义事件参数:

  • 不得超过1000个字符;如果更长,可能会被截断
  • 定价和收入:仅使用数字和小数,例如,5或5.2
  • 阶段后的定价和收入值最多可以有5位数字,例如,5.12345

了解事件结构定义

Ideally, the marketer should provide you with clear event structure definitions, based on the instructions in Defining In-app events. For example, a definition of an af_content_view event for an eCommerce app would look something like this:

事件名称事件参数参数值地点/时间(可选)
af_content_viewaf_price
af_content_type
af_content_id
af_price: Item price
af_content_type: Item category.
af_content_id: Item SKU.
当用户导航到商品视图时。
  • The first column (Event name) is the value you pass as logEvent's second argument.

    af_content_view 是营销人员在控制面板中查看事件的方式。建议使用预定义的事件常量,不要使用营销人员提供的原始字符串值。

  • The second column (Event parameters) lists the event parameters associated with the event. In this case, you should pass the following event parameters to logEvent:

    • af_price
    • af_content_type
    • af_content_id
  • The third column (Parameter values) contains additional information about particular values assigned to event parameters. In the example above, the marketer clearly communicates that the af_content_id event parameter value should be the viewed item's SKU.

  • 第四列是营销人员描述事件在应用程序中发生的地点和时间

请看以上示例定义是如何在AndroidiOS上实现的。

离线应用内事件

SDK可以缓存在没有互联网连接时发生的应用内事件:

  • SDK向AppsFlyer服务器发送事件并等待响应
  • 如果SDK没有收到200响应,则缓存事件
  • 一旦收到下一个200响应,存储的事件就会被重新发送到服务器
  • 如果缓存中有多个事件,则会将它们一个接一个地发送到服务器(不分批,每个事件一个广告平台请求)。

SDK最多可以缓存40个事件。只有前40个离线事件被保存。之后的所有内容(直到下一次成功响应)都会被丢弃。