-
Notifications
You must be signed in to change notification settings - Fork 52
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
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() { | ||
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
💡 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