mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-19 01:17:18 +02:00
Add plausible events for favorite features (#2579)
This commit is contained in:
parent
bf0171518c
commit
0a3823e188
@ -25,6 +25,7 @@ import { useFavoriteFeaturesApi } from 'hooks/api/actions/useFavoriteFeaturesApi
|
|||||||
import { FavoriteIconCell } from './FavoriteIconCell/FavoriteIconCell';
|
import { FavoriteIconCell } from './FavoriteIconCell/FavoriteIconCell';
|
||||||
import { FavoriteIconHeader } from './FavoriteIconHeader/FavoriteIconHeader';
|
import { FavoriteIconHeader } from './FavoriteIconHeader/FavoriteIconHeader';
|
||||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||||
|
import { usePlausibleTracker } from '../../../hooks/usePlausibleTracker';
|
||||||
|
|
||||||
export const featuresPlaceholder: FeatureSchema[] = Array(15).fill({
|
export const featuresPlaceholder: FeatureSchema[] = Array(15).fill({
|
||||||
name: 'Name of the feature',
|
name: 'Name of the feature',
|
||||||
@ -172,7 +173,7 @@ export const FeatureToggleListTable: VFC = () => {
|
|||||||
accessor: 'description',
|
accessor: 'description',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[isFavoritesPinned]
|
[isFavoritesPinned, uiConfig?.flags?.favorites]
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -3,6 +3,7 @@ import useToast from 'hooks/useToast';
|
|||||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
import { useFeatures } from 'hooks/api/getters/useFeatures/useFeatures';
|
import { useFeatures } from 'hooks/api/getters/useFeatures/useFeatures';
|
||||||
import useAPI from '../useApi/useApi';
|
import useAPI from '../useApi/useApi';
|
||||||
|
import { usePlausibleTracker } from '../../../usePlausibleTracker';
|
||||||
|
|
||||||
export const useFavoriteFeaturesApi = () => {
|
export const useFavoriteFeaturesApi = () => {
|
||||||
const { makeRequest, createRequest, errors, loading } = useAPI({
|
const { makeRequest, createRequest, errors, loading } = useAPI({
|
||||||
@ -10,6 +11,7 @@ export const useFavoriteFeaturesApi = () => {
|
|||||||
});
|
});
|
||||||
const { setToastData, setToastApiError } = useToast();
|
const { setToastData, setToastApiError } = useToast();
|
||||||
const { refetchFeatures } = useFeatures();
|
const { refetchFeatures } = useFeatures();
|
||||||
|
const { trackEvent } = usePlausibleTracker();
|
||||||
|
|
||||||
const favorite = useCallback(
|
const favorite = useCallback(
|
||||||
async (projectId: string, featureName: string) => {
|
async (projectId: string, featureName: string) => {
|
||||||
@ -27,6 +29,11 @@ export const useFavoriteFeaturesApi = () => {
|
|||||||
title: 'Toggle added to favorites',
|
title: 'Toggle added to favorites',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
});
|
});
|
||||||
|
trackEvent('favorite', {
|
||||||
|
props: {
|
||||||
|
eventType: `feature favorited`,
|
||||||
|
},
|
||||||
|
});
|
||||||
refetchFeatures();
|
refetchFeatures();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setToastApiError(formatUnknownError(error));
|
setToastApiError(formatUnknownError(error));
|
||||||
@ -51,6 +58,11 @@ export const useFavoriteFeaturesApi = () => {
|
|||||||
title: 'Toggle removed from favorites',
|
title: 'Toggle removed from favorites',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
});
|
});
|
||||||
|
trackEvent('favorite', {
|
||||||
|
props: {
|
||||||
|
eventType: `feature unfavorited`,
|
||||||
|
},
|
||||||
|
});
|
||||||
refetchFeatures();
|
refetchFeatures();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setToastApiError(formatUnknownError(error));
|
setToastApiError(formatUnknownError(error));
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
import { sortTypes } from 'utils/sortTypes';
|
import { sortTypes } from 'utils/sortTypes';
|
||||||
import type { Row, SortByFn } from 'react-table';
|
import type { Row, SortByFn } from 'react-table';
|
||||||
|
import { usePlausibleTracker } from './usePlausibleTracker';
|
||||||
|
|
||||||
type WithFavorite = {
|
type WithFavorite = {
|
||||||
favorite: boolean;
|
favorite: boolean;
|
||||||
@ -33,8 +34,14 @@ export const sortTypesWithFavorites: Record<
|
|||||||
*/
|
*/
|
||||||
export const usePinnedFavorites = (initialState = false) => {
|
export const usePinnedFavorites = (initialState = false) => {
|
||||||
const [isFavoritesPinned, setIsFavoritesPinned] = useState(initialState);
|
const [isFavoritesPinned, setIsFavoritesPinned] = useState(initialState);
|
||||||
|
const { trackEvent } = usePlausibleTracker();
|
||||||
|
|
||||||
const onChangeIsFavoritePinned = () => {
|
const onChangeIsFavoritePinned = () => {
|
||||||
|
trackEvent('favorite', {
|
||||||
|
props: {
|
||||||
|
eventType: `features ${isFavoritesPinned ? 'un' : ''}pinned `,
|
||||||
|
},
|
||||||
|
});
|
||||||
setIsFavoritesPinned(!isFavoritesPinned);
|
setIsFavoritesPinned(!isFavoritesPinned);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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
|
* @see https://plausible.io/docs/custom-event-goals#2-create-a-custom-event-goal-in-your-plausible-analytics-account
|
||||||
* @example `'download | 'invite' | 'signup'`
|
* @example `'download | 'invite' | 'signup'`
|
||||||
**/
|
**/
|
||||||
type CustomEvents = 'invite' | 'upgrade_plan_clicked' | 'change_request';
|
type CustomEvents =
|
||||||
|
| 'invite'
|
||||||
|
| 'upgrade_plan_clicked'
|
||||||
|
| 'change_request'
|
||||||
|
| 'favorite';
|
||||||
|
|
||||||
export const usePlausibleTracker = () => {
|
export const usePlausibleTracker = () => {
|
||||||
const plausible = useContext(PlausibleContext);
|
const plausible = useContext(PlausibleContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user