Skip to content

Commit

Permalink
integrate statsig (#215)
Browse files Browse the repository at this point in the history
* integrate statsig

* comment

* remove FirebaseRemoteConfig

* add skip to features.json

* change inputs to on/off

* integrate statsig with featureflag protocol

* comment

* change assertion failure to log

* delete file

* deleted code

* comment

* Update PodFile

* bump abacus

* fix pods?

* remove unnecessary import

---------

Co-authored-by: Mike <[email protected]>
  • Loading branch information
mike-dydx and mike-dydx committed Aug 20, 2024
1 parent 847edaf commit 82c2ca8
Show file tree
Hide file tree
Showing 138 changed files with 29,386 additions and 20,786 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
314B5E4723DCCD6800139EB3 /* FirebaseRunner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 314B5E3823DCCD6700139EB3 /* FirebaseRunner.swift */; };
314B5E4823DCCD6800139EB3 /* FirebaseFeatureFlagsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 314B5E3A23DCCD6700139EB3 /* FirebaseFeatureFlagsProvider.swift */; };
314B5E4923DCCD6800139EB3 /* CrashlyticsErrorLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 314B5E3C23DCCD6700139EB3 /* CrashlyticsErrorLogging.swift */; };
314B5E4A23DCCD6800139EB3 /* FirebaseTracking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 314B5E3E23DCCD6700139EB3 /* FirebaseTracking.swift */; };
314B5E4B23DCCD6800139EB3 /* FirebaseNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 314B5E4023DCCD6800139EB3 /* FirebaseNotification.swift */; };
Expand Down Expand Up @@ -227,7 +226,6 @@
2AC82E9412F0658CCD3B5F99 /* Pods-iOS-FirebaseStaticInjectionsTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iOS-FirebaseStaticInjectionsTests.debug.xcconfig"; path = "Target Support Files/Pods-iOS-FirebaseStaticInjectionsTests/Pods-iOS-FirebaseStaticInjectionsTests.debug.xcconfig"; sourceTree = "<group>"; };
3101FAF82511444A00AC4010 /* GoogleLogin.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GoogleLogin.xib; sourceTree = "<group>"; };
314B5E3823DCCD6700139EB3 /* FirebaseRunner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirebaseRunner.swift; sourceTree = "<group>"; };
314B5E3A23DCCD6700139EB3 /* FirebaseFeatureFlagsProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirebaseFeatureFlagsProvider.swift; sourceTree = "<group>"; };
314B5E3C23DCCD6700139EB3 /* CrashlyticsErrorLogging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CrashlyticsErrorLogging.swift; sourceTree = "<group>"; };
314B5E3E23DCCD6700139EB3 /* FirebaseTracking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirebaseTracking.swift; sourceTree = "<group>"; };
314B5E4023DCCD6800139EB3 /* FirebaseNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirebaseNotification.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -291,7 +289,6 @@
314B5E3923DCCD6700139EB3 /* _FeatureFlags */ = {
isa = PBXGroup;
children = (
314B5E3A23DCCD6700139EB3 /* FirebaseFeatureFlagsProvider.swift */,
);
path = _FeatureFlags;
sourceTree = "<group>";
Expand Down Expand Up @@ -805,7 +802,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
314B5E4823DCCD6800139EB3 /* FirebaseFeatureFlagsProvider.swift in Sources */,
314B5E4723DCCD6800139EB3 /* FirebaseRunner.swift in Sources */,
314B5E4923DCCD6800139EB3 /* CrashlyticsErrorLogging.swift in Sources */,
31B3E3C122763B19009E8FEF /* FirebaseStaticInjections.swift in Sources */,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

2 changes: 1 addition & 1 deletion JedioKit/JedioKit/_Field/FieldDefinition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Utilities
}

override open var parser: Parser {
return Parser.featureFlagged
return Parser.standard
}
}

Expand Down
2 changes: 1 addition & 1 deletion JedioKit/JedioKit/_Field/FieldDefinitionGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Utilities

@objc open class FieldDefinitionGroup: DictionaryEntity {
override open var parser: Parser {
return Parser.featureFlagged
return Parser.standard
}

public var input: Bool {
Expand Down
2 changes: 1 addition & 1 deletion JedioKit/JedioKit/_Field/FieldLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ import Utilities
}

override open var parser: Parser {
return Parser.featureFlagged
return Parser.standard
}
}
4 changes: 0 additions & 4 deletions ParticlesKit/ParticlesKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
3101F98D25112EBE00AC4010 /* LocatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3101F98A25112EBE00AC4010 /* LocatorService.swift */; };
3101F99325112F2600AC4010 /* Login.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3101F99125112F2500AC4010 /* Login.xib */; };
3101F99425112F2600AC4010 /* Logout.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3101F99225112F2600AC4010 /* Logout.xib */; };
3102D3052720C622000E7B3A /* FeaturesConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3102D3042720C622000E7B3A /* FeaturesConfig.swift */; };
310C4F742533B57700DF1D62 /* StreamApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310C4F732533B57700DF1D62 /* StreamApi.swift */; };
310C4F752533B57700DF1D62 /* StreamApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310C4F732533B57700DF1D62 /* StreamApi.swift */; };
310C4F762533B57700DF1D62 /* StreamApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310C4F732533B57700DF1D62 /* StreamApi.swift */; };
Expand Down Expand Up @@ -414,7 +413,6 @@
3101F98A25112EBE00AC4010 /* LocatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocatorService.swift; sourceTree = "<group>"; };
3101F99125112F2500AC4010 /* Login.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Login.xib; sourceTree = "<group>"; };
3101F99225112F2600AC4010 /* Logout.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Logout.xib; sourceTree = "<group>"; };
3102D3042720C622000E7B3A /* FeaturesConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeaturesConfig.swift; sourceTree = "<group>"; };
310C4F732533B57700DF1D62 /* StreamApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamApi.swift; sourceTree = "<group>"; };
311C0FDA21B0E9C4001775BA /* ParticlesKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ParticlesKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
311C0FDD21B0E9C4001775BA /* ParticlesKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ParticlesKit.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -630,7 +628,6 @@
3102D2FF2720C5DD000E7B3A /* _Features */ = {
isa = PBXGroup;
children = (
3102D3042720C622000E7B3A /* FeaturesConfig.swift */,
);
path = _Features;
sourceTree = "<group>";
Expand Down Expand Up @@ -1558,7 +1555,6 @@
314B61DD23DCCE6200139EB3 /* ErrorLogging.swift in Sources */,
314B620523DCCE6200139EB3 /* InteractorProtocol.swift in Sources */,
314B618D23DCCE6100139EB3 /* XibProviderProtocol.swift in Sources */,
3102D3052720C622000E7B3A /* FeaturesConfig.swift in Sources */,
314B623123DCCE6200139EB3 /* GridInteractor.swift in Sources */,
314B61C123DCCE6200139EB3 /* TimeCounter+Particle.swift in Sources */,
314B61D123DCCE6200139EB3 /* LoaderProtocol.swift in Sources */,
Expand Down
32 changes: 0 additions & 32 deletions ParticlesKit/ParticlesKit/_Cache/_Features/FeaturesConfig.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class JsonCredentialsProvider: NSObject {

private var entity: DictionaryEntity?

public func key(for lookupKey: String) -> String? {
public func credential(for lookupKey: String) -> String? {
let content = entity?.data?[lookupKey]
if let contentDict = parser.asDictionary(content) {
let value = parser.asString(contentDict["value"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ import Utilities
completion()
}

public func flag(feature: String?) -> Any? {
if let feature = feature {
if let value = featureFlags?[feature] {
if (value as? String) == "<null>" {
return nil
}
return value
}
public func isOn(feature: String) -> Bool? {
featureFlags?[feature] as? Bool
}

public func value(feature: String) -> String? {
if let value = featureFlags?[feature] as? String {
return value
}
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions ParticlesKit/ParticlesKit/_Shared/ParticlesInjection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ open class ParticlesInjection: NSObject, InjectionProtocol {

open func injectParsers() {
Console.shared.log("injectParsers")
// Router and Xib loader supports Feature flagging
MappedRouter.parserOverwrite = Parser.featureFlagged
XibJsonFile.parserOverwrite = Parser.featureFlagged
MappedRouter.parserOverwrite = Parser.standard
XibJsonFile.parserOverwrite = Parser.standard
JsonEndpointResolver.parserOverwrite = Parser.debug
JsonCredentialsProvider.parserOverwrite = Parser.debug
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open class ParticlesPlatformInjection: ParticlesInjection {

HapticFeedback.shared = MotionHapticFeedback()
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
RoutingTabBarController.parserOverwrite = Parser.featureFlagged
RoutingTabBarController.parserOverwrite = Parser.standard
PrompterFactory.shared = UIKitPrompterFactory()
}
}
34 changes: 26 additions & 8 deletions Shared/CommonAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import FirebaseStaticInjections
import dydxStateManager
import dydxViews
import dydxAnalytics
import StatsigInjections

open class CommonAppDelegate: ParticlesAppDelegate {
open var notificationTag: String {
Expand All @@ -45,17 +46,18 @@ open class CommonAppDelegate: ParticlesAppDelegate {

override open func injectFeatures(completion: @escaping () -> Void) {
Console.shared.log("injectFeatures")
// these two injections need to happen before app start
// these three injections need to happen before app start
injectFirebase()
injectRating()
injectStatsigApiKey()
let compositeFeatureFlags = CompositeFeatureFlagsProvider()
switch Installation.source {
case .debug, .testFlight:
compositeFeatureFlags.local = FeatureFlagsStore.shared
case .appStore, .jailBroken:
break
}
compositeFeatureFlags.remote = FirebaseRunner.shared.enabled ? FirebaseFeatureFlagsProvider() : nil
compositeFeatureFlags.remote = StatsigFeatureFlagsProvider.shared
FeatureService.shared = compositeFeatureFlags
FeatureService.shared?.activate { /* [weak self] in */
Injection.shared?.injectFeatured(completion: completion)
Expand Down Expand Up @@ -101,26 +103,42 @@ open class CommonAppDelegate: ParticlesAppDelegate {
add(errorLogging: CrashlyticsErrorLogging())
}
}

open func injectAmplitude() {
Console.shared.log("injectAmplitude")
let apiKey: String?
switch Installation.source {
case .jailBroken, .debug, .testFlight:
apiKey = CredientialConfig.shared.key(for: "amplitudeStagingApiKey")
apiKey = CredientialConfig.shared.credential(for: "amplitudeStagingApiKey")
case .appStore:
apiKey = CredientialConfig.shared.key(for: "amplitudeApiKey")
apiKey = CredientialConfig.shared.credential(for: "amplitudeApiKey")
}
if let apiKey = apiKey, apiKey.isNotEmpty {
AmplitudeRunner.shared.apiKey = apiKey
add(tracking: dydxAmplitudeTracking())
}
}

open func injectStatsigApiKey() {
Console.shared.log("injectStatsig")
let environment: StatsigFeatureFlagsProvider.Environment
switch Installation.source {
case .debug, .testFlight:
environment = .development
case .appStore, .jailBroken:
environment = .production
}
guard let apiKey = CredientialConfig.shared.credential(for: "statsigApiKey") else {
assertionFailure("Statsig API key is missing")
return
}
StatsigFeatureFlagsProvider.shared = StatsigFeatureFlagsProvider(apiKey: apiKey, environment: environment)
}

open func injectAttribution() {
Console.shared.log("injectAttribution")
if let devKey = CredientialConfig.shared.key(for: "appsFlyerDevKey"), devKey.isNotEmpty,
let appId = CredientialConfig.shared.key(for: "appsFlyerAppId"), appId.isNotEmpty {
if let devKey = CredientialConfig.shared.credential(for: "appsFlyerDevKey"), devKey.isNotEmpty,
let appId = CredientialConfig.shared.credential(for: "appsFlyerAppId"), appId.isNotEmpty {
AppsFlyerRunner.shared.devKey = devKey
AppsFlyerRunner.shared.appId = appId
Attributer.shared = AppsFlyerAttributor()
Expand Down Expand Up @@ -155,7 +173,7 @@ open class CommonAppDelegate: ParticlesAppDelegate {
}

open func injectWebview() {
ParticlesWebView.setup(urlString: CredientialConfig.shared.key(for: "webAppUrl"))
ParticlesWebView.setup(urlString: CredientialConfig.shared.credential(for: "webAppUrl"))
}

override open func startup(completion: @escaping () -> Void) {
Expand Down
Loading

0 comments on commit 82c2ca8

Please sign in to comment.