Attentive IOS SDK
Attentive IOS SDK 提供在 IOS 移动应用程序中渲染 Attentive 创意单元和收集 Attentive 事件的函数。
安装
attentive-ios-sdk 通过 CocoaPods 提供。要使用 Cocoapods 在独立项目中安装 SDK,请将 pod 包含在应用 Podfile 中
target 'MyApp' do
pod 'attentive-ios-sdk', 'THE_SDK_VERSION'
end
然后确保运行
pod install
使用此命令检查 SDK 的新版本
pod update attentive-ios-sdk
然后您可以在 podfile 中更新版本并再次运行 pod install
来拉取更改。
用法
查看 示例项目 以了解如何使用 Attentive IOS SDK。
*** 注意:请避免使用任何内部或未记录的类或方法,因为它们可能在版本之间发生变化。 ***
初始化 SDK
下面的代码示例假设您正在使用 Objective C 编程。要使 SDK 可用,需要在安装 SDK 后导入头文件。
#import "attentive_ios_sdk/attentive-ios-sdk-umbrella.h"
// Initialize the SDK with your attentive domain, in production mode
ATTNSDK *sdk = [[ATTNSDK alloc] initWithDomain:@"myCompanyDomain"];
// Alternatively, initialize the SDK in debug mode for more information about your creative and filtering rules
ATTNSDK *sdk = [[ATTNSDK alloc] initWithDomain:@"myCompanyDomain" mode:@"debug"];
// Initialize the AttentiveEventTracker. The AttentiveEventTracker is used to send user events (e.g. a Purchase) to Attentive. It must be set up before it can be used to send events.
[ATTNEventTracker setupWithSDk:sdk];
识别当前用户信息
使用 Attentive SDK 注册您拥有的任何关于用户的识别信息。此方法可在您有新信息可以与用户关联时随时调用。
[sdk identify:@{ IDENTIFIER_TYPE_CLIENT_USER_ID: @"myAppUserId", IDENTIFIER_TYPE_PHONE: @"+15556667777"}];
传给 identify
方法的标识符越多,SDK 就越有用。以下是可能标识符的列表
标识符名称 | 类型 | 描述 |
---|---|---|
客户端用户 ID | NSString* | 您的唯一用户标识符。这应该在整个用户生命周期中保持一致。例如,数据库 ID。 |
电话 | NSString* | 用户 E.164 格式的电话号码 |
电子邮件 | NSString* | 用户的电子邮件 |
Shopify ID | NSString* | 用户的 Shopify ID |
Klaviyo ID | NSString* | 用户的 Klaviyo ID |
自定义标识符 | NSDictionary |
自定义标识符名称和值的键值对。值应对于此用户唯一。 |
对于每种标识符类型,在用户标识符映射中使用 IDENTIFIER_TYPE_{IDENTIFIER_NAME}
作为键名的名称。
加载和渲染创意
// Load the creative with a completion handler.
[sdk trigger:self.view
handler:^(NSString *triggerStatus) {
if (triggerStatus == CREATIVE_TRIGGER_STATUS_OPENED) {
NSLog(@"Opened the Creative!");
} else if (triggerStatus == CREATIVE_TRIGGER_STATUS_NOT_OPENED) {
NSLog(@"Couldn't open the Creative!");
} else if (triggerStatus == CREATIVE_TRIGGER_STATUS_CLOSED) {
NSLog(@"Closed the Creative!");
} else if (triggerStatus == CREATIVE_TRIGGER_STATUS_NOT_CLOSED) {
NSLog(@"Couldn't close the Creative!");
}
}];
请参考 ATTNSDK.m 了解所有不同的触发状态。
// Alternatively, you can load the creative without a completion handler
[sdk trigger:self.view];
记录用户事件
当前 SDK 支持以下事件:ATTNPurchaseEvent
,ATTNAddToCartEvent
,ATTNProductViewEvent
和 ATTNCustomEvent
。
// Create the Item(s) that was/were purchased
ATTNItem* item = [[ATTNItem alloc] initWithProductId:@"222" productVariantId:@"55555" price:[[ATTNPrice alloc] initWithPrice:[[NSDecimalNumber alloc] initWithString:@"15.99"] currency:@"USD"]];
// Create the Order
ATTNOrder* order = [[ATTNOrder alloc] initWithOrderId:@"778899"];
// Create PurchaseEvent
ATTNPurchaseEvent* purchase = [[ATTNPurchaseEvent alloc] initWithItems:@[item] order:order];
// Finally, record the event!
[[ATTNEventTracker sharedInstance] recordEvent:purchase];
清除当前用户
如果用户登出,则应删除当前用户标识符
[sdk clearUser];
当/如果用户重新登录时,应再次调用 identify
并传入用户的标识符