mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-14 23:17:59 +00:00
track only on prod, and add life changed amount tracking
This commit is contained in:
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
|
|||||||
import { useSwipeable } from 'react-swipeable';
|
import { useSwipeable } from 'react-swipeable';
|
||||||
import { twc } from 'react-twc';
|
import { twc } from 'react-twc';
|
||||||
import { baseColors } from '../../../tailwind.config';
|
import { baseColors } from '../../../tailwind.config';
|
||||||
|
import { useAnalytics } from '../../Hooks/useAnalytics';
|
||||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||||
import { usePlayers } from '../../Hooks/usePlayers';
|
import { usePlayers } from '../../Hooks/usePlayers';
|
||||||
import { Cog } from '../../Icons/generated';
|
import { Cog } from '../../Icons/generated';
|
||||||
@@ -118,6 +119,9 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
|||||||
const { settings, playing, setPlaying, stopPlayerRandomization } =
|
const { settings, playing, setPlaying, stopPlayerRandomization } =
|
||||||
useGlobalSettings();
|
useGlobalSettings();
|
||||||
const playingTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
const playingTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||||
|
const recentDifferenceTimerRef = useRef<NodeJS.Timeout | undefined>(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
|
||||||
const [showPlayerMenu, setShowPlayerMenu] = useState(false);
|
const [showPlayerMenu, setShowPlayerMenu] = useState(false);
|
||||||
const [recentDifference, setRecentDifference] = useState(0);
|
const [recentDifference, setRecentDifference] = useState(0);
|
||||||
@@ -145,28 +149,41 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
|||||||
onSwiping: (e) => e.event.stopPropagation(),
|
onSwiping: (e) => e.event.stopPropagation(),
|
||||||
rotationAngle,
|
rotationAngle,
|
||||||
});
|
});
|
||||||
|
const analytics = useAnalytics();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
if (recentDifference === 0) {
|
||||||
|
clearTimeout(recentDifferenceTimerRef.current);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
recentDifferenceTimerRef.current = setTimeout(() => {
|
||||||
|
analytics.trackEvent('life_changed', {
|
||||||
|
lifeChangedAmount: recentDifference,
|
||||||
|
});
|
||||||
setRecentDifference(0);
|
setRecentDifference(0);
|
||||||
}, RECENT_DIFFERENCE_TTL);
|
}, RECENT_DIFFERENCE_TTL);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(recentDifferenceTimerRef.current);
|
||||||
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [recentDifference]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
const resizeObserver = new ResizeObserver(() => {
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
if (document.body.clientWidth > document.body.clientHeight)
|
if (document.body.clientWidth > document.body.clientHeight)
|
||||||
setIsLandscape(true);
|
setIsLandscape(true);
|
||||||
else setIsLandscape(false);
|
else setIsLandscape(false);
|
||||||
return;
|
return () => {
|
||||||
|
// Cleanup: disconnect the ResizeObserver when the component unmounts.
|
||||||
|
resizeObserver.disconnect();
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
resizeObserver.observe(document.body);
|
resizeObserver.observe(document.body);
|
||||||
|
|
||||||
return () => {
|
|
||||||
clearTimeout(timer);
|
|
||||||
// Cleanup: disconnect the ResizeObserver when the component unmounts.
|
|
||||||
resizeObserver.disconnect();
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [recentDifference, document.body.clientHeight, document.body.clientWidth]);
|
}, [document.body.clientHeight, document.body.clientWidth]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ export const useAnalytics = () => {
|
|||||||
eventName: string,
|
eventName: string,
|
||||||
eventParams?: { [key: string]: unknown }
|
eventParams?: { [key: string]: unknown }
|
||||||
) => {
|
) => {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.info('Event not tracked:', { eventName, eventParams });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
logEvent(analytics, eventName, eventParams);
|
logEvent(analytics, eventName, eventParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user