Refactor platform properties loading

This commit is contained in:
James Salter 2021-07-21 18:35:25 +01:00
parent 585b702652
commit c34afdb4bd
3 changed files with 36 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import posthog, { PostHog } from 'posthog-js';
import PlatformPeg from './PlatformPeg';
import SdkConfig from './SdkConfig';
interface IEvent {
@ -226,6 +227,22 @@ export class PosthogAnalytics {
}
}
export async function getPlatformProperties() {
const platform = PlatformPeg.get();
let appVersion;
try {
appVersion = await platform.getAppVersion();
} catch (e) {
// this happens if no version is set i.e. in dev
appVersion = "unknown";
}
return {
appVersion,
appPlatform: platform.getHumanReadableName(),
};
}
export function getAnalytics(): PosthogAnalytics {
return PosthogAnalytics.instance();
}