Skip to content

iOS SDK for RudderStack - the Customer Data Platform for Developers. Now supports tvOS, watchOS and macOS tracking!

License

Notifications You must be signed in to change notification settings

ananinja/rudder-sdk-ios

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Customer Data Platform for Developers

Website · Documentation · Community Slack


RudderStack iOS SDK

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.

What's new in v2

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

Installing the SDK

The iOS SDK is available through CocoaPods, Carthage, and Swift Package Manager (SPM).

CocoaPods

To install the SDK, simply add the following line to your Podfile:

pod 'Rudder', '2.5.1-beta'

Carthage

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:

Objective C

@import Rudder;

Swift

import Rudder

Swift Package Manager(SPM)

You can also add the RudderStack SDK using the Swift Package Mangaer in one of the following two ways:

Xcode

  1. Go to File > Add Package, as shown:

Adding a package

  1. Enter the package repository ([email protected]:rudderlabs/rudder-sdk-ios.git) in the search bar.
  2. In Dependency Rule, select Up to Next Major Version, and enter 2.5.1-beta as the value, as shown:

Setting the dependency

  1. Select the project to which you want to add the package.
  2. Finally, click Add Package.

Swift

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"]),
    ]
)

Initializing the RudderStack client

To the initialize RSClient, place the following code in your AppDelegate file under the method didFinishLaunchingWithOptions:

Objective C

RSConfig *config = [[RSConfig alloc] initWithWriteKey:WRITE_KEY];
[config dataPlaneURL:DATA_PLANE_URL];
[config recordScreenViews:YES];
[[RSClient sharedInstance] configureWith:config];

Swift

let config: RSConfig = RSConfig(writeKey: WRITE_KEY)
            .dataPlaneURL(DATA_PLANE_URL)
            .loglevel(.debug)
            .trackLifecycleEvents(true)
            .recordScreenViews(true)
RSClient.sharedInstance().configure(with: config)

Sending events

Identify

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:

Objective C

[[RSClient sharedInstance] identify:@"test_user_id" traits:@{
    @"foo": @"bar",
    @"foo1": @"bar1",
    @"email": @"[email protected]"
}];

Swift

RSClient.sharedInstance().identify("test_user_id", traits:[
    "foo": "bar",
    "foo1": "bar1",
    "email": "[email protected]"
])

Track

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:

Objective C

[[RSClient sharedInstance] track:@"sample_track_call"];
[[RSClient sharedInstance] track:@"sample_track_call" properties:@{
    @"key_1" : @"value_1",
    @"key_2" : @"value_2"
}];

Swift

RSClient.sharedInstance().track("sample_track_call")
RSClient.sharedInstance().track("sample_track_call", properties:[
    "key_1" : "value_1",
    "key_2" : "value_2"
])

Screen

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:

Objective C

[[RSClient sharedInstance] screen:@"Main" properties:@{@"prop_key" : @"prop_value"}];

Swift

RSClient.sharedInstance().screen("Main", properties:["prop_key" : "prop_value"]);

Group

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:

Objective C

[[RSClient sharedInstance] group:@"sample_group_id" traits:@{
    @"foo": @"bar", 
    @"foo1": @"bar1", 
    @"email": @"[email protected]"
}];

Swift

RSClient.sharedInstance().group("sample_group_id" traits:[
    "foo": "bar", 
    "foo1": "bar1", 
    "email": "[email protected]"
])

Alias

The alias call associates the user with a new identification.

A sample alias call is shown in the following sections:

Objective C

[[RSClient sharedInstance] alias:@"new_user_id"];

Swift

RSClient.sharedInstance().alias("new_user_id")

Reset

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:

Objective C

[[RSClient sharedInstance] reset];

Swift

RSClient.sharedInstance().reset()

Supported device mode destinations

Integration Package
Adjust https://github.com/rudderlabs/rudder-integration-adjust-swift
AppCenter https://github.com/rudderlabs/rudder-integration-appcenter-swift
AppsFlyer https://github.com/rudderlabs/rudder-integration-appsflyer-swift
Branch https://github.com/rudderlabs/rudder-integration-branch-swift
Bugsnag https://github.com/rudderlabs/rudder-integration-bugsnag-swift
Facebook App Events https://github.com/rudderlabs/rudder-integration-facebook-app-events-swift
Firebase https://github.com/rudderlabs/rudder-integration-firebase-swift
Kochava https://github.com/rudderlabs/rudder-integration-kochava-swift
MoEngage https://github.com/rudderlabs/rudder-integration-moengage-swift
Singular https://github.com/rudderlabs/rudder-integration-singular-swift

Contribute

We would love to see you contribute to this project. Get more information on how to contribute here.

About RudderStack

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.

Contact us

For more information on using the RudderStack iOS SDK, you can contact us or start a conversation on our Slack channel.

About

iOS SDK for RudderStack - the Customer Data Platform for Developers. Now supports tvOS, watchOS and macOS tracking!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 98.5%
  • Other 1.5%