Skip to content

Commit

Permalink
Make ref_ always strings (#3583)
Browse files Browse the repository at this point in the history
* Make ref_ always strings

* Harden types
  • Loading branch information
gaearon authored Apr 16, 2024
1 parent 48bd98f commit 71c427c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/lib/statsig/statsig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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') ?? ''
Expand Down Expand Up @@ -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',
},
}
}
Expand Down

0 comments on commit 71c427c

Please sign in to comment.