fix build

This commit is contained in:
goenning 2023-09-01 15:55:55 +01:00
parent f6de1cd18b
commit 4b1aae55c6

View file

@ -3,8 +3,8 @@ export type AptabaseOptions = {
appVersion?: string;
};
const locale = navigator?.languages && navigator?.languages.length ? navigator?.languages[0] : navigator?.language;
const isDebug = location?.hostname === 'localhost';
const locale = getBrowserLocale();
const isDebug = getIsDebug();
let _appKey = '';
let _apiUrl = '';
@ -83,3 +83,27 @@ export function trackEvent(eventName: string, props?: Record<string, string | nu
})
.catch(console.error);
}
function getBrowserLocale(): string | null {
if (typeof navigator === 'undefined') {
return null;
}
if (navigator.languages.length > 0) {
return navigator.languages[0];
}
return navigator.language;
}
function getIsDebug(): boolean {
if (process.env.NODE_ENV === 'development') {
return true;
}
if (typeof location === 'undefined') {
return false;
}
return location.hostname === 'localhost';
}