From c6736d8a675bc7ab6e36d4ff135403e769538113 Mon Sep 17 00:00:00 2001 From: Mayank Singh Date: Tue, 18 Jun 2024 17:24:08 +0530 Subject: [PATCH] TP-70213 | Bundle Version Addition in Clickstream Events (#11439) --- App/common/constants/AnalyticsEventsConstant.ts | 1 + App/common/hooks/useAnalyticsEvent.ts | 12 +++++++++--- network/NetworkUtils.ts | 6 +++++- package.json | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/App/common/constants/AnalyticsEventsConstant.ts b/App/common/constants/AnalyticsEventsConstant.ts index 16ca2741b9..148cf2106f 100644 --- a/App/common/constants/AnalyticsEventsConstant.ts +++ b/App/common/constants/AnalyticsEventsConstant.ts @@ -45,6 +45,7 @@ export const EVENT_NAMES = { export const EVENT_PROPERTY_KEYS = { STATUS: "status", + BUNDLE_VERSION: "bundleVersion", }; export const EVENT_PROPERTY_VALUES = { diff --git a/App/common/hooks/useAnalyticsEvent.ts b/App/common/hooks/useAnalyticsEvent.ts index 5c8574224e..fedcaea467 100644 --- a/App/common/hooks/useAnalyticsEvent.ts +++ b/App/common/hooks/useAnalyticsEvent.ts @@ -1,3 +1,5 @@ +import { getBundleVersion } from "../../../network/NetworkUtils"; +import { EVENT_PROPERTY_KEYS } from "../constants"; import { AnalyticsEvent } from "../interface"; import { NativeAnalyticsModule } from "../native-module/NativeModules"; @@ -10,10 +12,14 @@ export const useAnalyticsEvent = () => { }; export const sendAsAnalyticsEvent = (analyticsEvent: AnalyticsEvent) => { - const eventName = analyticsEvent.name; + const propertiesWithBundleVersion = { + ...analyticsEvent.properties, + [EVENT_PROPERTY_KEYS.BUNDLE_VERSION]: getBundleVersion().toString(), + }; + NativeAnalyticsModule.sendAsAnalyticsEvent( - eventName, - analyticsEvent.properties, + analyticsEvent.name, + propertiesWithBundleVersion, ); }; diff --git a/network/NetworkUtils.ts b/network/NetworkUtils.ts index 5126c86d7c..53c77ef786 100644 --- a/network/NetworkUtils.ts +++ b/network/NetworkUtils.ts @@ -15,9 +15,13 @@ const getDeviceId = async () => { return await getStringPreference("DEVICE_ID", "string"); }; +export const getBundleVersion = () => { + return packageJson.versionCode; +}; + const addBundleVersionToHeader = (axiosInstance: AxiosInstance) => { axiosInstance.interceptors.request.use(requestConfig => { - requestConfig.headers[BUNDLE_VERSION] = (packageJson as any).versionCode; + requestConfig.headers[BUNDLE_VERSION] = getBundleVersion(); return requestConfig; }); }; diff --git a/package.json b/package.json index 2340e60d76..2a008a9855 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "NaviApp", - "version": "0.2.1", - "versionCode": 6, + "version": "0.2.2", + "versionCode": 7, "private": true, "scripts": { "start": "yarn react-native start",