如何设置事件
事件 (Events) 用于跟踪用户在应用中执行的各种操作。事件数据会按历史记录存储,从而创建用户行为的时间线。有关事件的所有上下文信息都可以作为一组属性及其值来传递。
正确收集后,这些数据可用于:
- 触发基于行为的消息;
- 在 Customer Journey 中根据用户行为修改用户沟通流程;
- 构建在应用中执行特定操作的用户细分;
- 获取有关用户流程、使用指标和其他统计数据的洞察。
事件类型
Anchor link toPushwoosh 中有两种类型的事件:
- 默认事件
- 自定义事件
默认事件
Anchor link to默认事件是用户在应用或网站中执行的基本交互,无论其行业或功能如何。这些关键用户行为构成了客户沟通的核心,可用于任何产品和处于客户生命周期任何阶段的客户。 默认事件在最新的 SDK 版本中开箱即用,除了 PW_InAppPurchase 外,无需任何额外设置。
了解更多关于默认事件的信息。
自定义事件
Anchor link to与默认事件(在许多应用和行业中是通用的)不同,自定义事件是您专门为您的应用创建的事件。这些事件跟踪您需求的特定操作,例如完成一次锻炼或延长订阅,并帮助您了解用户如何与您的特定功能进行交互。
自定义事件需要您在自己的端实现。
自定义事件实现
Anchor link to1. 创建事件并设置属性
Anchor link toPushwoosh 会在第一次 postEvent 调用时,如果事件名称无法识别,则会自动创建该事件及其属性,并根据接收到的值推断每个属性的类型。如果您需要控制这些类型而不是让系统推断,请先声明事件及其属性类型。
您可以让您的营销团队直接在 Pushwoosh 控制面板中创建事件,或使用 createEvent API 方法。这包括指定事件名称和您想要跟踪的任何相关数据。
2. 调用 /postEvent API
Anchor link to当您想要跟踪的事件在您的应用中发生时,调用 /postEvent API 将此事件发送到 Pushwoosh。
调用 postEvent 将事件发送到 Pushwoosh:
PWInAppManager.shared().postEvent("eventName", withAttributes: nil)[[PushNotificationManager pushManager] postEvent:@“eventName” withAttributes:@{}];要添加有关事件的详细信息(参考属性),请按如下方式使用 attributes 参数:
let attributes: [String : Any] = ["AttributedString" : "someString", "AttributeInt" : 42, "AttributeList" : [123, 456, "someString"], "AttributeBool" : true, "AttributeDate" : NSDate()]
PWInAppManager.shared().postEvent("eventName", withAttributes: attributes)NSDictionary *attributes = @{ @"AttributeString" : @"someString", @"AttributeInt" : @(42), @"AttributeList" : @[ @(123), @(456), @"someString" ], @"AttributeBool" : @YES, @"AttributeDate" : [NSDate date]};
[[PushNotificationManager pushManager] postEvent:@“eventName” withAttributes:attributes];Android
Anchor link to当事件在您的 Android 应用中发生时,请使用以下说明将此事件发送到 Pushwoosh。
调用 postEvent 将事件发送到 Pushwoosh:
PushwooshInApp.getInstance().postEvent("eventName");要添加有关事件的详细信息(参考属性),请按如下方式使用 attributes 参数:
TagsBundle attributes = new TagsBundle.Builder() .putInt("AttributeInt", 17) .putString("AttributeString", "str") .putDate("AttributeDate", new Date()) .putBoolean("AttributeBool", true) .putList("AttributeList", Arrays.asList("item1", "item2", "item3")) .build();
PushwooshInApp.getInstance().postEvent("eventName", attributes);