[Statsig] Fix exposure logging for reduced onboarding (#4131)
* Add dangerouslyDisableExposureLogging option * Rename onboarding gate to v2 * Disable exposure logging for onboarding in PostFeed query
This commit is contained in:
		
							parent
							
								
									516eb69637
								
							
						
					
					
						commit
						4fa92d7a49
					
				
					 8 changed files with 29 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -4,7 +4,7 @@ export type Gate =
 | 
			
		|||
  | 'disable_min_shell_on_foregrounding_v3'
 | 
			
		||||
  | 'disable_poll_on_discover_v2'
 | 
			
		||||
  | 'dms'
 | 
			
		||||
  | 'reduced_onboarding_and_home_algo'
 | 
			
		||||
  | 'reduced_onboarding_and_home_algo_v2'
 | 
			
		||||
  | 'request_notifications_permission_after_onboarding'
 | 
			
		||||
  | 'show_follow_back_label_v2'
 | 
			
		||||
  | 'start_session_with_following_v2'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -108,20 +108,29 @@ export function logEvent<E extends keyof LogEvents>(
 | 
			
		|||
// Our own cache ensures consistent evaluation within a single session.
 | 
			
		||||
const GateCache = React.createContext<Map<string, boolean> | null>(null)
 | 
			
		||||
 | 
			
		||||
export function useGate(): (gateName: Gate) => boolean {
 | 
			
		||||
type GateOptions = {
 | 
			
		||||
  dangerouslyDisableExposureLogging?: boolean
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function useGate(): (gateName: Gate, options?: GateOptions) => boolean {
 | 
			
		||||
  const cache = React.useContext(GateCache)
 | 
			
		||||
  if (!cache) {
 | 
			
		||||
    throw Error('useGate() cannot be called outside StatsigProvider.')
 | 
			
		||||
  }
 | 
			
		||||
  const gate = React.useCallback(
 | 
			
		||||
    (gateName: Gate): boolean => {
 | 
			
		||||
    (gateName: Gate, options: GateOptions = {}): boolean => {
 | 
			
		||||
      const cachedValue = cache.get(gateName)
 | 
			
		||||
      if (cachedValue !== undefined) {
 | 
			
		||||
        return cachedValue
 | 
			
		||||
      }
 | 
			
		||||
      const value = Statsig.initializeCalled()
 | 
			
		||||
        ? Statsig.checkGate(gateName)
 | 
			
		||||
        : false
 | 
			
		||||
      let value = false
 | 
			
		||||
      if (Statsig.initializeCalled()) {
 | 
			
		||||
        if (options.dangerouslyDisableExposureLogging) {
 | 
			
		||||
          value = Statsig.checkGateWithExposureLoggingDisabled(gateName)
 | 
			
		||||
        } else {
 | 
			
		||||
          value = Statsig.checkGate(gateName)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      cache.set(gateName, value)
 | 
			
		||||
      return value
 | 
			
		||||
    },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue