Blue Triangle’s iOS SDK allows developers to send timing data from their native apps to the Blue Triangle portal to be included in RUM stats. The SDK can time API and database calls, scenes and views, and asynchronous functions, threds, app crashes, and errors. Developers can segment this data in two different ways by page name, traffic segment or both.
Implement the SDK in any project by including Cocoapods. The repository can be found in our Cocoapods Repo.
An example project can be found on GitHub BlueTriangleMarketing.
Step 1 – install Cocoapods if you have not already done so
In terminal execute
$ sudo gem install cocoapods
Step 2 - create an swift Project if you have not already
Open XCode and click create a new xcode project
Make an iOS app
Make a SwiftUI interface with Swift as the language
Step 3 - open the directory of your project in terminal and execute pod init to generate a pod file if you do not have one already
Step 4 – edit the pod file created in the directory with vim or another text editor
Add the Blue Triangle pod as a dependency
The version number can be located on the Cocoapods website: https://cocoapods.org/pods/BlueTriangleSDK-iOS
Step 5 – run pod install if this is a new project or pod update if this is an existing project
Step 6 – close xcode and open the new generated workspace
Step 7 – one the workspace is open check to make sure the BlueTriangleSDK-iOS pod files are there

Step 8 – add the foundation framework to the Frameworks-> iOS folder if it is showing up in red
Double click pods
Click the plus on Frameworks and Libraries section
Type foundation in the search box to locate Foundation.framework then click add to add the framework
You should see the foundation framework like this now
Drag it to the iOS folder
Delete the red framework
Step 9 – import the BlueTriangleSDK-iOS to your project
Open your app delegate swift file
Import the blue triangle SDK
import SwiftUI
import BlueTriangleSDK_iOS
Step 10 – add the Blue Triangle tracker to your app delegate
class AppDelegate: NSObject, UIApplicationDelegate, ObservableObject {
@Published var tracker = BTTracker();
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
tracker.setSiteID("YOUR_SITE_PREFIX");
return true
}
}
Change YOUR_SITE_PREFIX to your own site prefix
Step 11 – start the Blue Triangle app crash monitoring
Call the track crashes method of the BTTracker class
tracker.setSiteID("YOUR_SITE_PREFIX");
tracker.trackCrashes();
Step 12 – create a timer, set up a timer, start it and submit to the portal
//Create the timer with a page name and traffic segment
var timer = BTTimer();
timer.setPageName("YOUR_PAGE_NAME");
timer.setTrafficSegmentName("YOUR_TRAFFIC_SEGMENT");
//Set custom fields
//CV1 - CV5 Maps to Custom Variable 1 - 5 in the portal
//CV6 - CV10 Maps to Custom Category 1 – 5 in the portal
//CV11 - CV15 Maps to Variable 6-10 in the Portal
//CN1 - CN20 is Custom Numeric 1 - 20
timer.setField("CV1", stringValue: "this is a custom string");
//Start the timer
timer.start();
//Do work …..
//Submit the timer
@EnvironmentObject var appDelegate: AppDelegate
appDelegate.tracker.submitTimer(self.timer)
Comments
0 comments
Please sign in to leave a comment.