Extole iOS SDK
此集成指南显示了如何使用我们的 iOS SDK 以最快的方式设置和启动 Extole 项目。
要求
Extole iOS SDK 支持iOS 13.0和更高版本。
步骤 1:添加 Cocoapods 依赖项
将 ExtoleMobileSDK
依赖项添加到您的 Podfile 中
pod 'ExtoleMobileSDK', '>= 0.0.29'
第 2 步:初始化 SDK
AppDelegate
类中,初始化 Extole
在您的 class AppDelegate: UIResponder, UIApplicationDelegate, ObservableObject {
...
@Published var extole: Extole = ExtoleImpl(programDomain: "<your-program-domain>")
...
}
有关示例,请参阅我们的 Github 文档。您需要提供您的 Extole 节目域名。有关更多详细配置选项,请参阅高级使用部分。
main
方法中,将 Extole 传递到您的视图中
在您的 @main
struct ExtoleApp: App {
...
@UIApplicationDelegateAdaptor var delegate: AppDelegate
...
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(delegate.extole)
}
}
....
}
有关示例,请参阅我们的 Github 文档。
View
初始化 Extole 提供的 struct ContentView: View {
...
@EnvironmentObject var extole: Extole
...
var body: some View {
NavigationView {
extole.getView()
}
}
...
}
默认情况下,Extole 将使用这个单个视图与客户交互。
发送Extole关于客户的客户信息
extole.identify("email", ["partner_user_id": "123"],
{(eventId: Id<Event>?, error: Error?) in
})
您可以选择传递任何类型的数据来描述客户。关于您客户的更丰富的数据,可以为您的营销团队提供信息,以便他们更好地细分您的程序参与者并以适当的宣传活动为目标。
发送如登记、注册、转化、账户开通等Extole事件
extole.sendEvent("signup", ["petname": "rover"]))
对于每种事件类型,您可以发送附加数据。例如,在转化事件中,您可能想传入订单ID或订单值等。
使用从Extole获取的内容填充呼唤行动(CTA)。
mobile menu items等呼唤行动可以在My Extole宣传活动编辑器中完全自定义。每个CTA都有一个指定的区域。以下代码是检索通过获取区域内容的示例:
extole.fetchZone("cta_prefetch") { (zone: ExtoleMobileSDK.Zone?, campaign: ExtoleMobileSDK.Campaign?, error: Error?) in
let ctaImage = zone?.get("image") as! String? ?? ""
let ctaText = zone?.get("text) as! String? ?? ""
let ctaMessage = zone?.get("message") as! String? ?? ""
}
// usage example:
View {
Text(extoleProgram.cta.ctaMessage)
}
// send the CTA event when the view is displayed
View {
.... // your view
}.task {
extoleProgram.fetchExtoleProgram()
extole.sendEvent("cta")
}
}
// on CTA tap send the event to Extole
View {
.... // your view
}.onTapGesture {
extole.sendEvent("cta_tap")
}
有关实现示例,请参阅我们的Github文档。要获取cta区域,该区域应在My Extole中配置,并返回包含image、text和message的JSON内容的响应。
重要提醒:我们建议您从My Extole获取CTA内容,因为这样做可以确保您的菜单项或叠加消息将反映您为您的活动配置的副本和出价。
高级使用
以下主题涵盖了Extole iOS SDK的高级使用案例。如果您想探索这些选项中的任何一个,请联系我们的支持团队,邮箱地址为 [email protected]。
与深链接提供者集成
一旦与深链接提供者(如Branch)集成,完成深链接集成就很简单了。向Extole发送一个移动事件,并根据您的移动操作配置,我们的框架将执行相应的操作。
深链接示例
class AppDelegate: UIResponder, UIApplicationDelegate, ObservableObject {
@Published var deeplinkProperties: [String: String] = [:]
@Published var extole: Extole = ExtoleImpl(programDomain: "https://mobile-monitor.extole.io",
applicationName: "iOS App", labels: ["business"], listenToEvents: true)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Branch.getInstance().initSession(launchOptions: launchOptions) { [self] (params, _) in
params?.forEach({ (key: AnyHashable, value: Any) in
deeplinkProperties[key as! String] = String(describing: value)
})
extole.getLogger().debug("Deeplink data: \(deeplinkProperties)")
extole.sendEvent("deeplink", deeplinkProperties) { _, _ in
}
}
return true
}
}
从事件配置动作
您可以为事件触发时发生特定操作而设置。例如,当客户点击您的菜单项CTA时,您可能希望事件触发加载您的微型网站并显示共享体验的操作。要设置此类配置,您需要与Extole支持团队合作,在My Extole中设置一个区域,返回包含条件和动作的JSON配置。SDK为特定事件通过的条件执行操作。
{
"operations": [
{
"conditions": [
{
"type": "EVENT",
"event_names": [
"cta_tap"
]
}
],
"actions": [
{
"type": "VIEW_FULLSCREEN",
"zone_name": "microsite"
}
]
}
]
}
支持的动作
我们的SDK默认支持以下类型的操作。
操作名称 | 描述 |
提示
|
显示原生iOS弹出通知。例如,当成功应用折扣或优惠券码时,可能会出现这种情况。 |
本地分享
|
使用预定义的消息和链接打开本地分享表单,顾客可以通过短信或任何启用的社交应用程序发送。 |
全屏查看
|
触发全屏移动网页视图。例如,这可能是在My Extole中配置的微站,用于展示分享体验。 |
自定义动作
如果您想创建超出我们默认设置的自定义动作,请使用以下示例中展示的格式。如果您有任何问题,请联系我们的支持团队:[email protected]
自定义动作示例
import ExtoleMobileSDK
public class CustomAction: Action {
public static var type: ActionType = ActionType.CUSTOM
var customActionValue: String?
public override func execute(event: AppEvent, extole: ExtoleImpl) {
extole.getLogger().setLogLevel(level: LogLevel.disable)
}
init(customActionValue: String) {
super.init()
self.customActionValue = customActionValue
}
override init() {
super.init()
}
public override func getType() -> ActionType {
ActionType.CUSTOM
}
public required init?(map: Map) {
super.init()
}
public override func mapping(map: Map) {
customActionValue <- map["custom_action_value"]
}
public var description: String {
return "CustomAction[customActionValue:\(customActionValue)]"
}
}
注册自定义动作
Action.customActionTypes["CUSTOM_ACTION"] = CustomAction()
附录
高级操作
加载操作
{
"type": "LOAD_OPERATIONS",
"zones": [
"<zone_name>"
],
"data": {
"key": "value"
}
}
获取
{
"type": "FETCH",
"zones": [
"<zone_name_1>",
"<zone_name_2>"
]
}
设置日志级别
{
"type": "SET_LOG_LEVEL",
"log_level": "WARN"
}