Support for custom API path

This commit is contained in:
goenning 2023-12-29 09:22:45 -03:00
parent 348898fc82
commit c980afd786
7 changed files with 34 additions and 17 deletions

View file

@ -1,3 +1,7 @@
## 0.4.1
- Support for custom API path
## 0.4.0
- Internal refactor

View file

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

View file

@ -1,10 +1,11 @@
import { inMemorySessionId, sendEvent, validateAppKey, type AptabaseOptions } from '../../shared';
import { getApiUrl, inMemorySessionId, sendEvent, validateAppKey, type AptabaseOptions } from '../../shared';
// Session expires after 1 hour of inactivity
const SESSION_TIMEOUT = 1 * 60 * 60;
const sdkVersion = `aptabase-web@${process.env.PKG_VERSION}`;
let _appKey = '';
let _apiUrl: string | undefined;
let _options: AptabaseOptions | undefined;
export { type AptabaseOptions };
@ -12,14 +13,18 @@ export { type AptabaseOptions };
export function init(appKey: string, options?: AptabaseOptions) {
if (!validateAppKey(appKey)) return;
_apiUrl = getApiUrl(appKey, options);
_appKey = appKey;
_options = options;
}
export async function trackEvent(eventName: string, props?: Record<string, string | number | boolean>): Promise<void> {
if (!_apiUrl) return;
const sessionId = inMemorySessionId(SESSION_TIMEOUT);
await sendEvent({
apiUrl: _apiUrl,
sessionId,
appKey: _appKey,
isDebug: _options?.isDebug,