Swiftpack.co - rudderlabs/rudder-sdk-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by rudderlabs.
rudderlabs/rudder-sdk-swift v1.0.0-beta.6
Repo for RudderStack's iOS/tvOS SDK. RudderStack is an open-source, warehouse-first Customer Data Pipeline and Segment-alternative. It collects and routes clickstream data and builds your customer data lake on your data warehouse.
⭐️ 0
🕓 6 days ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/rudderlabs/rudder-sdk-swift.git", from: "v1.0.0-beta.6")

The Customer Data Platform for Developers

Website · Documentation · Community Slack


RudderStack iOS SDK

RudderStack's 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 preferred destinations such as Google Analytics, Amplitude, and more.

For detailed documentation on the iOS SDK, click here.

Installing the iOS 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 'RudderStack', '1.0.0-beta.6'

Carthage

For Carthage support, add the following line to your Cartfile:

github "rudderlabs/rudder-sdk-swift" "v1.0.0-beta.6"

Remember to include the following code where you want to refer to or use the RudderStack SDK classes, as shown:

Objective C
@import RudderStack;
Swift
import RudderStack

Swift Package Manager (SPM)

You can also add the RudderStack iOS SDK via Swift Package Mangaer, via one of the following two ways:

Xcode

  • Go to File - Add Package, as shown:

Adding a package

  • Enter the package repository (git@github.com:rudderlabs/rudder-sdk-swift.git) in the search bar.

  • In Dependency Rule, select Up to Next Major Version and enter 1.0.0-beta.6 as the value, as shown:

Setting dependency

  • Select the project to which you want to add the package.

  • Finally, click on 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: "git@github.com:rudderlabs/rudder-sdk-swift.git", from: "1.0.0-beta.6")
    ],
    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: "RudderStack", package: "rudder-sdk-swift")
            ]),
        .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 *client = [[RSClient alloc] initWithConfig:config];

Swift

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

Sending Events

Track

Objective C
[client track:@"sample_track_call" properties:NULL option:NULL];
[client track:@"sample_track_call" properties:@{
    @"key_1" : @"value_1",
    @"key_2" : @"value_2"
} option:NULL];

Swift

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

Screen

Objective C
[client screen:@"Main" properties:@{@"prop_key" : @"prop_value"} option:NULL];

Swift

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

Identify

Objective C
[client identify:@"test_user_id" traits:@{
    @"foo": @"bar",
    @"foo1": @"bar1",
    @"email": @"test@gmail.com"
} option:NULL];

Swift

client.identify("test_user_id", traits:[
    "foo": "bar",
    "foo1": "bar1",
    "email": "test@email.com"
])

Group

Objective C
[client group:@"sample_group_id" traits:@{
    @"foo": @"bar", 
    @"foo1": @"bar1", 
    @"email": @"test@gmail.com"
} option:NULL];

Swift

client.group("sample_group_id" traits:[
    "foo": "bar", 
    "foo1": "bar1", 
    "email": "test@gmail.com"
])

Alias

Objective C
[client alias:@"new_user_id" option:NULL];

Swift

client.alias("new_user_id")

Reset

Objective C
[client reset];

Swift

client.reset()

For detailed documentation on the iOS SDK, click here.

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.

GitHub

link
Stars: 0
Last commit: 2 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Release v1.0.0-beta.6
1 week ago

What's Changed

  • [Enhancement] Added LifeCycleEvents, identify and screen keys.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics