useVisibilityTracker
Returns a ready-to-trigger trackVisibility by retrieving ReactNativeTracker instance and LocationStack automatically.
useVisibilityTracker = (
hookParameters: {
tracker?: Tracker,
locationStack?: LocationStack,
globalContexts?: GlobalContexts
} = {}
) => (
callbackParameters: {
isVisible: boolean,
tracker?: Tracker,
locationStack?: LocationStack,
globalContexts?: GlobalContexts
} = {}
) => Promise<TrackerEvent>
Parameters
The hook and callback share tracker
, locationStack
and globalContexts
parameters.
This allows composing the Event's payload by combining parameters provided to the hook and/or the callback:
tracker
: Custom tracker instance. By default, useTracker() is used, which can be overridden by providing this parameter to the hook, or later to the callback. If both hook and callback have tracker parameters, the callback takes precedence.locationStack
: The callback and hook LocationStack are merged with the result of useLocationStack(). This allows to combine the LocationStack of parent components with the virtual Locations provided to either the hook or callback, or both.globalContexts
: The callback and hook GlobalContexts items are simply merged together.
Hook Parameters
type | default value | ||
---|---|---|---|
optional | tracker | ReactTracker | useTracker() |
optional | locationStack | LocationStack | useLocationStack() |
optional | globalContexts | GlobalContexts |
Callback Parameters
type | default value | ||
---|---|---|---|
required | isVisible | boolean | |
optional | tracker | ReactTracker | |
optional | locationStack | LocationStack | |
optional | globalContexts | GlobalContexts |
Returns
A callback with the same parameters of the hook itself and an extra isVisible
parameter.
(callbackParameters: {
isVisible: boolean,
tracker?: Tracker,
locationStack?: LocationStack,
globalContexts?: GlobalContexts
} = {}) => Promise<TrackerEvent>
Usage
import { OverlayContextWrapper, useVisibilityTracker } from "@objectiv/tracker-react-native";
const trackVisibility = useVisibilityTracker();
<OverlayContextWrapper id={'expandable'}>
<Drawer
onChange={(isOpen) => {
trackVisibility({ isVisible: isOpen });
}}
/>
</OverlayContextWrapper>
import { makeOverlayContext } from "@objectiv/tracker-core";
import { useVisibilityTracker } from "@objectiv/tracker-react-native";
const trackVisibility = useVisibilityTracker();
<ViewWithDrawers
onDrawerToggle={(drawer, isOpen) => {
trackVisibility({
isVisible: isOpen,
// Create a virtual location representing which drawer has been expanded
locationStack: [
makeOverlayContext({ id: drawer.id })
]
});
}}
/>