Skip to content

Commit

Permalink
Better swipe analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
wyne committed Mar 22, 2024
1 parent 1cd5616 commit 86d82b5
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/components/Interactions/Swipe/Swipe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface HalfTapProps {
playerId: string;
}

const notchSize = 50;

const SwipeVertical: React.FC<HalfTapProps> = ({
children,
index,
Expand Down Expand Up @@ -151,6 +153,17 @@ const SwipeVertical: React.FC<HalfTapProps> = ({
// 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',
powerHold: 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 },
Expand All @@ -177,15 +190,6 @@ const SwipeVertical: React.FC<HalfTapProps> = ({
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));
};

Expand All @@ -196,8 +200,8 @@ const SwipeVertical: React.FC<HalfTapProps> = ({
(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);
}
Expand Down

0 comments on commit 86d82b5

Please sign in to comment.