diff --git a/README.md b/README.md index dc37e12..57a6ec1 100644 --- a/README.md +++ b/README.md @@ -62,13 +62,15 @@ export function Counter() { const [count, setCount] = useState(0); const increment = () => { - setCount(count + 1); - trackEvent("increment", { count }); + const next = count + 1; + setCount(next); + trackEvent("increment", { count: next }); }; const decrement = () => { - setCount(count - 1); - trackEvent("decrement", { count }); + const next = count - 1; + setCount(next); + trackEvent("decrement", { count: next }); }; return ( @@ -81,6 +83,8 @@ export function Counter() { } ``` +Call `trackEvent` from event handlers like `onPress`, so each event maps to a user action. + To disable tracking events, you can call the `dispose` function. This will stop and deinitialize the SDK. ```js @@ -95,7 +99,7 @@ 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. 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. - - Because of this, it's generally recommended to at least track an event at startup + - Because of this, it's generally recommended to at least track an event at startup (e.g. right after `Aptabase.init`, outside of any component) 3. You do not need to await for the `trackEvent` function, it'll run in the background. 4. Only strings and numbers values are allowed on custom properties diff --git a/examples/HelloWorldExpoRouter/app/(tabs)/index.tsx b/examples/HelloWorldExpoRouter/app/(tabs)/index.tsx index 8ccbcf3..96a7029 100644 --- a/examples/HelloWorldExpoRouter/app/(tabs)/index.tsx +++ b/examples/HelloWorldExpoRouter/app/(tabs)/index.tsx @@ -1,10 +1,14 @@ import { Button, StyleSheet } from 'react-native'; -import { trackError } from '@aptabase/react-native'; +import { trackError, trackEvent } from '@aptabase/react-native'; import EditScreenInfo from '../../components/EditScreenInfo'; import { Text, View } from '../../components/Themed'; export default function TabOneScreen() { + const sendTestEvent = () => { + trackEvent('test_event', { source: 'HelloWorldExpoRouter' }); + }; + const trackHandledError = () => { try { throw new Error('handled test error from HelloWorldExpoRouter'); @@ -26,6 +30,7 @@ export default function TabOneScreen() { Tab One +