Added an option to specify isDebug at init time

This commit is contained in:
goenning 2023-10-20 09:08:19 +01:00
parent 2aaf2e8c1e
commit 53f0f40aa1
6 changed files with 22 additions and 13 deletions

6
package-lock.json generated
View file

@ -13333,10 +13333,10 @@
}, },
"packages/react": { "packages/react": {
"name": "@aptabase/react", "name": "@aptabase/react",
"version": "0.1.2", "version": "0.2.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@aptabase/web": "0.2.0" "@aptabase/web": "0.3.0"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^18.0.0" "react": "^18.0.0"
@ -13344,7 +13344,7 @@
}, },
"packages/web": { "packages/web": {
"name": "@aptabase/web", "name": "@aptabase/web",
"version": "0.2.0", "version": "0.3.0",
"license": "MIT" "license": "MIT"
} }
} }

View file

@ -1,3 +1,7 @@
## 0.2.0
- Updated dependencies
## 0.1.2 ## 0.1.2
- Fixed an issue with client-side checking - Fixed an issue with client-side checking

View file

@ -1,6 +1,6 @@
{ {
"name": "@aptabase/react", "name": "@aptabase/react",
"version": "0.1.2", "version": "0.2.0",
"type": "module", "type": "module",
"description": "React SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps", "description": "React SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"main": "./dist/index.cjs", "main": "./dist/index.cjs",
@ -34,7 +34,7 @@
"package.json" "package.json"
], ],
"dependencies": { "dependencies": {
"@aptabase/web": "0.2.0" "@aptabase/web": "0.3.0"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^18.0.0" "react": "^18.0.0"

View file

@ -1,3 +1,7 @@
## 0.3.0
- Added an option to specify `isDebug` at init time
## 0.2.0 ## 0.2.0
- Some internal refactor to support the new `@aptabase/react` package - Some internal refactor to support the new `@aptabase/react` package

View file

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

View file

@ -3,10 +3,10 @@ import { newSessionId } from './session';
export type AptabaseOptions = { export type AptabaseOptions = {
host?: string; host?: string;
appVersion?: string; appVersion?: string;
isDebug?: boolean;
}; };
const locale = getBrowserLocale(); const locale = getBrowserLocale();
const isDebug = getIsDebug();
// Session expires after 1 hour of inactivity // Session expires after 1 hour of inactivity
const SESSION_TIMEOUT = 1 * 60 * 60; const SESSION_TIMEOUT = 1 * 60 * 60;
@ -14,7 +14,8 @@ let _sessionId = newSessionId();
let _lastTouched = new Date(); let _lastTouched = new Date();
let _appKey = ''; let _appKey = '';
let _apiUrl = ''; let _apiUrl = '';
let _options: AptabaseOptions | undefined; let _isDebug = false;
let _appVersion = '';
const _hosts: { [region: string]: string } = { const _hosts: { [region: string]: string } = {
US: 'https://us.aptabase.com', US: 'https://us.aptabase.com',
@ -24,9 +25,6 @@ const _hosts: { [region: string]: string } = {
}; };
export function init(appKey: string, options?: AptabaseOptions) { export function init(appKey: string, options?: AptabaseOptions) {
_appKey = appKey;
_options = options;
const parts = appKey.split('-'); const parts = appKey.split('-');
if (parts.length !== 3 || _hosts[parts[1]] === undefined) { if (parts.length !== 3 || _hosts[parts[1]] === undefined) {
console.warn(`The Aptabase App Key "${appKey}" is invalid. Tracking will be disabled.`); console.warn(`The Aptabase App Key "${appKey}" is invalid. Tracking will be disabled.`);
@ -35,6 +33,9 @@ export function init(appKey: string, options?: AptabaseOptions) {
const baseUrl = getBaseUrl(parts[1], options); const baseUrl = getBaseUrl(parts[1], options);
_apiUrl = `${baseUrl}/api/v0/event`; _apiUrl = `${baseUrl}/api/v0/event`;
_appKey = appKey;
_isDebug = options?.isDebug ?? getIsDebug();
_appVersion = options?.appVersion ?? '';
} }
export async function trackEvent(eventName: string, props?: Record<string, string | number | boolean>): Promise<void> { export async function trackEvent(eventName: string, props?: Record<string, string | number | boolean>): Promise<void> {
@ -66,9 +67,9 @@ export async function trackEvent(eventName: string, props?: Record<string, strin
sessionId: _sessionId, sessionId: _sessionId,
eventName: eventName, eventName: eventName,
systemProps: { systemProps: {
isDebug,
locale, locale,
appVersion: _options?.appVersion ?? '', isDebug: _isDebug,
appVersion: _appVersion,
sdkVersion: globalThis.__APTABASE_SDK_VERSION__ ?? `aptabase-web@${process.env.PKG_VERSION}`, sdkVersion: globalThis.__APTABASE_SDK_VERSION__ ?? `aptabase-web@${process.env.PKG_VERSION}`,
}, },
props: props, props: props,