本开发者指南将介绍如何使用 Android 版 Google Analytics(分析)SDK v3 来衡量应用中的事件。
概览
事件是一种实用的工具,可帮助您衡量用户与您的应用中的互动式组件的互动情况,例如按钮点击或游戏中某个道具的使用情况。
每个事件由 4 个字段组成,您可以使用这些字段来描述用户与您的应用内容的互动:
字段名称 | 跟踪器字段 | 类型 | 必需 | 说明 |
---|---|---|---|---|
类别 | Fields.EVENT_CATEGORY
|
String
|
是 | 事件类别 |
操作 | Fields.EVENT_ACTION
|
String
|
是 | 事件操作 |
唱片公司 | Fields.EVENT_LABEL
|
String
|
否 | 事件标签 |
值 | Fields.EVENT_VALUE
|
Long
|
否 | 事件值 |
实现
要向 Google Analytics(分析)发送事件,请使用 MapBuilder.createEvent()
并发送命中,如下例所示:
@Override public void onClick(View v) { // May return null if a EasyTracker has not yet been initialized with a // property ID. EasyTracker easyTracker = EasyTracker.getInstance(this); // MapBuilder.createEvent().build() returns a Map of event fields and values // that are set and sent with the hit. easyTracker.send(MapBuilder .createEvent("ui_action", // Event category (required) "button_press", // Event action (required) "play_button", // Event label null) // Event value .build() ); }