ATTNSDKFramework 1.0.0

ATTNSDKFramework 1.0.0

EPD 维护。



  • Ivan Loughman-Pawelko

Attentive IOS SDK

Attentive IOS SDK 提供在 IOS 移动应用程序中渲染 Attentive 创意单元和收集 Attentive 事件的函数。

安装

Cocoapods

attentive-ios-sdk 通过 CocoaPods 提供。要在单独的项目中使用 Cocoapods 安装 SDK,请将 pod 包含在您的应用程序的 Podfile 中

target 'MyApp' do
  pod 'ATTNSDKFramework', '~> 0.6'
end

然后请确保运行以下操作:

pod install

使用此命令检查 SDK 的新版本:

pod update ATTNSDKFramework

然后您可以在 pod 文件中更新版本,并再次运行 pod install 来拉取更改。

重要

attentive-ios-sdk 已弃用,以支持 ATTNSDKFramework。请使用 SDK 的最新名称更新您的 Podfile。

Swift 包管理器

我们同时支持通过 Swift 包管理器添加依赖项。

在您的应用程序的 Package.swift 文件中,添加 attentive-ios-sdk 作为依赖项

dependencies: [
    // your other app dependencies
    .package(url: "https://github.com/attentive-mobile/attentive-ios-sdk", from: "0.6.0"),
],

这将允许您的包使用 swift package update 更新补丁版本,但不会自动升级任何次要或主要版本。

然后,从命令行中,运行以下操作

swift package resolve

要更新您本地的包,请运行 swift package update

要检查此 SDK 的新版本的重大和次要版本,请转到项目的 版本 选项卡。然后您可以手动更新 Package.swift 文件中的版本,并运行 swift package resolve 以完成更新。

使用方法

有关 Attentive IOS SDK 如何使用的示例,请参阅 示例项目

重要

请勿使用任何内部或未记录的类或方法,因为它们可能会在版本之间更改。

初始化 SDK

以下代码段和示例假设您正在使用 Objective C。为了使 SDK 可用,您需要在安装 SDK 后导入头文件

Swift

import attentive_ios_sdk
// Initialize the SDK with your attentive domain, in production mode
let sdk = ATTNSDK(domain: "myCompanyDomain")

// Alternatively, initialize the SDK in debug mode for more information about your creative and filtering rules
let sdk = ATTNSDK(domain: "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.setup(with: sdk)

Objective-C

#import "attentive_ios_sdk/attentive-ios-sdk-umbrella.h"
ATTNSDK *sdk = [[ATTNSDK alloc] initWithDomain:@"myCompanyDomain"];

ATTNSDK *sdk = [[ATTNSDK alloc] initWithDomain:@"myCompanyDomain" mode:@"debug"];

[ATTNEventTracker setupWithSDk:sdk];

识别有关当前用户的信息

使用 Attentive SDK 注册有关用户的任何标识信息。当您有新信息可以归因于用户时,可以调用此方法。

Swift

sdk.identify([
  ATTNIdentifierType.clientUserId : "myAppUserId",
  ATTNIdentifierType.phone : "+15556667777"
])

Objective-C

[sdk identify:@{
  ATTNIdentifierType.clientUserId: @"myAppUserId",
  ATTNIdentifierType.phone: @"+15556667777"
}];

传递给 identify 的标识符越多,SDK 的功能就越好。以下是 ATTNIdentifierType 中可用的可能标识符的列表

标识符名称 常量名称 类型 描述
客户端用户 ID clientUserId String 用户唯一标识符。这应在用户的生命周期内保持一致。例如,数据库 ID。
电话 phone String 用户的 E.164 格式的电话号码
电子邮件 email String 用户的电子邮件
Shopify ID shopifyId String 用户 Shopify ID
Klaviyo ID klaviyoId String 用户 Klaviyo ID
自定义标识符 customIdentifiers [String: String] 自定义标识符名称和值的键值对。值应为该用户的唯一标识。

加载并渲染创意内容

Swift

sdk.trigger(view) { status in
  switch status {
  // Status passed to ATTNCreativeTriggerCompletionHandler when the creative is opened sucessfully
  case ATTNCreativeTriggerStatus.opened:
    print("Opened the Creative!")
  // Status passed to the ATTNCreativeTriggerCompletionHandler when the Creative has been triggered but it is not opened successfully. 
  // This can happen if there is no available mobile app creative, if the creative is fatigued, if the creative call has been timed out, or if an unknown exception occurs.
  case ATTNCreativeTriggerStatus.notOpened:
    print("Couldn't open the Creative!")
  // Status passed to ATTNCreativeTriggerCompletionHandler when the creative is closed sucessfully
  case ATTNCreativeTriggerStatus.closed:
    print("Closed the Creative!")
  // Status passed to the ATTNCreativeTriggerCompletionHandler when the Creative is not closed due to an unknown exception
  case ATTNCreativeTriggerStatus.notClosed:
    print("Couldn't close the Creative!")
  default:
    break
  }
}

Objective-C

// Load the creative with a completion handler.
[sdk trigger:self.view
     handler:^(NSString *triggerStatus) {
      if (triggerStatus == ATTNCreativeTriggerStatus.opened) {
        NSLog(@"Opened the Creative!");
      } else if (triggerStatus == ATTNCreativeTriggerStatus.notOpened) {
        NSLog(@"Couldn't open the Creative!");
      } else if (triggerStatus == ATTNCreativeTriggerStatus.closed) {
        NSLog(@"Closed the Creative!");
      } else if (triggerStatus == ATTNCreativeTriggerStatus.notClosed) {
        NSLog(@"Couldn't close the Creative!");
      }
    }];

Swift

// Alternatively, you can load the creative without a completion handler
sdk.trigger(view)

Objective-C

[sdk trigger:self.view];

记录用户事件

当前SDK支持以下事件:ATTNPurchaseEventATTNAddToCartEventATTNProductViewEventATTNCustomEvent

Swift

let price = ATTNPrice(price: NSDecimalNumber(string: "15.99"), currency: "USD")

// Create the Item(s) that was/were purchased
let item = ATTNItem(productId: "222", productVariantId: "55555", price: price)

// Create the Order
let order = ATTNOrder(orderId: "778899")

// Create PurchaseEvent
let purchase = ATTNPurchaseEvent(items: [item], order: order)

// Finally, record the event!
ATTNEventTracker.sharedInstance().record(event: purchase)

Objective-C

ATTNItem* item = [[ATTNItem alloc] initWithProductId:@"222" productVariantId:@"55555" price:[[ATTNPrice alloc] initWithPrice:[[NSDecimalNumber alloc] initWithString:@"15.99"] currency:@"USD"]];

ATTNOrder* order = [[ATTNOrder alloc] initWithOrderId:@"778899"];

ATTNPurchaseEvent* purchase = [[ATTNPurchaseEvent alloc] initWithItems:@[item] order:order];

[[ATTNEventTracker sharedInstance] recordEvent:purchase];

清除当前用户

如果用户登出,则应删除当前用户标识符

Swift

sdk.clearUser()

Objective-C

[sdk clearUser];

当/如果用户重新登录,应再次调用identify并与用户的标识符一起调用

变更日志

点击此处查看每个发布版本的完整变更日志