Gate bitdrift integration (#7088)

* Move Statsig init call earlier

* Gate Bitdrift init call

* Remove IS_TEST env constant

* Mock statsig
This commit is contained in:
dan
2024-12-13 17:14:41 +00:00
committed by GitHub
parent 5655241bef
commit e2a7965e43
12 changed files with 38 additions and 24 deletions
+16 -3
View File
@@ -1,7 +1,20 @@
import {init} from '@bitdrift/react-native'
import {Statsig} from 'statsig-react-native-expo'
import {initPromise} from './statsig/statsig'
const BITDRIFT_API_KEY = process.env.BITDRIFT_API_KEY
if (BITDRIFT_API_KEY) {
init(BITDRIFT_API_KEY, {url: 'https://api-bsky.bitdrift.io'})
}
initPromise.then(() => {
let isEnabled = false
try {
if (Statsig.checkGate('enable_bitdrift')) {
isEnabled = true
}
} catch (e) {
// Statsig may complain about it being called too early.
}
if (isEnabled && BITDRIFT_API_KEY) {
init(BITDRIFT_API_KEY, {url: 'https://api-bsky.bitdrift.io'})
}
})
+2 -3
View File
@@ -16,6 +16,8 @@ import {Gate} from './gates'
const SDK_KEY = 'client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV'
export const initPromise = initialize()
type StatsigUser = {
userID: string | undefined
// TODO: Remove when enough users have custom.platform:
@@ -219,9 +221,6 @@ export async function tryFetchGates(
// Use this for less common operations where the user would be OK with a delay.
timeoutMs = 1500
}
// Note: This condition is currently false the very first render because
// Statsig has not initialized yet. In the future, we can fix this by
// doing the initialization ourselves instead of relying on the provider.
if (Statsig.initializeCalled()) {
await Promise.race([
timeout(timeoutMs),