Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clear-flowers-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'posthog-react-native': patch
---

fix: on react native running on the web should be Desktop or Mobile and not Web since its a hardware type and not platform
1 change: 1 addition & 0 deletions examples/example-expo-53/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Or...
```bash
npx expo run:ios
npx expo run:android
npx expo start --web
```

If your RN SDK changes are not picked up:
Expand Down
10 changes: 5 additions & 5 deletions examples/example-expo-53/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
},
"devDependencies": {
"@babel/cli": "^7.19.3",
"@babel/plugin-transform-class-properties": "^7.27.1",
"@babel/plugin-transform-private-methods": "^7.27.1",
"@babel/plugin-transform-private-property-in-object": "^7.27.1",
"@posthog-tooling/rollup-utils": "workspace:*",
"@posthog-tooling/tsconfig-base": "workspace:*",
Expand Down
30 changes: 29 additions & 1 deletion packages/react-native/src/native-deps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,35 @@ const getDeviceType = (): string => {
if (Platform.OS === 'macos' || Platform.OS === 'windows') {
deviceType = 'Desktop'
} else if (Platform.OS === 'web') {
deviceType = 'Web'
// Check user agent to determine if it's desktop or mobile
const ua = navigator.userAgent

// Comprehensive mobile and tablet detection based on browser package logic
const isMobileOrTablet =
// iOS devices
/iPhone|iPod|iPad/i.test(ua) ||
// Android devices - check for mobile keyword or specific tablet models
(/Android/i.test(ua) &&
(/Mobile/i.test(ua) ||
// Android tablets that don't have 'Mobile' in UA
/(9138B|TB782B|Nexus [97]|pixel c|HUAWEISHT|BTV|noble nook|smart ultra 6)/i.test(ua))) ||
// Windows Phone
/(Windows Phone|WPDesktop|IEMobile)/i.test(ua) ||
// BlackBerry
/(BlackBerry|PlayBook|BB10)/i.test(ua) ||
// Other mobile browsers and devices
/webOS|Opera Mini|UCWEB|UCBrowser/i.test(ua) ||
// Kindle devices
/(kf[a-z]{2}wi|aeo[c-r]{2})( bui|\))/i.test(ua) ||
/(kf[a-z]+)( bui|\)).+silk\//i.test(ua) ||
// Generic mobile/tablet keywords
/(Mobile|Tablet|pda)/i.test(ua) ||
// Nokia
/Nokia/i.test(ua) ||
// Kobo e-readers
/(kobo)\s(ereader|touch)/i.test(ua)

deviceType = isMobileOrTablet ? 'Mobile' : 'Desktop'
}
return deviceType
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/posthog-rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface PostHogOptions extends PostHogCoreOptions {
* - $app_namespace: App bundle identifier / namespace
* - $os_name: Operating system name
* - $os_version: Operating system version
* - $device_type: Device type (Mobile, Desktop, Web)
* - $device_type: Device type (Mobile, Desktop)
* - $lib: Name of the SDK library
* - $lib_version: Version of the SDK library
*
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface PostHogCustomAppProperties {
$device_name?: string | null
/** Model identifier like "iPhone13,2" or "SM-S921B" */
$device_model?: string | null
/** Device type ("Mobile" | "Desktop" | "Web") */
/** Device type ("Mobile" | "Desktop") */
$device_type?: string | null
/** Operating system name like iOS or Android */
$os_name?: string | null
Expand Down
19 changes: 7 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading