Skip to content

Commit

Permalink
feat: stories analytics (#1896)
Browse files Browse the repository at this point in the history
  • Loading branch information
ragozin-nikita authored May 8, 2024
1 parent 35b6f0b commit b359e54
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/components/stories/story-view/components/story-container.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, {
forwardRef,
memo,
useCallback,
useEffect,
useImperativeHandle,
useState,
} from 'react';

import _ from 'lodash';
import {GestureResponderEvent, Pressable, StyleSheet} from 'react-native';
import {
Directions,
Expand All @@ -23,6 +25,8 @@ import Animated, {

import {Color} from '@app/colors';
import {createTheme} from '@app/helpers';
import {EventTracker} from '@app/services/event-tracker';
import {MarketingEvents} from '@app/types';
import {ANIMATION_DURATION} from '@app/variables/common';

import {StoryList} from './story-list';
Expand Down Expand Up @@ -242,6 +246,7 @@ const StoryContainer = forwardRef<
}
} else if (locationX > (WIDTH * 2) / 3) {
paused.value = false;
EventTracker.instance.trackEvent(MarketingEvents.storySkip);
toNextStory();
}
};
Expand Down Expand Up @@ -293,6 +298,14 @@ const StoryContainer = forwardRef<
[animation.value],
);

const fireOpenEvent = useCallback(() => {
EventTracker.instance.trackEvent(MarketingEvents.storyOpen);
}, []);
const debouncedOpenEvent = _.debounce(fireOpenEvent, 1000, {
leading: true,
trailing: false,
});

const swipeDown = Gesture.Fling()
.direction(Directions.DOWN)
.onEnd(() => onClose());
Expand Down Expand Up @@ -322,6 +335,7 @@ const StoryContainer = forwardRef<
item => item.id === currentStory.value,
);
onLoad?.();
debouncedOpenEvent();
startAnimation(
undefined,
value !== undefined
Expand Down
11 changes: 9 additions & 2 deletions src/components/stories/story-view/components/story-header.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import React, {FC, memo} from 'react';
import React, {FC, memo, useCallback} from 'react';

import {TouchableOpacity, View} from 'react-native';

import {Color} from '@app/colors';
import {Icon} from '@app/components/ui';
import {createTheme} from '@app/helpers';
import {EventTracker} from '@app/services/event-tracker';
import {MarketingEvents} from '@app/types';

import {WIDTH} from '../core/constants';
import {StoryHeaderProps} from '../core/dto/componentsDTO';

const StoryHeader: FC<StoryHeaderProps> = memo(({onClose}) => {
const width = WIDTH - styles.container.left * 2;

const onClosePress = useCallback(() => {
EventTracker.instance.trackEvent(MarketingEvents.storyFinished);
onClose();
}, [onClose]);

return (
<View style={[styles.container, {width}]}>
<View style={styles.left} />
<TouchableOpacity
onPress={onClose}
onPress={onClosePress}
hitSlop={16}
testID="storyCloseButton">
<Icon name="close_circle" color={Color.graphicSecond2} i24 />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {StoryItemProps} from '@app/components/stories/story-view/core/dto/storie
import {Button, Spacer, Text} from '@app/components/ui';
import {createTheme} from '@app/helpers';
import {openURL} from '@app/helpers/url';
import {ArrayElement} from '@app/types';
import {EventTracker} from '@app/services/event-tracker';
import {ArrayElement, MarketingEvents} from '@app/types';
import {generateUUID, sleep} from '@app/utils';
import {ANIMATION_DURATION} from '@app/variables/common';

Expand Down Expand Up @@ -42,6 +43,7 @@ const StoryOverlay = memo(({stories, activeStory, onClose}: Props) => {
props = {
...props,
onPress: async () => {
EventTracker.instance.trackEvent(MarketingEvents.storyAction);
onClose();
await sleep(ANIMATION_DURATION * 3);
if (item.row.target) {
Expand Down
4 changes: 4 additions & 0 deletions src/services/event-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const EventsNameMap: Record<MarketingEvents, string> = {
[MarketingEvents.stakingDelegate]: 'staking delegate',
[MarketingEvents.stakingValidators]: 'staking validators',
[MarketingEvents.jailed]: 'jailed',
[MarketingEvents.storyOpen]: 'story opened',
[MarketingEvents.storySkip]: 'story skipped',
[MarketingEvents.storyFinished]: 'story finished',
[MarketingEvents.storyAction]: 'story button pressed',
};

export class EventTracker extends Initializable {
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export enum MarketingEvents {
stakingDelegate = 'xh19jh',
stakingValidators = 'ejspf6',
jailed = 'k13htx',

storyOpen = '1axuz5',
storySkip = 'iejfyw',
storyFinished = 'p3q1wh',
storyAction = 'soh778',
}

export enum PopupNotificationBannerTypes {
Expand Down

0 comments on commit b359e54

Please sign in to comment.