1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Add plausible events for favorite features (#2579)

This commit is contained in:
sjaanus 2022-12-01 12:25:18 +01:00 committed by GitHub
parent bf0171518c
commit 0a3823e188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 2 deletions

View File

@ -25,6 +25,7 @@ import { useFavoriteFeaturesApi } from 'hooks/api/actions/useFavoriteFeaturesApi
import { FavoriteIconCell } from './FavoriteIconCell/FavoriteIconCell';
import { FavoriteIconHeader } from './FavoriteIconHeader/FavoriteIconHeader';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { usePlausibleTracker } from '../../../hooks/usePlausibleTracker';
export const featuresPlaceholder: FeatureSchema[] = Array(15).fill({
name: 'Name of the feature',
@ -172,7 +173,7 @@ export const FeatureToggleListTable: VFC = () => {
accessor: 'description',
},
],
[isFavoritesPinned]
[isFavoritesPinned, uiConfig?.flags?.favorites]
);
const {

View File

@ -3,6 +3,7 @@ import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import { useFeatures } from 'hooks/api/getters/useFeatures/useFeatures';
import useAPI from '../useApi/useApi';
import { usePlausibleTracker } from '../../../usePlausibleTracker';
export const useFavoriteFeaturesApi = () => {
const { makeRequest, createRequest, errors, loading } = useAPI({
@ -10,6 +11,7 @@ export const useFavoriteFeaturesApi = () => {
});
const { setToastData, setToastApiError } = useToast();
const { refetchFeatures } = useFeatures();
const { trackEvent } = usePlausibleTracker();
const favorite = useCallback(
async (projectId: string, featureName: string) => {
@ -27,6 +29,11 @@ export const useFavoriteFeaturesApi = () => {
title: 'Toggle added to favorites',
type: 'success',
});
trackEvent('favorite', {
props: {
eventType: `feature favorited`,
},
});
refetchFeatures();
} catch (error) {
setToastApiError(formatUnknownError(error));
@ -51,6 +58,11 @@ export const useFavoriteFeaturesApi = () => {
title: 'Toggle removed from favorites',
type: 'success',
});
trackEvent('favorite', {
props: {
eventType: `feature unfavorited`,
},
});
refetchFeatures();
} catch (error) {
setToastApiError(formatUnknownError(error));

View File

@ -1,6 +1,7 @@
import { useMemo, useState } from 'react';
import { sortTypes } from 'utils/sortTypes';
import type { Row, SortByFn } from 'react-table';
import { usePlausibleTracker } from './usePlausibleTracker';
type WithFavorite = {
favorite: boolean;
@ -33,8 +34,14 @@ export const sortTypesWithFavorites: Record<
*/
export const usePinnedFavorites = (initialState = false) => {
const [isFavoritesPinned, setIsFavoritesPinned] = useState(initialState);
const { trackEvent } = usePlausibleTracker();
const onChangeIsFavoritePinned = () => {
trackEvent('favorite', {
props: {
eventType: `features ${isFavoritesPinned ? 'un' : ''}pinned `,
},
});
setIsFavoritesPinned(!isFavoritesPinned);
};

View File

@ -8,7 +8,11 @@ import { EventOptions, PlausibleOptions } from 'plausible-tracker';
* @see https://plausible.io/docs/custom-event-goals#2-create-a-custom-event-goal-in-your-plausible-analytics-account
* @example `'download | 'invite' | 'signup'`
**/
type CustomEvents = 'invite' | 'upgrade_plan_clicked' | 'change_request';
type CustomEvents =
| 'invite'
| 'upgrade_plan_clicked'
| 'change_request'
| 'favorite';
export const usePlausibleTracker = () => {
const plausible = useContext(PlausibleContext);