SDK for iOS methods

View as Markdown

The SDK for iOS is equipped to handle all essential event calls, including screen, track, identify, and group. Furthermore, it offers functionalities to efficiently manage session information.

With these capabilities, you can seamlessly track and analyze user interactions, facilitating a comprehensive understanding of user behavior and engagement.

Below the SDK for iOS methods:

screen

The screen method implements the screen call.

The screen call enables you to capture instances when a user views a screen and record associated properties or details about that particular screen.

Syntax

screen(title: String, category: String? = nil, properties: P?)

Parameters

Name Type Required Description
title String
Title of the screen.
category String? Category to describe the screen.
properties P: Encodable Properties of the screen.

Example

analytics.screen(title: "Order completed", properties: [
    "items": 3,
    "total": 274.99
])

track

The track method implements the track call.

The track call is used to send specific events or pipelines, and associated properties, that occur when users interact with your application or website.

Syntax

track(name: String, properties: P?)

Parameters

Name Type Required Description
name String
Name of the event.
properties P: Encodable Properties of the event.

Example

analytics.track(name: "Product added to cart", properties: [
    "id": 12345
])

identify

The identify method implements the identify call.

Through an identify call, you can connect previous and upcoming events to a recognized user and save details about them along with their events, such as name and email. The user information can also be utilized to update and enhance unified data from other sources.

Syntax

identify(userId: String, traits: T?)

Parameters

Name Type Required Description
userId String
Identifier of the user.
traits T: Encodable Traits to add to the user's traits.

Example

analytics.identify(userId: "59a20n37ec82", traits: [
    "firstName": "Emily",
    "lastName": "Johnson",
    "email": "emma.johnson@example.com"
])

group

The group method implements the group call.

The group call provides a way to associate individual users with groups, such as a company, organization, team, association, or initiative. A user who has been identified can be associated with several groups.

Syntax

group(groupId: String, traits: T?)

Parameters

Name Type Required Description
groupId String
Identifier of the group.
traits T: Encodable Traits of the group.

Example

analytics.group(groupId: "84s76y49tb28v1jxq", traits: [
    "name": "AcmeTech",
    "industry": "Technology",
    "employeeCount": 100
])

traits

The traits method is used to retrieve a user's traits. These traits are for the anonymous user if the user is anonymous, and for the non-anonymous user if non-anonymous.

To modify the user's traits, use the identify method or the reset method.

Syntax

traits() -> [String: Any]?

Parameters

There are no parameters.

Example

let traits = analytics.traits()

alias

The alias method is used to merge two user identities, effectively connecting two sets of user data as one. This method is applicable when the event is sent to a destination, such as Mixpanel.

In Krenalis, user merging is handled by Krenalis's Identity Resolution. Therefore this method is not utilized in this process.

Syntax

alias(newId: String)

Parameters

Name Type Required Description
newId String
The new ID you want to alias the existing ID to.

Example

analytics.alias(newId: "12r60m18ff04")

reset

The reset method resets the user identifier, and updates or removes the Anonymous ID and traits according to the strategy (as detailed in the table below). If all is true it always resets the Anonymous ID by generating a new one, and ends the session if one exists, regardless of the strategy.

Strategy Behavior of reset()
Conversion Removes User ID and user traits, and changes Anonymous ID and session.
Fusion Removes User ID and user traits. Does not change Anonymous ID or session.
Isolation Removes User ID and user traits and changes Anonymous ID and session.
Preservation Removes User ID. Restores Anonymous ID, user traits and session to their state before the latest identify call.

Syntax

reset(all: Bool = false)

Parameters

Name Type Required Description
all Bool Indicates if the Anonymous ID and the session must be reset, regardless of the strategy.

Example

analytics.reset()

Segment Compatibility

To align with Segment's reset() behavior, choose the "Conversion" or "Isolation" strategy in Krenalis. Note that reset(all: true) is not available in Segment.

RudderStack Compatibility

To match RudderStack's reset() behavior, choose the "Conversion" or "Isolation" strategy in Krenalis. In Krenalis, reset(all: true) works the same way as it does in RudderStack for all strategies.

getSessionId

The getSessionId method returns the current session identifier. It returns nil if there is no session.

Syntax

getSessionId() -> Int64?

Parameters

There are no parameters.

Example

let sessionId = analytics.getSessionId()

startSession

The startSession method starts a new session using the provided identifier. If the identifier provided is nil, it generates one automatically using the current time in milliseconds. The provided session ID, if not nil, must be a positive Int64.

Syntax

startSession(id: Int64? = nil)

Parameters

Name Type Required Description
id Int64? Session identifier. Must be positive.

Example

analytics.startSession(id: 123456789)

endSession

The endSession method ends the session.

Syntax

endSession()

Parameters

There are no parameters.

Example

analytics.endSession()