Skip to content
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

[Statsig] Add test gates and events #3659

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib/statsig/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ export type LogEvents = {
| 'ProfileMenu'
| 'ProfileHoverCard'
}

'test:all:always': {}
'test:all:sometimes': {}
'test:all:boosted_by_gate1': {reason: 'base' | 'gate1' | 'gate2'}
'test:all:boosted_by_gate2': {reason: 'base' | 'gate1' | 'gate2'}
'test:all:boosted_by_both': {reason: 'base' | 'gate1' | 'gate2'}
'test:gate1:always': {}
'test:gate1:sometimes': {}
'test:gate2:always': {}
'test:gate2:sometimes': {}
}
2 changes: 2 additions & 0 deletions src/lib/statsig/gates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export type Gate =
| 'hide_vertical_scroll_indicators'
| 'show_follow_back_label_v2'
| 'start_session_with_following_v2'
| 'test_gate_1'
| 'test_gate_2'
| 'use_new_suggestions_endpoint'
78 changes: 77 additions & 1 deletion src/view/screens/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useMemo} from 'react'
import React, {useEffect, useMemo} from 'react'
import {StyleSheet} from 'react-native'
import {
AppBskyActorDefs,
Expand All @@ -11,6 +11,7 @@ import {useLingui} from '@lingui/react'
import {useFocusEffect} from '@react-navigation/native'
import {useQueryClient} from '@tanstack/react-query'

import {logEvent, useGate} from '#/lib/statsig/statsig'
import {cleanError} from '#/lib/strings/errors'
import {useProfileShadow} from '#/state/cache/profile-shadow'
import {useLabelerInfoQuery} from '#/state/queries/labeler'
Expand Down Expand Up @@ -465,6 +466,7 @@ function ProfileScreenLoaded({
accessibilityHint=""
/>
)}
<TestGates />
</ScreenHider>
)
}
Expand Down Expand Up @@ -522,3 +524,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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always fires. Baseline.

logEvent('test:all:sometimes', {})
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also baseline, but fires less often.

if (Math.random() < 0.1) {
logEvent('test:all:boosted_by_gate1', {
reason: 'base',
})
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't fire as much... unless you're in gate 1 (see below).

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') ? <TestGate1 /> : null,
shouldExposeToGate2 && gate('test_gate_2') ? <TestGate2 /> : null,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expose everyone to this GK.

]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expose a smaller % to this gate (note separate sessions increase the probability of exposure because Math.random for shouldExposeToGate2 is at module level)

})

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',
})
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sure we hit more of these under the first gate.

if (Math.random() < 0.5) {
logEvent('test:all:boosted_by_both', {
reason: 'gate1',
})
}
}, [])
return null
}

function TestGate2() {
useEffect(() => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same but for the other gate.

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',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both gates boost this one, but neither does it better.

})
}
}, [])
return null
}
Loading