From 21e51c02cda9fb20c1ca0779eeb97aa505801afd Mon Sep 17 00:00:00 2001 From: goenning Date: Fri, 29 Sep 2023 10:45:42 +0100 Subject: [PATCH] Added a warning log when trackEvent is called with invalid parameters --- CHANGELOG.md | 4 ++++ README.md | 2 +- package.json | 2 +- src/track.ts | 10 ++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0697206..3eed62b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.2 + +- Added a warning log when trackEvent is called with invalid parameters + ## 0.3.1 - Fixed an issue where the `appBuildNumber` would sometimes be sent as a number instead of a string diff --git a/README.md b/README.md index a04c8ea..7ba8cf5 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ export function Counter() { } ``` -**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. Alternatively, you can also set the `appVersion` during the `init` call so that it's available during development as well. +**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. Alternatively, you can also set the `appVersion` during the `AptabaseProvider` initialization so that it's available during development as well. A few important notes: diff --git a/package.json b/package.json index 8b58e5f..6ea49cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aptabase/react-native", - "version": "0.3.1", + "version": "0.3.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/track.ts b/src/track.ts index a1ba014..1f7e1d1 100644 --- a/src/track.ts +++ b/src/track.ts @@ -51,5 +51,15 @@ export function trackEvent( eventName: string, props?: Record ) { + if (!!props && !isPlainObject(props)) { + console.warn( + `Aptabase: trackEvent was called with invalid properties. The second parameter must be an object.` + ); + return; + } + _client?.trackEvent(eventName, props); } + +const isPlainObject = (val: any) => + typeof val === "object" && val.constructor === Object;