forked from grafana/faro-web-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use correct values for
browser
meta
- Loading branch information
1 parent
0f6e372
commit f5060fc
Showing
6 changed files
with
1,054 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,21 @@ | ||
import { UAParser } from 'ua-parser-js'; | ||
// eslint-disable-next-line import/namespace | ||
import { Dimensions, Platform } from 'react-native'; | ||
import { getBrand, getModel, getReadableVersion, getSystemVersion } from 'react-native-device-info'; | ||
|
||
import { unknownString } from '@grafana/faro-core'; | ||
import type { Meta, MetaBrowser, MetaItem } from '@grafana/faro-core'; | ||
import { Meta, MetaItem } from '@grafana/faro-core'; | ||
|
||
export const browserMeta: MetaItem<Pick<Meta, 'browser'>> = () => { | ||
const parser = new UAParser(); | ||
const { name, version } = parser.getBrowser(); | ||
const { name: osName, version: osVersion } = parser.getOS(); | ||
const userAgent = parser.getUA(); | ||
const language = navigator.language; | ||
const mobile = navigator.userAgent.includes('Mobi'); | ||
const brands = getBrands(); | ||
const { width, height } = Dimensions.get('window'); | ||
|
||
return { | ||
browser: { | ||
name: name ?? unknownString, | ||
version: version ?? unknownString, | ||
os: `${osName ?? unknownString} ${osVersion ?? unknownString}`, | ||
userAgent: userAgent ?? unknownString, | ||
language: language ?? unknownString, | ||
mobile, | ||
brands: brands ?? unknownString, | ||
viewportWidth: `${window.innerWidth}`, | ||
viewportHeight: `${window.innerHeight}`, | ||
export const browserMeta: MetaItem<Pick<Meta, 'browser'>> = () => ({ | ||
browser: { | ||
name: Platform.OS, | ||
version: getReadableVersion(), | ||
os: getSystemVersion(), | ||
mobile: true, | ||
userAgent: `${Platform.OS}/${getSystemVersion()} (${getBrand()} ${getModel()})`, | ||
windowSize: { | ||
width, | ||
height, | ||
}, | ||
}; | ||
|
||
function getBrands(): MetaBrowser['brands'] | undefined { | ||
if (!name || !version) { | ||
return undefined; | ||
} | ||
|
||
if ('userAgentData' in navigator && navigator.userAgentData) { | ||
// userAgentData in experimental (only Chrome supports it) thus TS does not ship the respective type declarations | ||
return (navigator as any).userAgentData.brands; | ||
} | ||
|
||
return undefined; | ||
} | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.