From fd04d2fc964d66f32e2ae071ebe851f86bff0b30 Mon Sep 17 00:00:00 2001 From: goenning Date: Tue, 18 Jul 2023 15:16:26 +0100 Subject: [PATCH] set appVersion during init --- CHANGELOG.md | 4 ++++ README.md | 8 +++----- package.json | 2 +- src/index.ts | 21 +++++++++++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ee4194..29cf29d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.2 + +Added an option to set the appVersion during init + ## 0.1.1 Fixed some links on package.json diff --git a/README.md b/README.md index 39f9d54..097a265 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,10 @@ Instrument your React Native or Expo apps with Aptabase, an Open Source, Privacy ## Install -Install the SDK using your preferred JavaScript package manager +Install the SDK using `npm` or your preferred JavaScript package manager ```bash -pnpm add @aptabase/react-native -# or npm add @aptabase/react-native -# or -yarn add @aptabase/react-native ``` ## Usage @@ -37,6 +33,8 @@ trackEvent("connect_click"); // An event with no properties trackEvent("play_music", { name: "Here comes the sun" }); // An event with a custom property ``` +**Note for Expo apps:** Events sent during development while running on Expo Go will not have the `App Version` property because native modules are not available in Expo Go. However, when you build your app and run it on a real device, the `App Version` property will be available. Alternative, you can also set the `appVersion` during the `init` call so that it's available during development as well. + A few important notes: 1. The SDK will automatically enhance the event with some useful information, like the OS, the app version, and other things. diff --git a/package.json b/package.json index 16076df..7c31885 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aptabase/react-native", - "version": "0.1.1", + "version": "0.1.2", "private": false, "description": "React Native SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps", "sideEffects": false, diff --git a/src/index.ts b/src/index.ts index 5970368..3cb0717 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,15 @@ import { newSessionId } from "./session"; import { EnvironmentInfo, getEnvironmentInfo } from "./env"; import { Platform } from "react-native"; +/** + * Custom initialization parameters for Aptabase SDK. + * Use this when calling the init function. + */ export type AptabaseOptions = { + // Host URL for Self-Hosted deployments host?: string; + + // Custom appVersion to override the default appVersion?: string; }; @@ -39,6 +46,11 @@ function getBaseUrl( return _hosts[region]; } +/** + * Initializes the SDK with given App Key + * @param {string} appKey - Aptabase App Key + * @param {AptabaseOptions} options - Optional initialization parameters + */ export function init(appKey: string, options?: AptabaseOptions) { _appKey = appKey; @@ -61,8 +73,17 @@ export function init(appKey: string, options?: AptabaseOptions) { const baseUrl = getBaseUrl(parts[1], options); _apiUrl = `${baseUrl}/api/v0/event`; _env = getEnvironmentInfo(); + + if (options?.appVersion) { + _env.appVersion = options.appVersion; + } } +/** + * Track an event using given properties + * @param {string} eventName - The name of the event to track + * @param {Object} props - Optional custom properties + */ export function trackEvent( eventName: string, props?: Record