Skip to content

Commit

Permalink
fix: if react-native-device-info is available for the Web target, do …
Browse files Browse the repository at this point in the history
…not set unknown for all properties (#157)
marandaneto authored Jan 22, 2024
1 parent a037210 commit 50f681d
Showing 4 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions posthog-react-native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Next

1. if `react-native-device-info` is available for the Web target, do not set `unknown` for all properties.

# 2.10.1 - 2024-01-15

1. The `tag_name` property of auto-captured events now uses the nearest `ph-label` from parent elements, if present.
24 changes: 16 additions & 8 deletions posthog-react-native/src/native-deps.tsx
Original file line number Diff line number Diff line change
@@ -40,19 +40,27 @@ export const getAppProperties = (): PostHogCustomAppProperties => {
}

if (OptionalReactNativeDeviceInfo) {
properties.$app_build = OptionalReactNativeDeviceInfo.getBuildIdSync()
properties.$app_name = OptionalReactNativeDeviceInfo.getApplicationName()
properties.$app_namespace = OptionalReactNativeDeviceInfo.getBundleId()
properties.$app_version = OptionalReactNativeDeviceInfo.getVersion()
properties.$device_manufacturer = OptionalReactNativeDeviceInfo.getManufacturerSync()
properties.$device_name = OptionalReactNativeDeviceInfo.getDeviceNameSync()
properties.$os_name = OptionalReactNativeDeviceInfo.getSystemName()
properties.$os_version = OptionalReactNativeDeviceInfo.getSystemVersion()
properties.$app_build = returnPropertyIfNotUnknown(OptionalReactNativeDeviceInfo.getBuildIdSync())
properties.$app_name = returnPropertyIfNotUnknown(OptionalReactNativeDeviceInfo.getApplicationName())
properties.$app_namespace = returnPropertyIfNotUnknown(OptionalReactNativeDeviceInfo.getBundleId())
properties.$app_version = returnPropertyIfNotUnknown(OptionalReactNativeDeviceInfo.getVersion())
properties.$device_manufacturer = returnPropertyIfNotUnknown(OptionalReactNativeDeviceInfo.getManufacturerSync())
properties.$device_name = returnPropertyIfNotUnknown(OptionalReactNativeDeviceInfo.getDeviceNameSync())
properties.$os_name = returnPropertyIfNotUnknown(OptionalReactNativeDeviceInfo.getSystemName())
properties.$os_version = returnPropertyIfNotUnknown(OptionalReactNativeDeviceInfo.getSystemVersion())
}

return properties
}

// react-native-device-info returns 'unknown' if the property is not available (Web target)
const returnPropertyIfNotUnknown = (value: string | null): string | null => {
if (value !== 'unknown') {
return value
}
return null
}

export const buildOptimisiticAsyncStorage = (): PostHogCustomAsyncStorage => {
if (OptionalExpoFileSystem) {
const filesystem = OptionalExpoFileSystem
Original file line number Diff line number Diff line change
@@ -3,5 +3,5 @@ import type ExpoFileSystem from 'expo-file-system'
export let OptionalExpoFileSystem: typeof ExpoFileSystem | undefined = undefined

try {
OptionalExpoFileSystem = require('expo-file-system')
OptionalExpoFileSystem = require('expo-file-system') // No Web support
} catch (e) {}
Original file line number Diff line number Diff line change
@@ -3,5 +3,5 @@ import type ReactNativeDeviceInfo from 'react-native-device-info'
export let OptionalReactNativeDeviceInfo: typeof ReactNativeDeviceInfo | undefined = undefined

try {
OptionalReactNativeDeviceInfo = require('react-native-device-info')
OptionalReactNativeDeviceInfo = require('react-native-device-info') // No Web support
} catch (e) {}

0 comments on commit 50f681d

Please sign in to comment.