diff --git a/packages/browser/CHANGELOG.md b/packages/browser/CHANGELOG.md index 7cefc44..e43c092 100644 --- a/packages/browser/CHANGELOG.md +++ b/packages/browser/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.1 + +- Support for custom API path +- use `installType` to determine if the extension is in debug mode + ## 0.1.0 - Initial version of the Aptabase SDK for Browser Extensions diff --git a/packages/browser/README.md b/packages/browser/README.md index f793e3c..9c11dbf 100644 --- a/packages/browser/README.md +++ b/packages/browser/README.md @@ -24,7 +24,7 @@ import { init } from '@aptabase/browser'; init(''); // 👈 this is where you enter your App Key ``` -The init function also supports an optional second parameter, which is an object with the `isDebug` property. Your data is seggregated between development and production environments, so it's important to set this value correctly. By default the SDK will use the `NODE_ENV` environment variable to determine if it's in development or production mode, which is only available in bundlers like Webpack, Rollup, etc. If you're not using a bundler, you can pass in the `isDebug` property manually. +The `init` function also supports an optional second parameter, which is an object with the `isDebug`property. Your data is segregated between development and production environments, so it's important to set this value correctly. By default the SDK will check if the extension was installed from an Extension Store, and if it wasn't it'll assume it's in development mode. If you want to override this behavior, you can set the`isDebug` property. Afterwards you can start tracking events with `trackEvent` from anywhere in your extension: diff --git a/packages/browser/package.json b/packages/browser/package.json index eda6b9c..45ea55a 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -1,6 +1,6 @@ { "name": "@aptabase/browser", - "version": "0.1.0", + "version": "0.1.1", "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", diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index a45f9d1..1bb9a7d 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -1,4 +1,4 @@ -import { newSessionId, sendEvent, validateAppKey, type AptabaseOptions } from '../../shared'; +import { getApiUrl, newSessionId, sendEvent, validateAppKey, type AptabaseOptions } from '../../shared'; // Session expires after 1 hour of inactivity const SESSION_TIMEOUT = 1 * 60 * 60; @@ -6,6 +6,7 @@ const sdkVersion = `aptabase-browser@${process.env.PKG_VERSION}`; const isWebContext = 'document' in globalThis; let _appKey = ''; +let _apiUrl: string | undefined; let _options: AptabaseOptions | undefined; globalThis.aptabase = { @@ -13,7 +14,7 @@ globalThis.aptabase = { trackEvent, }; -export function init(appKey: string, options?: AptabaseOptions) { +export async function init(appKey: string, options?: AptabaseOptions): Promise { if (isWebContext) { console.error('@aptabase/browser can only be initialized in your background script.'); return; @@ -21,8 +22,14 @@ export function init(appKey: string, options?: AptabaseOptions) { if (!validateAppKey(appKey)) return; + const ext = await chrome.management.getSelf(); + + const isDebug = options?.isDebug ?? ext.installType === 'development'; + const appVersion = options?.appVersion ?? chrome.runtime.getManifest().version; + + _apiUrl = options?.apiUrl ?? getApiUrl(appKey, options); _appKey = appKey; - _options = { ...options, appVersion: options?.appVersion ?? chrome.runtime.getManifest().version }; + _options = { ...options, isDebug, appVersion }; chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message && message.type === '__aptabase__trackEvent') { @@ -36,9 +43,11 @@ export async function trackEvent(eventName: string, props?: Record