Documentation

iOS Implementation

Introduction

For iOS applications, our SDK provides two essential functions to manage the client_user_id: initialize(clientUserId: String? = nil) and setClientUserId( clientUserId: String?). These functions enable the integration of user-specific analytics in your app.

Functions

initialize(clientUserId: String? = nil)

  • Purpose: This function is used to initialize the SDK with an optional client_user_id. It should be called at the beginning of the SDK initialization process in your iOS app.
  • Parameters:
    clientUserId: A String value representing the unique identifier of the user. It is optional and can be nil.
  • Behavior:
    If a non-nil clientUserId is provided, the SDK will begin tracking and associating user data with the given ID.
    If nil is passed or the parameter is omitted, no user-specific tracking will occur until a client_user_id is set.

setClientUserId(_ clientUserId: String?)

  • Purpose: This function allows you to set or reset the client_user_id at any point after the SDK has been initialized.
  • Parameters:
    clientUserId: A String value representing the unique identifier of the user. It can be nil.
  • Behavior:
    Passing a non-nil clientUserId will update the current user ID and start tracking new analytics data under this ID.
    Passing nil will reset/clear the existing client_user_id, stopping any further user-specific data collection until a new ID is set.

Examples

1. Initialize SDK with a Specific User ID

KeyboardSDK.initialize(clientUserId: "tappa_swiftui_demo")

This initializes the SDK with a client_user_id of "tappa_swiftui_demo", enabling user-specific analytics from the start.

2. Reset/Clear the Client User ID

KeyboardSDK.setClientUserId(clientUserId: nil)

This resets the client_user_id, halting the collection of user-specific data.

3. Set or Update the Client User ID

KeyboardSDK.setClientUserId(clientUserId: "tappa_swiftui_demo")

This sets or updates the client_user_id to "tappa_swiftui_demo", resuming or starting user-specific analytics tracking.

Best Practices

  • Call initialize at the earliest appropriate lifecycle method of your app to ensure the SDK is ready for use.
  • Use setClientUserId judiciously to update the user ID only when necessary, such as when a user logs in or changes accounts.
  • Ensure that user IDs are unique and consistent for each user to maintain accurate analytics.