Getting Android Platform Info

Google has started reducing the amount of information available in the userAgent string. The first impact of this is the loss of Android device, platform, and version information. If your application has a lot of variability here, it might be important for you to continue to have this data.

To make this information available, you need to allow it with some additional HTTP Headers from your hosting platform. Then, you’ll need to get the new client-hints and patch them onto the userAgent string.

Add User-Agent Client Hint Headers

You’ll need to serve your pages with the Accept-CH header to allow the Platform version to be exposed:

Accept-CH: Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, Sec-CH-UA-Model
HTTP Header to expose client hints

Retrofill the navigator.userAgent string

The TrackJS agent has not switch to the new Client Hints API yet, so you need to polyfill the navigator.userAgent string. We recommend doing this with the UACH Retrofill Library from Google.

Once included, call overrideUserAgentUsingClientHints(["uaFullVersion"]); as early as possible in your code. Here is a more-complete example:

import { TrackJS } from 'trackjs';
import { overrideUserAgentUsingClientHints } from './uach-retrofill.js';

overrideUserAgentUsingClientHints(["uaFullVersion"]);

TrackJS.install({...});
HTTP Header to expose client hints