Skip to main content

Client API

All methods on ISunglassesClient (returned by SunglassesCore.create()).

Event tracking​

client.capture(eventName, properties?, options?)
client.screen(screenName, properties?)
client.identify(userId, traits?)
client.alias(newId, existingId)
client.group(groupId, traits?)

Super properties​

client.register({ experiment_group: 'A' })
client.unregister('experiment_group')
client.getRegisteredProperties()

App metadata​

client.setEnvironment('production')
client.setAppUpdate({ id, channel, embedded })
client.setFeatures(['new-onboarding'])
client.setEntitlements(['premium'])
client.setAppMetadata({ environment, features })
client.getAppMetadata()
client.optIn()
client.optOut()
client.getConsentStatus() // 'opted-in' | 'opted-out' | 'unknown'
client.getConsentHistory()

Identity​

client.reset() // Clear identity + queue + session

GDPR​

client.exportUserData()
client.deleteUserData({ resetConsent? })
client.clearLocalArchive({ maxAgeMs? })

Lifecycle​

client.flush() // Force-send queued events
client.shutdown() // Flush + stop timers (call on unmount)

Diagnostics​

client.getQueuedEventCount()
client.getEventCount(name, period, date?) // requires enableEventCounting
client.resetEventCount(name)
client.eventCounter // EventCounter instance (if enabled)

React hooks​

HookPackagePurpose
useSunglasses()react, react-nativeAccess client from context
useCapture()reactTyped capture helper
useConsentStatus()reactReactive consent state
useScreenTracking()reactHistory API screen tracking
useExpoRouterScreenTracking()react-nativeExpo Router screens
useNavigationScreenTracking()react-nativeReact Navigation screens
useExpoRouterUtmCapture()react-nativeUTM from Expo Router
useLinkingUtmCapture()react-nativeUTM from Linking API

Components​

ComponentPackagePurpose
SunglassesProviderreact, react-nativeContext + optional tracking
SunglassesErrorBoundaryreact, react-nativeRender error capture