Overview
This article provides documentation for our Swift SDK for iOS. Here is an overview of the sections in this article:
Installation
Xcode 13: go to File > Add Packages…, enter the package repository URL https://github.com/blue-triangle-tech/btt-swift-sdk.git
, and click Add Package.
Xcode 11 - 12: go to File > Swift Packages > Add Package Dependency… and enter the package repository URL https://github.com/blue-triangle-tech/btt-swift-sdk.git
, then follow the instructions.
Usage
Configuration
Before sending timers you must first configure BlueTriangle
. It is recommended to do this in you AppDelegate.application(_:didFinishLaunchingWithOptions:)
method:
BlueTriangle.configure { config in
config.siteID = "MY_SITE_ID"
config.abTestID = "MY_AB_TEST_ID"
config.campaignMedium = "MY_CAMPAIGN_MEDIUM"
config.campaignName = "MY_CAMPAIGN_NAME"
config.campaignSource = "MY_CAMPAIGN_SOURCE"
config.dataCenter = "MY_DATA_CENTER"
config.trafficSegmentName = "MY_SEGMENT_NAME"
config.performanceMonitorSampleRate = 1.0
config.crashTracking = .nsException
}
Timers
Initialize a Page
object with your page properties and pass it to BlueTriangle.startTimer(page:)
to receive a running BTTimer
instance.
let page = Page(pageName: "MY_PAGE")
let timer = BlueTriangle.startTimer(page: page)
If you need to defer the start of the timer, pass your Page
instance to BlueTriangle.makeTimer(page: page)
and call the timer's start()
method when you are ready to start timing:
let page = Page(pageName: "MY_PAGE")
let timer = BlueTriangle.makeTimer(page: page)
...
timer.start()
In both cases, pass your timer to BlueTriangle.endTimer(_:purchaseConfirmation:)
to send it to the Blue Triangle server.
BlueTriangle.endTimer(timer)
This automatically stops the timer, though you can end timing earlier by calling the timer's end()
method.
timer.end()
...
// You must still pass the timer to `BlueTriangle.endTimer(_:)` to send it to the Blue Triangle server
BlueTriangle.endTimer(timer)
For timers that are associated with checkout, create a PurchaseConfirmation
object and pass that along with the timer to BlueTriangle.endTimer()
timer.end()
let purchaseConfirmation = PurchaseConfirmation(cartValue: 99.00)
BlueTriangle.endTimer(timer, purchaseConfirmation: purchaseConfirmation)
Comments
0 comments
Please sign in to leave a comment.