-
Notifications
You must be signed in to change notification settings - Fork 59
feat: load remote config and feature flags #283
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: load remote config and feature flags #283
Conversation
@@ -217,4 +237,45 @@ class PostHogApi { | |||
} | |||
}.resume() | |||
} | |||
|
|||
func remoteConfig( |
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.
Call to new remote config endpoint
#if os(iOS) | ||
/// Enable mobile surveys | ||
/// Experimental support | ||
/// Default: false | ||
@objc public var surveysEnabled: Bool = false | ||
#endif |
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.
No functionality for now, just setting up the public api
// PostHog | ||
// | ||
// Created by Manoel Aranda Neto on 10.10.23. | ||
// | ||
|
||
import Foundation | ||
|
||
class PostHogFeatureFlags { | ||
class PostHogRemoteConfig { |
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.
Grouped config and feature flags in a single object here
} | ||
|
||
private func preloadFeatureFlags() { 10000 | ||
featureFlagsLock.withLock { |
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.
Not sure about this. I think we may need to move it in config.preloadFeatureFlags
check below
let cachedFeatureFlags = featureFlagsLock.withLock { self.featureFlags } | ||
let hasFeatureFlags = remoteConfig["hasFeatureFlags"] as? Bool == true | ||
if hasFeatureFlags, cachedFeatureFlags == nil { | ||
reloadFeatureFlags() |
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.
This is where we reload feature flags in case hasFeatureFlags
is true, but flags are missing
return nil | ||
} | ||
|
||
let url = baseUrl.appendingPathComponent("/array/\(config.apiKey)/config") |
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.
I think we should fix #274 otherwise its one more place that this will fail
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.
True, I'll follow up with another PR to address that part
* feat: load remote config and feature flags (#283) * feat: load remote config and feature flags * fix: cleanup * fix: redundant assignment * fix: hasFeatureFlags * fix: lint * feat: add survey domain models (#284) * feat: add survey domain models * fix: reuse date formatter * fix: improve test fixtures and model consistency * Merge branch 'main' into feat/mobile-surveys-merge-main (#313) * chore: session replay ga (#286) * fix: xcframework builds (#288) * fix: xcframework builds * fix: import access level * feat: add sample xcframework project * fix: build examples * chore: update CHANGELOG * Update version * chore: skip creating a visionOS simulator if not needed (#289) * chore: skip creating a visionOS simulator if not needed * fix: external sdk example * Update version * feat: add survey domain models * Merge branch 'main' into feat/mobile-surveys-merge-main # 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 * fix: lint * feat: add base survey integration (#314) * feat: add survey domain models * Merge branch 'main' into feat/mobile-surveys-merge-main # 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 * feat: base surveys integration * feat: base survey display * fix: builds * fix: test * fix: tests * fix: remote config tests * feat: add survey UI and display logic (#320) * feat: add survey domain models * Merge branch 'main' into feat/mobile-surveys-merge-main # 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 * feat: base surveys integration * feat: base survey display * fix: builds * fix: test * fix: tests * fix: remote config tests * feat: add survey ui components * feat: survey question type display and next question logic * feat: send survey seen, sent, dismissed events * feat: add event-activated surveys * fix: empty question description * fix: hit test on iOS 18 * fix: safe area inset * refactor: move display related to logic to display manager * fix: handle case displayThankYouMessage is false * fix: tests * fix: handle optional questions * fix: build * feat: public api * chore: update CHANGELOG * feat: iOS15 presentation detents (#324) * feat: add survey domain models * Merge branch 'main' into feat/mobile-surveys-merge-main # 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 * feat: base surveys integration * feat: base survey display * fix: builds * fix: test * fix: tests * fix: remote config tests * feat: add survey ui components * feat: survey question type display and next question logic * feat: send survey seen, sent, dismissed events * feat: add event-activated surveys * fix: empty question description * fix: hit test on iOS 18 * fix: safe area inset * refactor: move display related to logic to display manager * fix: handle case displayThankYouMessage is false * fix: tests * feat: add backport for iOS 15 presentation detents * fix: lint * fix: sheet height * fix: remove ViewBuilder attribute * feat: add configuration option for remoteConfig * chore: prefix survey models * fix: cache needed integrations in sdk instance * chore: split survey models to multiple files * chore: refactor remote config callback
💡 Motivation and Context
Building the foundation for mobile surveys. This is one part of many on the feature branch
feat/mobile-surveys
.This adds remote config loading and caching on SDK
hasFeatureFlags
. When this value is false, we can skip loading feature flags cause the team doesn't have any flags enabled.hasFeatureFlags
is true we make sure that flags are reloaded#skip-changelog
💚 How did you test it?
Modified and added some unit tests
📝 Checklist