Skip to content

Commit

Permalink
set appVersion during init
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Jul 18, 2023
1 parent cf16a91 commit fd04d2f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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;

Expand All @@ -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<string, string | number | boolean>
Expand Down

0 comments on commit fd04d2f

Please sign in to comment.