blue-triangle

3.2.1

Blue Triangle Performance Monitoring SDK for iOS
blue-triangle-tech/btt-swift-sdk

What's New

3.2.1

2022-10-14T19:38:46Z

Bug Fixes

  • Fixed a bug which could cause the Network Capture data to not show on the Performance Details Session level scatterplot.

Blue Triangle SDK for iOS

Blue Triangle analytics SDK for iOS.

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 your AppDelegate.application(_:didFinishLaunchingWithOptions:) method:

BlueTriangle.configure { config in
    config.siteID = "MY_SITE_ID"
    config.isReturningVisitor = true
    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.crashTracking = .nsException
    config.performanceMonitorSampleRate = 1.0
}

Timers

To measure the duration of a user interaction, initialize a Page object describing that interaction and pass it to BlueTriangle.startTimer(page:timerType) to receive a running timer 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:timerType) 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)

Running timers are automatically stopped when passed to BlueTriangle.endTimer(_:purchaseConfirmation:), 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 to pass along with the timer to BlueTriangle.endTimer(_:purchaseConfirmation:):

timer.end()
let purchaseConfirmation = PurchaseConfirmation(cartValue: 99.00)
BlueTriangle.endTimer(timer, purchaseConfirmation: purchaseConfirmation)

Timer Types

BlueTriangle.makeTimer(page:timerType:) and BlueTriangle.startTimer(page:timerType:) have a timerType parameter to specify the type of the timer they return. By default, both methods return main timers with the type BTTimer.TimerType.main. When network capture is enabled, requests made with one of the bt-prefixed URLSession methods will be associated with the last main timer to have been started at the time the request completes. It is recommended to only have a single main timer running at any given time. If you need overlapping timers, create additional custom timers by specifying a BTTimer.TimerType.custom timer type:

let mainTimer = BlueTriangle.startTimer(page: Page(pageName: "MY_PAGE"))
let customTimer = BlueTriangle.startTimer(page: Page(pageName: "MY_OTHER_TIMER"), timerType: .custom)
// ...
BlueTriangle.endTimer(mainTimer)
// ...
BlueTriangle.endTimer(customTimer)

Network Capture

The Blue Triangle SDK offers bt-prefixed versions of common URLSession methods that can be used to gather information about network requests when network capture is enabled:

Standard Network Capture
URLSession.dataTask(with:completionHandler:) URLSession.btDataTask(with:completionHandler:)
URLSession.data(for:delegate:) URLSession.btData(for:delegate:)
URLSession.dataTaskPublisher(for:) URLSession.btDataTaskPublisher(for:)

To enable network capture, configure the SDK with a non-zero network sample rate:

BlueTriangle.configure { config in
    ...
    config.networkSampleRate = 0.05
}

A value of 0.05, for example, means that network capture will be randomly enabled for 5% of user sessions. Network requests made using one of the bt-prefixed URLSession methods will be associated with the last main timer to have been started.

let timer = BlueTriangle.startTimer(page: Page(pageName: "MY_PAGE"))
URLSession.shared.btDataTask(with: URL(string: "https://example.com")!) { data, response, error in
    // ...
}.resume()

Requests are not associated with a timer until the request ends.

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Dec 04 2022 16:31:29 GMT-0500 (GMT-05:00)