|
| 1 | + |
| 2 | + |
| 3 | +# Aptabase SDK for Browser Extensions |
| 4 | + |
| 5 | +A tiny SDK (1 kB) to instrument your Browser/Chrome extensions with Aptabase, an Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps. |
| 6 | + |
| 7 | +## Install |
| 8 | + |
| 9 | +Install the SDK using npm or your preferred JavaScript package manager |
| 10 | + |
| 11 | +```bash |
| 12 | +npm add @aptabase/browser |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +First you need to get your `App Key` from Aptabase, you can find it in the `Instructions` menu on the left side menu. |
| 18 | + |
| 19 | +Initialize the SDK in your `Background Script` using your `App Key`: |
| 20 | + |
| 21 | +```js |
| 22 | +import { init } from '@aptabase/browser'; |
| 23 | + |
| 24 | +init('<YOUR_APP_KEY>'); // 👈 this is where you enter your App Key |
| 25 | +``` |
| 26 | + |
| 27 | +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. |
| 28 | + |
| 29 | +Afterwards you can start tracking events with `trackEvent` from anywhere in your extension: |
| 30 | + |
| 31 | +```js |
| 32 | +import { trackEvent } from '@aptabase/browser'; |
| 33 | + |
| 34 | +trackEvent('connect_click'); // An event with no properties |
| 35 | +trackEvent('play_music', { name: 'Here comes the sun' }); // An event with a custom property |
| 36 | +``` |
| 37 | + |
| 38 | +A few important notes: |
| 39 | + |
| 40 | +1. The SDK will automatically enhance the event with some useful information, like the OS, the app version, and other things. |
| 41 | +2. You're in control of what gets sent to Aptabase. This SDK does not automatically track any events, you need to call `trackEvent` manually. |
| 42 | + - Because of this, it's generally recommended to at least track an event at startup |
| 43 | +3. You do not need to await the `trackEvent` function, it'll run in the background. |
| 44 | +4. Only strings and numeric values are allowed on custom properties |
0 commit comments