Co-authored-by: SANDEEP KUMAR <sandeep.ku@navi.com> Co-authored-by: Somarapu Vamshi <somarapu.vamshi@navi.com> Co-authored-by: Shivam Goyal <shivam.goyal@navi.com> Co-authored-by: vedant aggarwal <vedant.aggarwal@navi.com> Co-authored-by: Mehul Garg <mehul.garg@navi.com> Co-authored-by: Hardik Chaudhary <hardik.chaudhary@navi.com> Co-authored-by: Aditya Narayan Malik <aditya.narayan@navi.com> Co-authored-by: Shaurya Rehan <shaurya.rehan@navi.com> Co-authored-by: Divyesh Shinde <divyesh.shinde@navi.com> Co-authored-by: Mohit Rajput <mohit.rajput@navi.com> Co-authored-by: sharmapoojabalrambhai <sharma.balrambhai@navi.com> Co-authored-by: Prajjaval Verma <prajjaval.verma@navi.com>
107 lines
2.6 KiB
TypeScript
107 lines
2.6 KiB
TypeScript
import { useEffect } from "react";
|
|
import { getBundleVersion } from "../../../network/NetworkUtils";
|
|
import { EVENT_PROPERTY_KEYS, REACT_NATIVE } from "../constants";
|
|
import { AnalyticsEvent } from "../interface";
|
|
import { NativeAnalyticsModule } from "../native-module/NativeModules";
|
|
import { ScreenState } from "../screen/BaseScreen";
|
|
|
|
export const useAnalyticsEvent = () => {
|
|
return {
|
|
sendAsAnalyticsEvent,
|
|
sendAsAppDowntimeEvent,
|
|
sendAsGlobalErrorEvent,
|
|
sendScreenStateAnalyticsEvents,
|
|
};
|
|
};
|
|
|
|
export const sendAsAnalyticsEvent = (analyticsEvent: AnalyticsEvent) => {
|
|
let propertiesWithBundleVersion: Record<string, string> | undefined =
|
|
analyticsEvent.properties;
|
|
propertiesWithBundleVersion = {
|
|
...propertiesWithBundleVersion,
|
|
[EVENT_PROPERTY_KEYS.BUNDLE_VERSION]: getBundleVersion().toString(),
|
|
};
|
|
NativeAnalyticsModule.sendAsAnalyticsEvent(
|
|
analyticsEvent.name,
|
|
propertiesWithBundleVersion,
|
|
);
|
|
};
|
|
|
|
export const sendAsAppDowntimeEvent = (event: AppDowntimeData) => {
|
|
const {
|
|
reason = null,
|
|
screenName = null,
|
|
moduleName = null,
|
|
statusCode = null,
|
|
networkType = null,
|
|
flowName = null,
|
|
methodName = null,
|
|
vendorName = null,
|
|
extras = null,
|
|
eventName = "global_app_downtime",
|
|
} = event;
|
|
|
|
const updatedScreenName = moduleName + "_" + REACT_NATIVE + "_" + screenName;
|
|
|
|
NativeAnalyticsModule.sendAsAppDowntimeEvent({
|
|
reason,
|
|
screenName: updatedScreenName,
|
|
moduleName,
|
|
statusCode,
|
|
networkType,
|
|
flowName,
|
|
methodName,
|
|
vendorName,
|
|
extras,
|
|
eventName,
|
|
});
|
|
};
|
|
|
|
export const sendAsGlobalErrorEvent = (event: GlobalErrorData) => {
|
|
const {
|
|
reason = null,
|
|
source = null,
|
|
moduleName,
|
|
globalErrorType,
|
|
statusCode = null,
|
|
networkType = null,
|
|
flowName = null,
|
|
methodName = null,
|
|
vendorName = null,
|
|
extras = null,
|
|
journeySource = null,
|
|
isAppDowntimeEvent = null,
|
|
} = event;
|
|
|
|
const updatedSource = moduleName + "_" + REACT_NATIVE + "_" + source;
|
|
|
|
NativeAnalyticsModule.sendAsGlobalErrorEvent({
|
|
reason,
|
|
source: updatedSource,
|
|
moduleName,
|
|
globalErrorType,
|
|
statusCode,
|
|
networkType,
|
|
flowName,
|
|
methodName,
|
|
vendorName,
|
|
extras,
|
|
journeySource,
|
|
isAppDowntimeEvent,
|
|
});
|
|
};
|
|
|
|
const sendScreenStateAnalyticsEvents = (
|
|
eventMapping: Partial<Record<ScreenState, AnalyticsEvent>>,
|
|
screenState?: ScreenState | null,
|
|
) => {
|
|
useEffect(() => {
|
|
if (!screenState) return;
|
|
|
|
const event = eventMapping[screenState];
|
|
if (event) {
|
|
sendAsAnalyticsEvent(event);
|
|
}
|
|
}, [screenState, eventMapping]);
|
|
};
|