Merge pull request #8 from ngregrichardson/fix/ssr-imports

fix: read browser locale and is debug on first event
This commit is contained in:
Bogdan Ivanov 2024-07-19 22:49:07 +03:00 committed by GitHub
commit f40989bc42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 40 additions and 14 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@aptabase/angular",
"version": "0.0.1",
"version": "0.0.2",
"description": "Angular SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"scripts": {
"ng": "ng",

View file

@ -1,3 +1,7 @@
## 0.1.2
- Move browser locale and is debug reads from import to first event to better support SSR
## 0.1.1
- Support for custom API path

View file

@ -1,6 +1,6 @@
{
"name": "@aptabase/browser",
"version": "0.1.1",
"version": "0.1.2",
"type": "module",
"description": "Browser Extension SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"main": "./dist/index.cjs",

View file

@ -1,3 +1,7 @@
## 0.3.4
- Move browser locale and is debug reads from import to first event to better support SSR
## 0.3.3
- Rename `apiPath` to `apiUrl`

View file

@ -1,6 +1,6 @@
{
"name": "@aptabase/react",
"version": "0.3.3",
"version": "0.3.4",
"type": "module",
"description": "React SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"main": "./dist/index.cjs",

View file

@ -1,5 +1,5 @@
const defaultLocale = getBrowserLocale();
const defaultIsDebug = getIsDebug();
let defaultLocale: string | undefined;
let defaultIsDebug: boolean | undefined;
const isInBrowser = typeof window !== 'undefined' && typeof window.fetch !== 'undefined';
const isInBrowserExtension = typeof chrome !== 'undefined' && !!chrome.runtime?.id;
@ -103,8 +103,8 @@ export async function sendEvent(opts: {
sessionId: opts.sessionId,
eventName: opts.eventName,
systemProps: {
locale: opts.locale ?? defaultLocale,
isDebug: opts.isDebug ?? defaultIsDebug,
locale: opts.locale ?? getBrowserLocale(),
isDebug: opts.isDebug ?? getIsDebug(),
appVersion: opts.appVersion ?? '',
sdkVersion: opts.sdkVersion,
},
@ -123,25 +123,39 @@ export async function sendEvent(opts: {
}
function getBrowserLocale(): string | undefined {
if (defaultLocale) {
return defaultLocale;
}
if (typeof navigator === 'undefined') {
return undefined;
}
if (navigator.languages.length > 0) {
return navigator.languages[0];
defaultLocale = navigator.languages[0];
} else {
defaultLocale = navigator.language;
}
return navigator.language;
return defaultLocale;
}
function getIsDebug(): boolean {
if (defaultIsDebug !== undefined) {
return defaultIsDebug;
}
if (process.env['NODE_ENV'] === 'development') {
return true;
defaultIsDebug = true;
return defaultIsDebug;
}
if (typeof location === 'undefined') {
return false;
defaultIsDebug = false;
return defaultIsDebug;
}
return location.hostname === 'localhost';
}
defaultIsDebug = location.hostname === 'localhost';
return defaultIsDebug;
}

View file

@ -1,3 +1,7 @@
## 0.4.3
- Move browser locale and is debug reads from import to first event to better support SSR
## 0.4.2
- Fix error when running on chrome

View file

@ -1,6 +1,6 @@
{
"name": "@aptabase/web",
"version": "0.4.2",
"version": "0.4.3",
"type": "module",
"description": "JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"main": "./dist/index.cjs",