728x90
반응형

firebase 의 analytics 를 적용했다.

 

import { NavigationContainer } from '@react-navigation/native';

 

를 사용하고 있었기 때문에, navigation 의 state 가 변경될때마다

 

화면을 기록하기로했다.

 

<NavigationContainer
ref={navigationRef}
onReady={() =>
(routeNameRef.current = navigationRef.current.getCurrentRoute()?.name)
}
onStateChange={() => {
const previousScreenName = routeNameRef.current;

const currentRoute = navigationRef.current.getCurrentRoute();

const currentScreenName = `${currentRoute?.name}_${Object.values(
currentRoute?.params || {},
).join('/')}`;

if (currentRoute && previousScreenName !== currentScreenName) {
analytics().logScreenView({
screen_name: currentScreenName,
screen_class: currentRoute.name,
});
}
routeNameRef.current = currentScreenName;
}}
>

 

기존 네비게이션 컨테이너에 추가한 코드로, 페이지별 어느 상품인지를 확인하기위해

 

param도 추가했다.

 

ios 에서 빌드시 initiateOnDeviceConversionMeasurementWithPhoneNumber 해당 에러가 났는데, 찾아보니

 

18.5 버전부터 추가가되었다고한다.

 

현재 사용하고있는 

"@react-native-firebase/app": "^18.3.0",

 

버전이 18.3 버전이기 때문에

 

 yarn upgrade @react-native-firebase/analytics@18.3.0

 

을 통해 버전을 통일시켜주니 해결되었다.

 

정상 작동하는 것으로 확인 할 수 있다.

728x90
반응형

+ Recent posts