import { PathmapNative, type NativeOptions } from '@pathmap/native'; import * as Crypto from 'expo-crypto'; import { Platform } from 'react-native'; import Storage from 'expo-sqlite/kv-store'; function nativePlatform() { if (Platform.OS !== 'android' && Platform.OS !== 'ios') throw new Error('Use the browser SDK for web.'); return Platform.OS === 'ios' ? 'iOS' : 'Android'; } export function expoAnalyticsStorage(options: Pick): NativeOptions['storage'] { const namespace = ['pathmap', options.siteId, nativePlatform(), options.appId, options.testToken ?? 'production'].join('.'); return { read: () => Storage.getItem(namespace), write: value => Storage.setItem(namespace, value), clear: () => Storage.removeItem(namespace), }; } export function expoAnalytics(options: Omit) { return new PathmapNative({ ...options, platform: nativePlatform(), uuid: Crypto.randomUUID, storage: expoAnalyticsStorage(options) }); }