From ee7282ea89f1a2f0f4ea111461e2d2dec2ea0991 Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 8 Jan 2025 11:17:48 -0800 Subject: [PATCH] add back statsig gate testing --- app.config.js | 9 +++++ src/lib/statsig/gates.ts | 2 + src/view/screens/Profile.tsx | 78 +++++++++++++++++++++++++++++++++++- 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/app.config.js b/app.config.js index d7428f5aeb..7f0dfacc33 100644 --- a/app.config.js +++ b/app.config.js @@ -39,6 +39,15 @@ module.exports = function (config) { const SENTRY_DIST = `${PLATFORM}.${VERSION}.${IS_TESTFLIGHT ? 'tf' : ''}${ IS_DEV ? 'dev' : '' }` + const fs = require('node:fs') + + fs.writeFile('./test.txt', process.env.EXPO_PUBLIC_ENV, err => { + if (err) { + console.error(err) + } else { + // file written successfully + } + }) return { expo: { diff --git a/src/lib/statsig/gates.ts b/src/lib/statsig/gates.ts index 455a703458..d2caa47f2a 100644 --- a/src/lib/statsig/gates.ts +++ b/src/lib/statsig/gates.ts @@ -4,4 +4,6 @@ export type Gate = | 'debug_subscriptions' | 'new_postonboarding' | 'remove_show_latest_button' + | 'test_gate_1' + | 'test_gate_2' | 'trending_topics_beta' diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index 24e8719e17..d4b6c25710 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useMemo} from 'react' +import React, {useCallback, useEffect, useMemo} from 'react' import {StyleSheet} from 'react-native' import {SafeAreaView} from 'react-native-safe-area-context' import { @@ -20,6 +20,7 @@ import { import {useSetTitle} from '#/lib/hooks/useSetTitle' import {ComposeIcon2} from '#/lib/icons' import {CommonNavigatorParams, NativeStackScreenProps} from '#/lib/routes/types' +import {logEvent, useGate} from '#/lib/statsig/statsig' import {combinedDisplayName} from '#/lib/strings/display-names' import {cleanError} from '#/lib/strings/errors' import {isInvalidHandle} from '#/lib/strings/handles' @@ -496,6 +497,7 @@ function ProfileScreenLoaded({ accessibilityHint="" /> )} + ) } @@ -554,3 +556,77 @@ const styles = StyleSheet.create({ textAlign: 'center', }, }) + +const shouldExposeToGate2 = Math.random() < 0.2 + +// --- Temporary: we're testing our Statsig setup --- +let TestGates = React.memo(function TestGates() { + const gate = useGate() + + useEffect(() => { + logEvent('test:all:always', {}) + if (Math.random() < 0.2) { + logEvent('test:all:sometimes', {}) + } + if (Math.random() < 0.1) { + logEvent('test:all:boosted_by_gate1', { + reason: 'base', + }) + } + if (Math.random() < 0.1) { + logEvent('test:all:boosted_by_gate2', { + reason: 'base', + }) + } + if (Math.random() < 0.1) { + logEvent('test:all:boosted_by_both', { + reason: 'base', + }) + } + }, []) + + return [ + gate('test_gate_1') ? : null, + shouldExposeToGate2 && gate('test_gate_2') ? : null, + ] +}) + +function TestGate1() { + useEffect(() => { + logEvent('test:gate1:always', {}) + if (Math.random() < 0.2) { + logEvent('test:gate1:sometimes', {}) + } + if (Math.random() < 0.5) { + logEvent('test:all:boosted_by_gate1', { + reason: 'gate1', + }) + } + if (Math.random() < 0.5) { + logEvent('test:all:boosted_by_both', { + reason: 'gate1', + }) + } + }, []) + return null +} + +function TestGate2() { + useEffect(() => { + logEvent('test:gate2:always', {}) + if (Math.random() < 0.2) { + logEvent('test:gate2:sometimes', {}) + } + if (Math.random() < 0.5) { + logEvent('test:all:boosted_by_gate2', { + reason: 'gate2', + }) + } + if (Math.random() < 0.5) { + logEvent('test:all:boosted_by_both', { + reason: 'gate2', + }) + } + }, []) + return null +}