Search documentation...

K
ChangelogBook a demoSign up

iOS SDK

The iOS SDK makes it easy to track events from Swift and Objective-C applications.

Installation

The iOS SDK is hosted on GitHub at git@github.com:ht-sdks/events-sdk-swift.git under the name events-sdk-swift.

You may install the SDK by adding it to your package.swift file, or adding it as a Package Dependency via Xcode.

Initialization

You should initialize the SDK in a central location and store it in a variable for use across your application. For example, you may want to initialize it in your app delegate.

Swift example:

import Hightouch

let configuration = Configuration(writeKey: "YOUR_WRITE_KEY")
    .apiHost("us-east-1.hightouch-events.com/v1")

analytics = Analytics(configuration: configuration)

Objective-C example:

@import Hightouch

HTConfiguration *config = [[HTConfiguration alloc] initWithWriteKey:@"YOUR_WRITE_KEY"];
config.apiHost = "us-east-1.hightouch-events.com/v1";

analytics = [[HTAnalytics alloc] initWithConfiguration: config];

Configuration options:

OptionTypeDescription
writeKeyStringYour Highotuch write key.
apiHostStringThe API host to send the tracked events to.
flushAtIntThe number of events to queue before sending events to the Hightouch API. Defaults to 20.
flushIntervalIntThe maximum amount of time (in seconds) to store events locally before forwarding to Hightouch. Defaults to 30 seconds.
trackApplicationLifecycleEventsBoolWhether to automatically track application lifecycle events (like opening the application). Defaults to true.

API

Identify

The identify method sends an identify event. It accepts user id and trait information for the current user -- if you only have partial information, you can just supply a single parameter.

Method signature:

func identify<T: Codable>(userId: String, traits: T)
func identify<T: Codable>(traits: T)
func identify(userId: String)

Method parameters:

ParameterTypeDescription
userIdStringThe user's persistent ID
traitsCodableAdditional traits about the user, such as email and name.

Track

The track method sends a track event. The event name is required, and additional properties that describe the event may be supplied.

Method signature:

func track(name: String)
func track<P: Codable>(name: String, properties: P?)

Method parameters:

ParameterTypeDescription
nameStringThe name of the event.
propertiesCodableAdditional properties about the event, such as product_id.

Screen

The screen method sends a screen event. The screen title is required, and additional information about the screen's category and properties may be supplied.

Method signature:

func screen(title: String, category: String? = nil)
func screen<P: Codable>(title: String, category: String? = nil, properties: P?)

Method parameters:

ParameterTypeDescription
titleStringThe screen's name. For example "Getting started"
categoryStringThe screen's category. For example "Docs"
propertiesCodableAdditional properties about the event, such as from_link.

Group

The group method sends a group event.

The id identifying the user's group is required. Additional traits on the group can be provided.

Method signature:

func group(groupId: String)
func group<T: Codable>(groupId: String, traits: T?)

Method parameters:

ParameterTypeDescription
groupIdStringThe id for the group.
traitsCodableAdditional traits about the group, such as company_name.

Flush

The iOS SDK buffers events locally before sending them to Hightouch's servers. This minimizes the number of requests made by the SDK and makes the tracking non-blocking.

To force the local buffer to be sent to Hightouch immediately call the flush method.

Method signature:

func flush()

Reset

The reset method resets the identify and group for the local session. Specifically, it resets the anonymousId, userId, referrer, and traits.

The reset method should be called when users log out. This way, if the user logs back in with another account, the userIds and traits from the different sessions remain separate.

Method signature:

func reset()

Ready to get started?

Jump right in or a book a demo. Your first destination is always free.

Book a demoSign upBook a demo

Need help?

Our team is relentlessly focused on your success. Don't hesitate to reach out!

Feature requests?

We'd love to hear your suggestions for integrations and other features.

Last updated: Oct 4, 2023

On this page

InstallationInitializationAPIIdentifyTrackScreenGroupFlushReset

Was this page helpful?