Device manager - UA parsing tweaks (#9382)
* parseUA - use full client version * dont check for custom element model and os when device type is unknown * ignore OS version in browser based sessions
This commit is contained in:
parent
66a9636ec5
commit
4a98e26c4a
2 changed files with 34 additions and 20 deletions
|
@ -58,15 +58,16 @@ const getDeviceType = (
|
|||
return DeviceType.Unknown;
|
||||
};
|
||||
|
||||
interface CustomValues {
|
||||
customDeviceModel?: string;
|
||||
customDeviceOS?: string;
|
||||
}
|
||||
/**
|
||||
* Some mobile model and OS strings are not recognised
|
||||
* by the UA parsing library
|
||||
* check they exist by hand
|
||||
*/
|
||||
const checkForCustomValues = (userAgent: string): {
|
||||
customDeviceModel?: string;
|
||||
customDeviceOS?: string;
|
||||
} => {
|
||||
const checkForCustomValues = (userAgent: string): CustomValues => {
|
||||
if (userAgent.includes(BROWSER_KEYWORD)) {
|
||||
return {};
|
||||
}
|
||||
|
@ -97,13 +98,23 @@ export const parseUserAgent = (userAgent?: string): ExtendedDeviceInformation =>
|
|||
const device = parser.getDevice();
|
||||
const operatingSystem = parser.getOS();
|
||||
|
||||
const deviceOperatingSystem = concatenateNameAndVersion(operatingSystem.name, operatingSystem.version);
|
||||
const deviceModel = concatenateNameAndVersion(device.vendor, device.model);
|
||||
const client = concatenateNameAndVersion(browser.name, browser.major || browser.version);
|
||||
|
||||
const { customDeviceModel, customDeviceOS } = checkForCustomValues(userAgent);
|
||||
const deviceType = getDeviceType(userAgent, device, browser, operatingSystem);
|
||||
|
||||
// OSX versions are frozen at 10.15.17 in UA strings https://chromestatus.com/feature/5452592194781184
|
||||
// ignore OS version in browser based sessions
|
||||
const shouldIgnoreOSVersion = deviceType === DeviceType.Web || deviceType === DeviceType.Desktop;
|
||||
const deviceOperatingSystem = concatenateNameAndVersion(
|
||||
operatingSystem.name,
|
||||
shouldIgnoreOSVersion ? undefined : operatingSystem.version,
|
||||
);
|
||||
const deviceModel = concatenateNameAndVersion(device.vendor, device.model);
|
||||
const client = concatenateNameAndVersion(browser.name, browser.version);
|
||||
|
||||
// only try to parse custom model and OS when device type is known
|
||||
const { customDeviceModel, customDeviceOS } = deviceType !== DeviceType.Unknown
|
||||
? checkForCustomValues(userAgent)
|
||||
: {} as CustomValues;
|
||||
|
||||
return {
|
||||
deviceType,
|
||||
deviceModel: deviceModel || customDeviceModel,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue