The Customer Data Platform for Developers
Website · Documentation · Community Slack
The RudderStack iOS SDK lets you track event data from your iOS, tvOS, watchOS and macOS applications. After integrating the SDK, you will also be able to send these events to your to your specified destinations via RudderStack.
For more information on the RudderStack iOS SDK, refer to the SDK documentation. |
---|
The latest version of the iOS SDK (v2) includes the following features:
- Support tracking events in the macOS applications
- You can now track push notifications
The iOS SDK is available through CocoaPods, Carthage, and Swift Package Manager (SPM).
To install the SDK, simply add the following line to your Podfile:
pod 'Rudder', '2.5.1-beta'
For Carthage support, add the following line to your Cartfile
:
github "rudderlabs/rudder-sdk-ios" "v2.5.1-beta"
Remember to include the following code where you want to refer to or use the RudderStack SDK classes, as shown:
@import Rudder;
import Rudder
You can also add the RudderStack SDK using the Swift Package Mangaer in one of the following two ways:
- Go to File > Add Package, as shown:
- Enter the package repository (
[email protected]:rudderlabs/rudder-sdk-ios.git
) in the search bar. - In Dependency Rule, select Up to Next Major Version, and enter
2.5.1-beta
as the value, as shown:
- Select the project to which you want to add the package.
- Finally, click Add Package.
To leverage package.swift
, use the following snippet in your project:
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "RudderStack",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "RudderStack",
targets: ["RudderStack"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "[email protected]:rudderlabs/rudder-sdk-ios.git", from: "2.5.1-beta")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "RudderStack",
dependencies: [
.product(name: "Rudder", package: "rudder-sdk-ios")
]),
.testTarget(
name: "RudderStackTests",
dependencies: ["RudderStack"]),
]
)
To the initialize RSClient
, place the following code in your AppDelegate
file under the method didFinishLaunchingWithOptions
:
RSConfig *config = [[RSConfig alloc] initWithWriteKey:WRITE_KEY];
[config dataPlaneURL:DATA_PLANE_URL];
[config recordScreenViews:YES];
[[RSClient sharedInstance] configureWith:config];
let config: RSConfig = RSConfig(writeKey: WRITE_KEY)
.dataPlaneURL(DATA_PLANE_URL)
.loglevel(.debug)
.trackLifecycleEvents(true)
.recordScreenViews(true)
RSClient.sharedInstance().configure(with: config)
The identify
call lets you identify a visiting user and associate them to their actions. It also lets you record the traits about them like their name, email address, etc.
A sample identify
call is shown in the following sections:
[[RSClient sharedInstance] identify:@"test_user_id" traits:@{
@"foo": @"bar",
@"foo1": @"bar1",
@"email": @"[email protected]"
}];
RSClient.sharedInstance().identify("test_user_id", traits:[
"foo": "bar",
"foo1": "bar1",
"email": "[email protected]"
])
The track
call lets you record the user events along with any properties associated with them.
A sample track
call is shown in the following sections:
[[RSClient sharedInstance] track:@"sample_track_call"];
[[RSClient sharedInstance] track:@"sample_track_call" properties:@{
@"key_1" : @"value_1",
@"key_2" : @"value_2"
}];
RSClient.sharedInstance().track("sample_track_call")
RSClient.sharedInstance().track("sample_track_call", properties:[
"key_1" : "value_1",
"key_2" : "value_2"
])
The screen
call lets you record whenever a user views their mobile screen, with any additional relevant information about the screen.
A sample screen
call is shown in the following sections:
[[RSClient sharedInstance] screen:@"Main" properties:@{@"prop_key" : @"prop_value"}];
RSClient.sharedInstance().screen("Main", properties:["prop_key" : "prop_value"]);
The group
call lets you link an identified user with a group like a company, organization, or an account. It also lets you record any traits associated with that group, like the name of the company, number of employees, etc.
A sample group
call is shown in the following sections:
[[RSClient sharedInstance] group:@"sample_group_id" traits:@{
@"foo": @"bar",
@"foo1": @"bar1",
@"email": @"[email protected]"
}];
RSClient.sharedInstance().group("sample_group_id" traits:[
"foo": "bar",
"foo1": "bar1",
"email": "[email protected]"
])
The alias
call associates the user with a new identification.
A sample alias
call is shown in the following sections:
[[RSClient sharedInstance] alias:@"new_user_id"];
RSClient.sharedInstance().alias("new_user_id")
The reset
call resets the user identification and clears any persisted user traits set in the identify
call.
A sample reset
call is shown in the following sections:
[[RSClient sharedInstance] reset];
RSClient.sharedInstance().reset()
We would love to see you contribute to this project. Get more information on how to contribute here.
RudderStack is a customer data platform for developers. Our tooling makes it easy to deploy pipelines that collect customer data from every app, website and SaaS platform, then activate it in your warehouse and business tools.
More information on RudderStack can be found here.
For more information on using the RudderStack iOS SDK, you can contact us or start a conversation on our Slack channel.