about summary refs log tree commit diff
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-04-16 21:55:12 +0100
committerGitHub <noreply@github.com>2024-04-16 21:55:12 +0100
commit71c427cea86db31f7bd6c11cd460c0d7a48c0b06 (patch)
tree81b0b22098882eab2408e38bb78cfcfb62f229d6
parent48bd98f9ef1425a0642e8373af2afab857ded28e (diff)
downloadvoidsky-71c427cea86db31f7bd6c11cd460c0d7a48c0b06.tar.zst
Make ref_ always strings (#3583)
* Make ref_ always strings

* Harden types
-rw-r--r--src/lib/statsig/statsig.tsx24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx
index 6fa476cd0..df540d79e 100644
--- a/src/lib/statsig/statsig.tsx
+++ b/src/lib/statsig/statsig.tsx
@@ -15,8 +15,21 @@ import {useSession} from '../../state/session'
 import {LogEvents} from './events'
 import {Gate} from './gates'
 
-let refSrc: string
-let refUrl: string
+type StatsigUser = {
+  userID: string | undefined
+  // TODO: Remove when enough users have custom.platform:
+  platform: 'ios' | 'android' | 'web'
+  custom: {
+    // This is the place where we can add our own stuff.
+    // Fields here have to be non-optional to be visible in the UI.
+    platform: 'ios' | 'android' | 'web'
+    refSrc: string
+    refUrl: string
+  }
+}
+
+let refSrc = ''
+let refUrl = ''
 if (isWeb && typeof window !== 'undefined') {
   const params = new URLSearchParams(window.location.search)
   refSrc = params.get('ref_src') ?? ''
@@ -97,19 +110,18 @@ export function useGate(gateName: Gate): boolean {
   return initialValue
 }
 
-function toStatsigUser(did: string | undefined) {
+function toStatsigUser(did: string | undefined): StatsigUser {
   let userID: string | undefined
   if (did) {
     userID = sha256(did)
   }
   return {
     userID,
-    platform: Platform.OS,
+    platform: Platform.OS as 'ios' | 'android' | 'web',
     custom: {
       refSrc,
       refUrl,
-      // Need to specify here too for gating.
-      platform: Platform.OS,
+      platform: Platform.OS as 'ios' | 'android' | 'web',
     },
   }
 }