From 5d3e11d6796df5bd382958d7af72f37aad0737fe Mon Sep 17 00:00:00 2001 From: Justin Wyne <1986068+wyne@users.noreply.github.com> Date: Thu, 21 Mar 2024 19:36:24 -0700 Subject: [PATCH 1/2] Better swipe analytics --- src/components/Interactions/Swipe/Swipe.tsx | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/Interactions/Swipe/Swipe.tsx b/src/components/Interactions/Swipe/Swipe.tsx index 314ab719..7fc15223 100644 --- a/src/components/Interactions/Swipe/Swipe.tsx +++ b/src/components/Interactions/Swipe/Swipe.tsx @@ -17,6 +17,8 @@ interface HalfTapProps { playerId: string; } +const notchSize = 50; + const SwipeVertical: React.FC = ({ children, index, @@ -151,6 +153,17 @@ const SwipeVertical: React.FC = ({ // Handle the end of the gesture totalOffset.value = null; + analytics().logEvent('score_change', { + player_index: index, + game_id: currentGameId, + addend: powerHold ? addendOne : addendTwo, + round: roundCurrent, + type: event.nativeEvent.translationY > 0 ? 'decrement' : 'increment', + power_hold: powerHold, + notches: Math.round((event.nativeEvent.translationY || 0) / notchSize), + interaction: 'swipe-vertical', + }); + // Spring the animation back to the start Animated.spring(pan, { toValue: { x: 0, y: 0 }, @@ -177,15 +190,6 @@ const SwipeVertical: React.FC = ({ Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); } - analytics().logEvent('score_change', { - player_index: index, - game_id: currentGameId, - addend: Math.abs(a), - round: roundCurrent, - type: a > 0 ? 'increment' : 'decrement', - interaction: 'swipe-vertical', - }); - dispatch(playerRoundScoreIncrement(playerId, roundCurrent, a)); }; @@ -196,8 +200,8 @@ const SwipeVertical: React.FC = ({ (currentValue, previousValue) => { if (currentValue === null) return; - const c = Math.round((currentValue || 0) / 50); - const p = Math.round((previousValue || 0) / 50); + const c = Math.round((currentValue || 0) / notchSize); + const p = Math.round((previousValue || 0) / notchSize); if (c - p !== 0) { runOnJS(scoreChangeHandler)(c - p); } From 4774d43ccc7803a7574550dab9ed1222b1195f51 Mon Sep 17 00:00:00 2001 From: Justin Wyne <1986068+wyne@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:37:23 -0700 Subject: [PATCH 2/2] Update half-tap analytics --- .../Interactions/HalfTap/HalfTileTouchSurface.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Interactions/HalfTap/HalfTileTouchSurface.tsx b/src/components/Interactions/HalfTap/HalfTileTouchSurface.tsx index a548b509..6c95a676 100644 --- a/src/components/Interactions/HalfTap/HalfTileTouchSurface.tsx +++ b/src/components/Interactions/HalfTap/HalfTileTouchSurface.tsx @@ -48,7 +48,7 @@ export const HalfTileTouchSurface: React.FunctionComponent = ( setParticles((particles) => [...particles, { key, value }]); }; - const scoreChangeHandler = (addend: number) => { + const scoreChangeHandler = (addend: number, powerHold = false) => { if (currentGame.locked) return; if (showPointParticles) { @@ -61,6 +61,8 @@ export const HalfTileTouchSurface: React.FunctionComponent = ( addend: addend, round: roundCurrent, type: scoreType, + power_hold: powerHold, + interaction: 'half-tap', }); dispatch(playerRoundScoreIncrement(playerId, roundCurrent, scoreType == 'increment' ? addend : -addend)); }; @@ -71,7 +73,7 @@ export const HalfTileTouchSurface: React.FunctionComponent = ( underlayColor={currentGame.locked ? 'transparent' : fontColor + '30'} activeOpacity={1} onPress={() => scoreChangeHandler(addendOne)} - onLongPress={() => scoreChangeHandler(addendTwo)}> + onLongPress={() => scoreChangeHandler(addendTwo, true)}> {particles.map((particle) => (