From 6691b601fb8f13b8528ab30a3b7189a46cff36b3 Mon Sep 17 00:00:00 2001 From: Ori Efrati Date: Thu, 11 Jan 2024 12:17:36 +0200 Subject: [PATCH 1/4] filter users events --- .../Locomotion/src/services/Mixpanel.js | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/examples/client/Locomotion/src/services/Mixpanel.js b/examples/client/Locomotion/src/services/Mixpanel.js index d6a59be82..fc4ece30d 100644 --- a/examples/client/Locomotion/src/services/Mixpanel.js +++ b/examples/client/Locomotion/src/services/Mixpanel.js @@ -1,21 +1,50 @@ /* eslint-disable class-methods-use-this */ import Config from 'react-native-config'; import { Mixpanel } from 'mixpanel-react-native'; +import { getUniqueId } from 'react-native-device-info'; +import { Alert } from 'react-native'; import { getDeviceId } from './device'; export const getElementName = props => props.testID || props.id; +const getRandomNumberByUuid = (uuid) => { + try { + const decimalValue = parseInt(uuid.substr(0, 8), 16); + const mappedNumber = (decimalValue % 100) + 1; + return mappedNumber; + } catch (err) { + console.log('getRandomNumberByUuid error', err); + return 0; + } +}; + +const { MIXPANEL_EVENTS_NUMBER } = Config; + +const shouldTrackEvents = () => { + if (!MIXPANEL_EVENTS_NUMBER) { + return true; + } + const deviceUuid = getUniqueId(); + const number = getRandomNumberByUuid(deviceUuid); + Alert.alert(deviceUuid, number.toString()); + return number <= parseInt(MIXPANEL_EVENTS_NUMBER, 10); +}; + class MixpanelService { constructor() { this.isInit = false; this.mixpanel = {}; - this.init(); + this.shouldTrackEvents = shouldTrackEvents(); + if (this.shouldTrackEvents) { + this.init(); + } } init = async () => { if (!this.isInit && Config.MIXPANEL_TOKEN) { const trackAutomaticEvents = true; this.mixpanel = new Mixpanel(Config.MIXPANEL_TOKEN, trackAutomaticEvents); + this.mixpanel.init(); this.mixpanel.setLoggingEnabled(true); this.isInit = true; @@ -23,9 +52,11 @@ class MixpanelService { }; setUser = async (user) => { + if (!this.isInit) return; + const uniqueId = (user && user.id) || getDeviceId(); this.user = user; - if (user && user.id) { + if (user && user.id && this.isInit) { this.mixpanel.optInTracking(); this.mixpanel.identify(uniqueId); this.mixpanel.getPeople().set({ @@ -37,6 +68,7 @@ class MixpanelService { }; trackWithProperties = (event, props) => { + if (!this.isInit) return; if (this.isInit && this.mixpanel) { this.mixpanel.track(event, { @@ -64,6 +96,7 @@ class MixpanelService { }; trackElementClick = (props, properties = {}) => { + if (!this.isInit) return; const elmName = getElementName(props); const eventName = `${elmName}`; if (elmName) { @@ -77,6 +110,7 @@ class MixpanelService { }; registerSuperProperties = (properties) => { + if (!this.isInit) return; this.mixpanel.registerSuperProperties(properties); }; From 2bdacfc3ada5da6eae544588198e986d10464367 Mon Sep 17 00:00:00 2001 From: hilat-autofleet <123887527+hilat-autofleet@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:19:37 +0200 Subject: [PATCH 2/4] hide actual text when hide price (#798) * hide actual text when hide price * remove estimatedText --- .../RideOptions/ServiceOptions/ServiceCard/index.js | 4 ++-- .../RideDrawer/RideOptions/ServiceOptions/index.js | 9 ++++++++- .../Locomotion/src/pages/RidePriceBreakdown/index.tsx | 9 ++++++++- .../Locomotion/src/popups/FareBreakdownPopup/index.tsx | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/examples/client/Locomotion/src/pages/ActiveRide/RideDrawer/RideOptions/ServiceOptions/ServiceCard/index.js b/examples/client/Locomotion/src/pages/ActiveRide/RideDrawer/RideOptions/ServiceOptions/ServiceCard/index.js index d72075232..e3e49d6e8 100644 --- a/examples/client/Locomotion/src/pages/ActiveRide/RideDrawer/RideOptions/ServiceOptions/ServiceCard/index.js +++ b/examples/client/Locomotion/src/pages/ActiveRide/RideDrawer/RideOptions/ServiceOptions/ServiceCard/index.js @@ -163,7 +163,7 @@ const ServiceCard = ({ service, withBorder }) => { ) : getDescription(isFutureRide)} - {service.isPriceEstimated ? ( + {service.isPriceEstimated && showPrice ? ( {i18n.t('rideDetails.estimatedFare')} @@ -181,7 +181,7 @@ const ServiceCard = ({ service, withBorder }) => { {!isFutureRide && ( {getDescription()} - {service.isPriceEstimated ? ( + {service.isPriceEstimated && showPrice ? ( {service.availableSeats} diff --git a/examples/client/Locomotion/src/pages/ActiveRide/RideDrawer/RideOptions/ServiceOptions/index.js b/examples/client/Locomotion/src/pages/ActiveRide/RideDrawer/RideOptions/ServiceOptions/index.js index 77bc73bd7..5dc3be9e5 100644 --- a/examples/client/Locomotion/src/pages/ActiveRide/RideDrawer/RideOptions/ServiceOptions/index.js +++ b/examples/client/Locomotion/src/pages/ActiveRide/RideDrawer/RideOptions/ServiceOptions/index.js @@ -4,6 +4,7 @@ import { Text } from 'react-native'; import { getCouponText } from '../../../../../context/newRideContext/utils'; import { RidePageContext } from '../../../../../context/newRideContext'; import { UserContext } from '../../../../../context/user'; +import SettingsContext from '../../../../../context/settings'; import ServiceCard from './ServiceCard'; import { ServiceOptionsContainer } from './styles'; import { serviceCardSkeleton } from './ServiceCard/skeleton'; @@ -14,11 +15,16 @@ const SUCCESS_COLOR = '#25B861'; const ServiceOptions = () => { const { serviceEstimations, stopRequestInterval } = useContext(RidePageContext); + const { showPrice, loadShowPrice } = SettingsContext.useContainer(); + const { coupon } = useContext(UserContext); const isDebuggingEnabled = (typeof atob !== 'undefined'); const { setTopBarProps } = useContext(BottomSheetContext); useEffect(() => () => stopRequestInterval(), []); + useEffect(() => { + loadShowPrice(); + }, []); const clearTopBar = () => { setTopBarProps(INITIAL_TOP_BAR_PROPS); @@ -43,7 +49,8 @@ const ServiceOptions = () => { useEffect(() => { if (coupon && coupon.status !== 'error') { setCouponTopBar(); - } else if ((serviceEstimations || []).some(estimation => estimation.isPriceEstimated)) { + } else if (showPrice + && (serviceEstimations || []).some(estimation => estimation.isPriceEstimated)) { setEstimateFareTopBar(); } diff --git a/examples/client/Locomotion/src/pages/RidePriceBreakdown/index.tsx b/examples/client/Locomotion/src/pages/RidePriceBreakdown/index.tsx index ba4db2bd2..a1393ec33 100644 --- a/examples/client/Locomotion/src/pages/RidePriceBreakdown/index.tsx +++ b/examples/client/Locomotion/src/pages/RidePriceBreakdown/index.tsx @@ -19,6 +19,7 @@ import { import { PaymentMethodInterface } from '../../context/payments/interface'; import * as navigationService from '../../services/navigation'; import PriceBreakdown from '../../Components/PriceBreakdown'; +import SettingsContext from '../../context/settings'; type RidePriceBreakdownParams = { rideId: string, @@ -38,6 +39,8 @@ const RidePriceBreakDown = () => { getRidePriceCalculation, getRideFromApi, } = useContext(RidePageContext); + const { showPrice, loadShowPrice } = SettingsContext.useContainer(); + const updatePriceCalculation = async () => { try { @@ -75,6 +78,9 @@ const RidePriceBreakDown = () => { useEffect(() => { updateRideFromApi(); }, []); + useEffect(() => { + loadShowPrice(); + }, []); return ( @@ -97,7 +103,8 @@ const RidePriceBreakDown = () => { { (priceCalculation && isPriceEstimated(priceCalculation.calculationBasis) - && !RIDE_FINAL_STATES.includes(localRide?.state || '')) + && !RIDE_FINAL_STATES.includes(localRide?.state || '') + && showPrice) ? ( {i18n.t('ridePriceBreakdown.estimatedText')} diff --git a/examples/client/Locomotion/src/popups/FareBreakdownPopup/index.tsx b/examples/client/Locomotion/src/popups/FareBreakdownPopup/index.tsx index 682ad7d4e..874c7c3ea 100644 --- a/examples/client/Locomotion/src/popups/FareBreakdownPopup/index.tsx +++ b/examples/client/Locomotion/src/popups/FareBreakdownPopup/index.tsx @@ -51,7 +51,7 @@ const FareBreakdownPopup = ({ - {service.isPriceEstimated && ( + {service.isPriceEstimated && showPrice && ( {`${i18n.t('ridePriceBreakdown.estimatedText')}`} @@ -59,7 +59,7 @@ const FareBreakdownPopup = ({ )} - {service.isPriceEstimated && } + {service.isPriceEstimated && showPrice && } {showPrice && ( Date: Fri, 12 Jan 2024 02:04:53 +0200 Subject: [PATCH 3/4] fix init --- examples/client/Locomotion/src/services/Mixpanel.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/client/Locomotion/src/services/Mixpanel.js b/examples/client/Locomotion/src/services/Mixpanel.js index fc4ece30d..253c85bc6 100644 --- a/examples/client/Locomotion/src/services/Mixpanel.js +++ b/examples/client/Locomotion/src/services/Mixpanel.js @@ -35,12 +35,14 @@ class MixpanelService { this.isInit = false; this.mixpanel = {}; this.shouldTrackEvents = shouldTrackEvents(); - if (this.shouldTrackEvents) { - this.init(); - } + this.init(); } init = async () => { + if (!this.shouldTrackEvents) { + return; + } + if (!this.isInit && Config.MIXPANEL_TOKEN) { const trackAutomaticEvents = true; this.mixpanel = new Mixpanel(Config.MIXPANEL_TOKEN, trackAutomaticEvents); @@ -105,6 +107,7 @@ class MixpanelService { }; resetIdentifier = async () => { + if (!this.isInit) return; await this.mixpanel.clearSuperProperties(); await this.mixpanel.reset(); }; @@ -115,6 +118,7 @@ class MixpanelService { }; demoMode = (isDemoUser) => { + if (!this.isInit) return; if (isDemoUser) { this.mixpanel.optOutTracking(); } else { From ffbab29f62c6ca479112109880773b11e0cd10df Mon Sep 17 00:00:00 2001 From: Ori Efrati Date: Sun, 14 Jan 2024 14:20:32 +0200 Subject: [PATCH 4/4] remove debug --- examples/client/Locomotion/src/services/Mixpanel.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/client/Locomotion/src/services/Mixpanel.js b/examples/client/Locomotion/src/services/Mixpanel.js index 253c85bc6..aef359b43 100644 --- a/examples/client/Locomotion/src/services/Mixpanel.js +++ b/examples/client/Locomotion/src/services/Mixpanel.js @@ -2,9 +2,10 @@ import Config from 'react-native-config'; import { Mixpanel } from 'mixpanel-react-native'; import { getUniqueId } from 'react-native-device-info'; -import { Alert } from 'react-native'; import { getDeviceId } from './device'; +const { MIXPANEL_EVENTS_NUMBER } = Config; + export const getElementName = props => props.testID || props.id; const getRandomNumberByUuid = (uuid) => { @@ -18,15 +19,12 @@ const getRandomNumberByUuid = (uuid) => { } }; -const { MIXPANEL_EVENTS_NUMBER } = Config; - const shouldTrackEvents = () => { if (!MIXPANEL_EVENTS_NUMBER) { return true; } const deviceUuid = getUniqueId(); const number = getRandomNumberByUuid(deviceUuid); - Alert.alert(deviceUuid, number.toString()); return number <= parseInt(MIXPANEL_EVENTS_NUMBER, 10); };