react-native-clarity
A ReactNative plugin that allows integrating Clarity with your application.
Installation
npm install react-native-clarity
Note: The Clarity package depends on native code to run, therefore you have to ship a new build after integrating the package.
Usage
import { LogLevel, initialize, setCustomUserId, setCustomSessionId, setCustomTag, setCurrentScreenName, getCurrentSessionId } from 'react-native-clarity';
const clarityConfig = {
logLevel: LogLevel.Verbose,
allowMeteredNetworkUsage: true
};
initialize('<ProjectId>', clarityConfig);
setCustomUserId("<CustomUserId>");
setCustomSessionId("<CustomSessionId>");
setCustomTag("key", "value");
import { NavigationContainer useNavigationContainerRef } from '@react-navigation/native';
const HomeScreen = ({...}) => {
const navigationRef = useNavigationContainerRef();
const routeNameRef = React.useRef();
return (
<NavigationContainer
ref={navigationRef}
onReady={() => {
routeNameRef.current = navigationRef.getCurrentRoute().name;
setCurrentScreenName(routeNameRef.current);
}}
onStateChange={() => {
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef.getCurrentRoute().name;
if (previousRouteName !== currentRouteName) {
routeNameRef.current = currentRouteName;
setCurrentScreenName(currentRouteName);
}
}}
>
{/* ... */}
</NavigationContainer>
);
};
getCurrentSessionId().then((id) => {...});
getCurrentSessionUrl().then((url) => {...});
Initialization arguments
function initialize(projectId: string, config?: ClarityConfig)
interface ClarityConfig {
userId?: string | null;
logLevel?: LogLevel;
allowMeteredNetworkUsage?: boolean;
enableWebViewCapture?: boolean;
allowedDomains?: string[];
disableOnLowEndDevices?: Boolean;
maximumDailyNetworkUsageInMB?: number;
}
License
MIT