PostHog iOS SDK
SDK Version:
PostHogSDK
The PostHogSDK class
Initialization methods
Examples
Returns
| Type |
|---|
Void |
withpublic
with method
Parameters
| Name | Type |
|---|---|
config | PostHogConfig |
The config parameter | |
param1 | PostHogSDK |
The param1 parameter | |
Examples
Returns
| Type |
|---|
PostHogSDK |
Capture methods
capturepublic
Captures a custom event without additional properties.
Notes:
Use this method to track user behavior or other occurrences in your application.
Parameters
| Name | Type |
|---|---|
event | Any |
The name of the event to capture. We recommend using an format (e.g., , ). | |
Examples
Returns
| Type |
|---|
Void |
capturepublic
capture method
Parameters
| Name | Type |
|---|---|
event | String |
The event parameter | |
distinctId | String |
The distinctId parameter | |
properties? | [String : Any]? = nil, |
The properties parameter | |
Examples
Returns
| Type |
|---|
Void |
capturepublic
capture method
Parameters
| Name | Type |
|---|---|
event | String |
The event parameter | |
distinctId | String |
The distinctId parameter | |
properties? | [String : Any]? = nil, |
The properties parameter | |
Examples
Returns
| Type |
|---|
Void |
capturepublic
capture method
Parameters
| Name | Type |
|---|---|
event | String |
The event parameter | |
properties? | [String : Any]? = nil |
The properties parameter | |
Examples
Returns
| Type |
|---|
Void |
capturepublic
Captures a custom event with optional event properties and user properties.
Notes:
Use this method to track user behavior or other occurrences, including additional context about the event and the user.
Parameters
| Name | Type |
|---|---|
event | Any |
The name of the event to capture. We recommend using an format (e.g., , ). | |
properties | String |
Optional. A dictionary with key-value pairs to include as event properties. | |
userProperties | String |
Optional. A dictionary with key-value pairs to set or update on the person profile associated with the event. These are set using . | |
Examples
Returns
| Type |
|---|
Void |
capturepublic
capture method
Parameters
| Name | Type |
|---|---|
event | String |
The event parameter | |
properties? | [String : Any]? = nil, |
The properties parameter | |
Examples
Returns
| Type |
|---|
Void |
capturepublic
capture method
Parameters
| Name | Type |
|---|---|
event | String |
The event parameter | |
properties? | [String : Any]? = nil, |
The properties parameter | |
Examples
Returns
| Type |
|---|
Void |
flushpublic
Manually flushes the event queue, sending all stored events to PostHog immediately.
Notes:
The SDK normally flushes events automatically based on and configuration. Call this method to force an immediate dispatch of events.
Examples
Returns
| Type |
|---|
Void |
registerpublic
register method
Parameters
| Name | Type |
|---|---|
properties | [String : Any] |
The properties parameter | |
Examples
Returns
| Type |
|---|
Void |
screenpublic
Captures a screen view event with a given title.
Notes:
This is a convenience method for without additional properties.
Parameters
| Name | Type |
|---|---|
screenTitle | Any |
The title or name of the screen being viewed. | |
Examples
Returns
| Type |
|---|
Void |
screenpublic
Captures a screen view event with an optional title and properties.
Notes:
Use this method to manually track screen changes in your application, especially for SwiftUI apps where automatic screen view tracking might not provide meaningful names.
Parameters
| Name | Type |
|---|---|
screenTitle | Any |
The title or name of the screen being viewed. | |
properties | String |
Optional. A dictionary with key-value pairs to include as event properties. | |
Examples
Returns
| Type |
|---|
Void |
unregisterpublic
unregister method
Parameters
| Name | Type |
|---|---|
key | String |
The key parameter | |
Examples
Returns
| Type |
|---|
Void |
Configuration methods
closepublic
close method
Examples
Returns
| Type |
|---|
Void |
debugpublic
Toggles verbose logging for the PostHog SDK.
Notes:
Enable debug mode to see detailed logs about event capture, feature flag evaluation, surveys, and other internal workings of the SDK. This is useful for troubleshooting during development.
Parameters
| Name | Type |
|---|---|
enabled | Any |
to enable debug mode, to disable. Defaults to . | |
Examples
Returns
| Type |
|---|
Void |
grouppublic
Associates the current session’s events with a specific group.
Notes:
Use this method to track user activity within a particular group (e.g., a company or team).
Parameters
| Name | Type |
|---|---|
type | String |
The group type (e.g., “company”, “team”). | |
key | String |
A unique identifier for the group in your database. | |
Examples
Returns
| Type |
|---|
Void |
grouppublic
Associates the current session’s events with a group and updates that group’s properties.
Notes:
This method allows you to track user activity within a group while simultaneously setting or updating properties associated with that group.
Parameters
| Name | Type |
|---|---|
type | String |
The group type (e.g., “company”, “team”). | |
key | String |
A unique identifier for the group in your database. | |
groupProperties | String |
Optional. A dictionary with key-value pairs to set or update on the group profile. | |
Examples
Returns
| Type |
|---|
Void |
didStartNotificationpublic
didStartNotification method
Examples
Returns
| Type |
|---|
Void |
sharedpublic
shared method
Examples
Returns
| Type |
|---|
Void |
Feature flags methods
getFeatureFlagpublic
Retrieves the value of a feature flag.
Notes:
The value of the feature flag (e.g., , ), or if the flag is not found.
Parameters
| Name | Type |
|---|---|
key | Any |
The key of the feature flag. | |
Examples
Returns
| Type |
|---|
Any? |
getFeatureFlagPayloadpublic
Retrieves the payload associated with a feature flag.
Notes:
The payload of the feature flag, or if no payload is associated or the flag is not found.
Parameters
| Name | Type |
|---|---|
key | Any |
The key of the feature flag. | |
Examples
Returns
| Type |
|---|
Any? |
isFeatureEnabledpublic
Checks if a boolean feature flag is enabled for the current user.
Notes:
if the feature flag is enabled, otherwise.
Parameters
| Name | Type |
|---|---|
key | Any |
The key of the feature flag. | |
Examples
Returns
| Type |
|---|
Bool |
reloadFeatureFlagspublic
Reloads all feature flags for the current user.
Notes:
Feature flag values are cached. Call this method to refetch the latest flag values from the server if something has changed with your user (e.g., properties updated).
Examples
Returns
| Type |
|---|
Void |
reloadFeatureFlagspublic
Reloads all feature flags for the current user and executes a completion callback.
Notes:
Use this method to refetch the latest flag values and perform actions immediately after the flags have been successfully reloaded.
Parameters
| Name | Type |
|---|---|
callback | Any |
A closure to be executed after feature flags are reloaded. | |
Examples
Returns
| Type |
|---|
Void |
resetGroupPropertiesForFlagspublic
Clears all group properties for feature flag evaluation.
Notes:
Clears all group properties for feature flag evaluation.
Examples
Returns
| Type |
|---|
Void |
resetGroupPropertiesForFlagspublic
Clears group properties for feature flag evaluation for a specific group type.
Notes:
Clears group properties for feature flag evaluation for a specific group type.
Parameters
| Name | Type |
|---|---|
groupType | Any |
The group type to clear properties for | |
Examples
Returns
| Type |
|---|
Void |
resetPersonPropertiesForFlagspublic
Resets all person properties that were set for feature flag evaluation.
Notes:
After calling this method, feature flag evaluation will only use server-side person properties and will not include any locally overridden properties.
Examples
Returns
| Type |
|---|
Void |
setGroupPropertiesForFlagspublic
Sets properties for a specific group type to include when evaluating feature flags. These properties supplement the standard group information sent to PostHog for flag evaluation, providing additional context that can be used in flag targeting conditions.
Notes:
Sets properties for a specific group type to include when evaluating feature flags. These properties supplement the standard group information sent to PostHog for flag evaluation, providing additional context that can be used in flag targeting conditions.
Parameters
| Name | Type |
|---|---|
groupType | Any |
The group type identifier (e.g., “organization”, “team”) | |
properties | String |
Dictionary of properties to set for this group type | |
Examples
Returns
| Type |
|---|
Void |
setGroupPropertiesForFlagspublic
Sets properties for a specific group type to include when evaluating feature flags. These properties supplement the standard group information sent to PostHog for flag evaluation, providing additional context that can be used in flag targeting conditions.
Notes:
Sets properties for a specific group type to include when evaluating feature flags. These properties supplement the standard group information sent to PostHog for flag evaluation, providing additional context that can be used in flag targeting conditions.
Parameters
| Name | Type |
|---|---|
groupType | Any |
The group type identifier (e.g., “organization”, “team”) | |
properties | String |
Dictionary of properties to set for this group type | |
reloadFeatureFlags | Bool |
Whether to automatically reload feature flags after setting properties | |
Examples
Returns
| Type |
|---|
Void |
setPersonPropertiesForFlagspublic
Sets person properties that will be included in feature flag evaluation requests.
Notes:
This method allows you to override server-side person properties for immediate feature flag evaluation, solving the race condition where person properties from calls may not have been processed by the server yet. Properties are merged additively with existing properties. Feature flags are automatically reloaded after setting properties.
Parameters
| Name | Type |
|---|---|
properties | Any |
Dictionary of person properties to include in flag evaluation | |
Examples
Returns
| Type |
|---|
Void |
setPersonPropertiesForFlagspublic
Sets person properties that will be included in feature flag evaluation requests.
Notes:
This method allows you to override server-side person properties for immediate feature flag evaluation, solving the race condition where person properties from calls may not have been processed by the server yet. Properties are merged additively with existing properties.
Parameters
| Name | Type |
|---|---|
properties | Any |
Dictionary of person properties to include in flag evaluation | |
reloadFeatureFlags | Bool |
Whether to automatically reload feature flags after setting properties | |
Examples
Returns
| Type |
|---|
Void |
didReceiveFeatureFlagspublic
didReceiveFeatureFlags method
Examples
Returns
| Type |
|---|
Void |
Identification methods
aliaspublic
Assigns an additional distinct ID to the current user.
Notes:
Use this method when you want to associate multiple distinct IDs with a single user, for example, if a distinct ID used on the frontend is not available in your backend.
Parameters
| Name | Type |
|---|---|
alias | Any |
The new distinct ID to associate with the current user. | |
Examples
Returns
| Type |
|---|
Void |
getAnonymousIdpublic
getAnonymousId method
Examples
Returns
| Type |
|---|
String |
getDistinctIdpublic
Returns the current user’s distinct ID.
Notes:
The current user’s distinct ID.
Examples
Returns
| Type |
|---|
String |
identifypublic
Associates events with a specific user by their distinct ID.
Notes:
This is a convenience method for without additional properties. You should call this method as soon as you are able to identify your user, typically after they log in.
Parameters
| Name | Type |
|---|---|
distinctId | Any |
A unique identifier for your user in your database. | |
Examples
Returns
| Type |
|---|
Void |
identifypublic
identify method
Parameters
| Name | Type |
|---|---|
distinctId | String |
The distinctId parameter | |
userProperties? | [String : Any]? = nil |
The userProperties parameter | |
Examples
Returns
| Type |
|---|
Void |
identifypublic
Associates events with a specific user by their distinct ID and sets/updates user properties.
Notes:
Use this method to gain insights into how your users interact with your product across sessions, devices, and platforms. All previously tracked anonymous events will be linked to this user.
Parameters
| Name | Type |
|---|---|
distinctId | Any |
A unique identifier for your user in your database. | |
userProperties | String |
Optional. A dictionary with key-value pairs to set on the person profile. These are set using . | |
userPropertiesSetOnce | String |
Optional. A dictionary with key-value pairs to set on the person profile only if they don’t already exist. These are set using . | |
Examples
Returns
| Type |
|---|
Void |
Privacy methods
isOptOutpublic
Checks if the user is currently opted out of data capture.
Notes:
if the user is opted out, otherwise.
Examples
Returns
| Type |
|---|
Bool |
optInpublic
Opts the user back into data capture.
Notes:
This method allows a previously opted-out user to resume data capture.
Examples
Returns
| Type |
|---|
Void |
optOutpublic
Opts the user out of all data capture.
Notes:
When a user is opted out, no events, session replays, or other data will be captured.
Examples
Returns
| Type |
|---|
Void |
resetpublic
Resets the user’s distinct ID, anonymous ID, and clears all super properties.
Notes:
This method is typically called after a user logs out to disassociate their activity from previous sessions and prepare for a new, potentially anonymous, user journey.
Examples
Returns
| Type |
|---|
Void |
Session replay methods
endSessionpublic
endSession method
Examples
Returns
| Type |
|---|
Void |
getSessionIdpublic
getSessionId method
Examples
Returns
| Type |
|---|
String? |
startSessionpublic
startSession method
Examples
Returns
| Type |
|---|
Void |
PostHogDisplaySurvey
A model representing a PostHog survey to be displayed to users
Configuration methods
appearancepublic
Optional appearance configuration for customizing the survey’s look and feel
Notes:
Optional appearance configuration for customizing the survey’s look and feel
Examples
Returns
| Type |
|---|
Void |
endDatepublic
Optional date indicating when the survey should stop being shown
Notes:
Optional date indicating when the survey should stop being shown
Examples
Returns
| Type |
|---|
Void |
idpublic
Unique identifier for the survey
Notes:
Unique identifier for the survey
Examples
Returns
| Type |
|---|
Void |
namepublic
Name of the survey
Notes:
Name of the survey
Examples
Returns
| Type |
|---|
Void |
questionspublic
Array of questions to be presented in the survey
Notes:
Array of questions to be presented in the survey
Examples
Returns
| Type |
|---|
Void |
startDatepublic
Optional date indicating when the survey should start being shown
Notes:
Optional date indicating when the survey should start being shown
Examples
Returns
| Type |
|---|
Void |
PostHogDisplayLinkQuestion
Represents a question with a clickable link
Configuration methods
linkpublic
The URL that will be opened when the link is clicked
Notes:
The URL that will be opened when the link is clicked
Examples
Returns
| Type |
|---|
Void |
PostHogDisplayChoiceQuestion
Represents a multiple or single choice question where users can select one or more options
Configuration methods
choicespublic
The list of options for the user to choose from
Notes:
The list of options for the user to choose from
Examples
Returns
| Type |
|---|
Void |
hasOpenChoicepublic
Whether the question includes an “other” option for users to input free-form text
Notes:
Whether the question includes an “other” option for users to input free-form text
Examples
Returns
| Type |
|---|
Void |
isMultipleChoicepublic
Whether the user can select multiple options
Notes:
Whether the user can select multiple options
Examples
Returns
| Type |
|---|
Void |
shuffleOptionspublic
Whether the options should be shuffled to randomize the order
Notes:
Whether the options should be shuffled to randomize the order
Examples
Returns
| Type |
|---|
Void |
PostHogNextSurveyQuestion
A model representing the next state of the survey progression.
Configuration methods
isSurveyCompletedpublic
Whether all questions have been answered and the survey is complete Depending on the survey appearance configuration, you may want to show the “Thank you” message or dismiss the survey at this point
Notes:
Whether all questions have been answered and the survey is complete Depending on the survey appearance configuration, you may want to show the “Thank you” message or dismiss the survey at this point
Examples
Returns
| Type |
|---|
Void |
questionIndexpublic
The index of the next question to be displayed (0-based)
Notes:
The index of the next question to be displayed (0-based)
Examples
Returns
| Type |
|---|
Void |
PostHogDisplayOpenQuestion
Represents an open-ended question where users can input free-form text
PostHogEvent
The PostHogEvent class
Configuration methods
distinctIdpublic
distinctId method
Examples
Returns
| Type |
|---|
Void |
eventpublic
event method
Examples
Returns
| Type |
|---|
Void |
propertiespublic
properties method
Examples
Returns
| Type |
|---|
Void |
timestamppublic
timestamp method
Examples
Returns
| Type |
|---|
Void |
uuidpublic
uuid method
Examples
Returns
| Type |
|---|
Void |
PostHogSurveyResponse
A model representing a user’s response to a survey question
Configuration methods
linkClickedpublic
Whether a link was clicked (for link questions)
Notes:
Whether a link was clicked (for link questions)
Examples
Returns
| Type |
|---|
Void |
ratingValuepublic
The numeric rating value (for rating questions)
Notes:
The numeric rating value (for rating questions)
Examples
Returns
| Type |
|---|
Void |
selectedOptionspublic
The selected options (for multiple or single choice questions)
Notes:
The selected options (for multiple or single choice questions)
Examples
Returns
| Type |
|---|
Void |
textValuepublic
The text response (for open questions)
Notes:
The text response (for open questions)
Examples
Returns
| Type |
|---|
Void |
typepublic
The type of response (link, rating, text, or multiple choice)
Notes:
The type of response (link, rating, text, or multiple choice)
Examples
Returns
| Type |
|---|
Void |
linkpublic
Creates a response for a link question
Notes:
Creates a response for a link question
Parameters
| Name | Type |
|---|---|
clicked | Any |
Whether the link was clicked | |
Examples
Returns
| Type |
|---|
PostHogSurveyResponse |
multipleChoicepublic
Creates a response for a multiple-choice question
Notes:
Creates a response for a multiple-choice question
Parameters
| Name | Type |
|---|---|
multipleChoice | Any |
The selected options | |
Examples
Returns
| Type |
|---|
PostHogSurveyResponse |
openEndedpublic
Creates a response for an open-ended question
Notes:
Creates a response for an open-ended question
Parameters
| Name | Type |
|---|---|
openEnded | Any |
The text response | |
Examples
Returns
| Type |
|---|
PostHogSurveyResponse |
ratingpublic
Creates a response for a rating question
Notes:
Creates a response for a rating question
Parameters
| Name | Type |
|---|---|
rating | Any |
The selected rating value | |
Examples
Returns
| Type |
|---|
PostHogSurveyResponse |
singleChoicepublic
Creates a response for a single-choice question
Notes:
Creates a response for a single-choice question
Parameters
| Name | Type |
|---|---|
singleChoice | Any |
The selected option | |
Examples
Returns
| Type |
|---|
PostHogSurveyResponse |
PostHogDisplaySurveyQuestion
Base class for all survey question types
Configuration methods
buttonTextpublic
Optional custom text for the question’s action button
Notes:
Optional custom text for the question’s action button
Examples
Returns
| Type |
|---|
Void |
idpublic
The question ID, empty if none
Notes:
The question ID, empty if none
Examples
Returns
| Type |
|---|
Void |
isOptionalpublic
Whether the question can be skipped
Notes:
Whether the question can be skipped
Examples
Returns
| Type |
|---|
Void |
questionpublic
The main question text to display
Notes:
The main question text to display
Examples
Returns
| Type |
|---|
Void |
questionDescriptionpublic
Optional additional description or context for the question
Notes:
Optional additional description or context for the question
Examples
Returns
| Type |
|---|
Void |
questionDescriptionContentTypepublic
Content type for the question description (HTML or plain text)
Notes:
Content type for the question description (HTML or plain text)
Examples
Returns
| Type |
|---|
Void |
PostHogSessionManager
The PostHogSessionManager class
Configuration methods
sharedpublic
shared method
Examples
Returns
| Type |
|---|
Void |
Session replay methods
setSessionIdpublic
setSessionId method
Parameters
| Name | Type |
|---|---|
sessionId | String |
The sessionId parameter | |
Examples
Returns
| Type |
|---|
Void |
PostHogSurveysConfig
The PostHogSurveysConfig class
Configuration methods
surveysDelegatepublic
Delegate responsible for managing survey presentation in your app. Handles survey rendering, response collection, and lifecycle events. You can provide your own delegate for a custom survey presentation.
Notes:
Defaults to which provides a standard survey UI.
Examples
Returns
| Type |
|---|
Void |
PostHogDisplayRatingQuestion
Represents a rating question where users can select a rating from a scale
Configuration methods
lowerBoundLabelpublic
The label for the lower bound of the rating scale
Notes:
The label for the lower bound of the rating scale
Examples
Returns
| Type |
|---|
Void |
ratingTypepublic
The type of rating scale (numbers, emoji)
Notes:
The type of rating scale (numbers, emoji)
Examples
Returns
| Type |
|---|
Void |
scaleLowerBoundpublic
The lower bound of the rating scale
Notes:
The lower bound of the rating scale
Examples
Returns
| Type |
|---|
Void |
scaleUpperBoundpublic
The upper bound of the rating scale
Notes:
The upper bound of the rating scale
Examples
Returns
| Type |
|---|
Void |
upperBoundLabelpublic
The label for the upper bound of the rating scale
Notes:
The label for the upper bound of the rating scale
Examples
Returns
| Type |
|---|
Void |
PostHogDisplaySurveyAppearance
Model that describes the appearance customization of a PostHog survey
Configuration methods
backgroundColorpublic
Optional background color as web color (e.g. “#FFFFFF” or “white”)
Notes:
Optional background color as web color (e.g. “#FFFFFF” or “white”)
Examples
Returns
| Type |
|---|
Void |
borderColorpublic
Optional border color as web color
Notes:
Optional border color as web color
Examples
Returns
| Type |
|---|
Void |
descriptionTextColorpublic
Optional color for description text as web color
Notes:
Optional color for description text as web color
Examples
Returns
| Type |
|---|
Void |
displayThankYouMessagepublic
Whether to show a thank you message after survey completion
Notes:
Whether to show a thank you message after survey completion
Examples
Returns
| Type |
|---|
Void |
fontFamilypublic
Optional font family to use throughout the survey
Notes:
Optional font family to use throughout the survey
Examples
Returns
| Type |
|---|
Void |
placeholderpublic
Optional placeholder text for input fields
Notes:
Optional placeholder text for input fields
Examples
Returns
| Type |
|---|
Void |
ratingButtonActiveColorpublic
Optional color for active/selected rating buttons as web color
Notes:
Optional color for active/selected rating buttons as web color
Examples
Returns
| Type |
|---|
Void |
ratingButtonColorpublic
Optional color for rating buttons as web color
Notes:
Optional color for rating buttons as web color
Examples
Returns
| Type |
|---|
Void |
submitButtonColorpublic
Optional background color for the submit button as web color
Notes:
Optional background color for the submit button as web color
Examples
Returns
| Type |
|---|
Void |
submitButtonTextpublic
Optional custom text for the submit button
Notes:
Optional custom text for the submit button
Examples
Returns
| Type |
|---|
Void |
submitButtonTextColorpublic
Optional text color for the submit button as web color
Notes:
Optional text color for the submit button as web color
Examples
Returns
| Type |
|---|
Void |
thankYouMessageCloseButtonTextpublic
Optional text for the close button in the thank you message
Notes:
Optional text for the close button in the thank you message
Examples
Returns
| Type |
|---|
Void |
thankYouMessageDescriptionpublic
Optional description text for the thank you message
Notes:
Optional description text for the thank you message
Examples
Returns
| Type |
|---|
Void |
thankYouMessageDescriptionContentTypepublic
Optional content type for the thank you message description
Notes:
Optional content type for the thank you message description
Examples
Returns
| Type |
|---|
Void |
thankYouMessageHeaderpublic
Optional header text for the thank you message
Notes:
Optional header text for the thank you message
Examples
Returns
| Type |
|---|
Void |