···001import {GrowthBook} from '@growthbook/growthbook-react'
23-import {type Metadata} from '#/analytics/metadata'
4import * as env from '#/env'
56export {Features} from '#/analytics/features/types'
0000000000000078/**
9 * We vary the amount of time we wait for GrowthBook to fetch feature
···46}
4748/**
49- * Converts our metadata into GrowthBook attributes and sets them.
00050 */
51-export function setAttributes({base, session, preferences}: Metadata) {
52- const {deviceId, sessionId, ...br} = base
000053 features.setAttributes({
54- device_id: deviceId, // GrowthBook special field
55- session_id: sessionId, // GrowthBook special field
56- user_id: session?.did, // GrowthBook special field
57- id: session?.did, // GrowthBook special field
58- ...br,
59- ...(session || {}),
60- ...(preferences || {}),
000061 })
62}
···1+import {MMKV} from '@bsky.app/react-native-mmkv'
2+import {setPolyfills} from '@growthbook/growthbook'
3import {GrowthBook} from '@growthbook/growthbook-react'
45+import {getNavigationMetadata, type Metadata} from '#/analytics/metadata'
6import * as env from '#/env'
78export {Features} from '#/analytics/features/types'
9+10+const CACHE = new MMKV({id: 'bsky_features_cache'})
11+12+setPolyfills({
13+ localStorage: {
14+ getItem: key => {
15+ const value = CACHE.getString(key)
16+ return value != null ? JSON.parse(value) : null
17+ },
18+ setItem: async (key, value) => {
19+ CACHE.set(key, JSON.stringify(value))
20+ },
21+ },
22+})
2324/**
25 * We vary the amount of time we wait for GrowthBook to fetch feature
···62}
6364/**
65+ * Converts our metadata into GrowthBook attributes and sets them. GrowthBook
66+ * attributes are manually configured in the GrowthBook dashboard. So these
67+ * values need to match exactly. Therefore, let's add them here manually to and
68+ * not spread them to avoid mistakes.
69 */
70+export function setAttributes({
71+ base,
72+ geolocation,
73+ session,
74+ preferences,
75+}: Metadata) {
76 features.setAttributes({
77+ deviceId: base.deviceId,
78+ sessionId: base.sessionId,
79+ platform: base.platform,
80+ appVersion: base.appVersion,
81+ countryCode: geolocation.countryCode,
82+ regionCode: geolocation.regionCode,
83+ did: session?.did,
84+ isBskyPds: session?.isBskyPds,
85+ appLanguage: preferences?.appLanguage,
86+ contentLanguages: preferences?.contentLanguages,
87+ currentScreen: getNavigationMetadata()?.currentScreen,
88 })
89}
···16 useSessionId,
17} from '#/analytics/identifiers'
18import {
019 getNavigationMetadata,
20 type MergeableMetadata,
21 type Metadata,
22} from '#/analytics/metadata'
23import {type Metrics, metrics} from '#/analytics/metrics'
24import * as refParams from '#/analytics/misc/refParams'
25-import {getMetadataForLogger} from '#/analytics/utils'
26import * as env from '#/env'
27import {useGeolocation} from '#/geolocation'
28import {device} from '#/storage'
···16 useSessionId,
17} from '#/analytics/identifiers'
18import {
19+ getMetadataForLogger,
20 getNavigationMetadata,
21 type MergeableMetadata,
22 type Metadata,
23} from '#/analytics/metadata'
24import {type Metrics, metrics} from '#/analytics/metrics'
25import * as refParams from '#/analytics/misc/refParams'
026import * as env from '#/env'
27import {useGeolocation} from '#/geolocation'
28import {device} from '#/storage'