-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add base survey integration #314
base: feat/mobile-surveys
Are you sure you want to change the base?
Conversation
# Conflicts: # CHANGELOG.md # Makefile # PostHog.podspec # PostHog.xcodeproj/project.pbxproj # PostHog/PostHogApi.swift # PostHog/PostHogSDK.swift # PostHog/PostHogVersion.swift # PostHogTests/PostHogFeatureFlagsTest.swift # PostHogTests/PostHogSessionManagerTest.swift # PostHogTests/TestUtils/MockApplicationLifecyclePublisher.swift # PostHogTests/TestUtils/TestPostHog.swift
@@ -59,11 +59,11 @@ import Foundation | |||
@objc public let sessionReplayConfig: PostHogSessionReplayConfig = .init() | |||
#endif | |||
|
|||
#if os(iOS) | |||
#if os(iOS) || TESTING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public api is still draft here. Just added TESTING so that tests can run on CI as well for now
#else | ||
properties["$is_emulator"] = false | ||
#endif | ||
if let deviceType = PostHogContext.deviceType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to extract deviceType
logic here since it was needed for surveys as well. Cleaned up/refactored a bit PostHogContext
@@ -37,7 +37,7 @@ let maxRetryDelay = 30.0 | |||
|
|||
private var queue: PostHogQueue? | |||
private var replayQueue: PostHogQueue? | |||
private var storage: PostHogStorage? | |||
private(set) var storage: PostHogStorage? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to internal visibility since it will be used by surveys to check survey seen info
return postHog.isFeatureEnabled(flagKey) | ||
} | ||
|
||
private func canRenderSurvey(survey _: Survey) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temp. Not called yet
private func setActiveSurvey(survey: Survey) { | ||
activeSurveyLock.withLock { | ||
if let activeSurvey { | ||
hedgeLog("Survey \(activeSurvey) already in focus. Cannot add survey \(survey).") | ||
return | ||
} | ||
activeSurvey = survey | ||
} | ||
} | ||
|
||
/// Removes given survey as active survey | ||
private func removeActiveSurvey(survey: Survey) { | ||
activeSurveyLock.withLock { | ||
guard activeSurvey?.id != survey.id else { | ||
hedgeLog("Survey \(survey) is not in focus. Cannot remove survey \(survey)") | ||
return | ||
} | ||
activeSurvey = nil | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temp. Not called yet
return matchType.matches(targets: deviceTypes, value: deviceType) | ||
} | ||
|
||
private func getNextSurveyStep( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temp. Not called yet
💡 Motivation and Context
Added base logic for survey integration, including flag-based/internal targeting and device type checks for display conditions.
Added some draft/test implementation on presentation logic.
No event trigger handling yet—considering a simple
surveyIntegration.onEventCaptured()
call for now. Ideally, though, internal delegates or handlers could provide better decoupling and would also enable us exposing these to the public API in the near future, something which is already requested herePublic API is still draft
#skip-changelog
TODO:
- user inputs are masked
- surveys are captured
💚 How did you test it?
Unit tests
📝 Checklist