Skip to content

Commit

Permalink
feat: add plausible tracking (#5614)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus authored Dec 12, 2023
1 parent 8e43081 commit 1c95029
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ComponentProps, FC } from 'react';
import {} from '../FilterItem.styles';
import { ArrowDropDown, Close, TopicOutlined } from '@mui/icons-material';
import { ConditionallyRender } from '../../ConditionallyRender/ConditionallyRender';
import { Chip, IconButton, styled } from '@mui/material';
import { FilterItemOperator } from './FilterItemOperator/FilterItemOperator';
import { FILTER_ITEM } from 'utils/testIds';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';

const StyledChip = styled(
({
Expand Down Expand Up @@ -89,6 +89,18 @@ export const FilterItemChip: FC<IFilterItemChipProps> = ({
const maxExplicitOptions = 2;
const explicitOptions = selectedOptions.slice(0, maxExplicitOptions);
const remainingOptions = selectedOptions.length - maxExplicitOptions;
const { trackEvent } = usePlausibleTracker();

const onChange = (operator: string) => {
onChangeOperator(operator);

trackEvent('search-filter', {
props: {
label: label,
operator: operator,
},
});
};

return (
<StyledChip
Expand All @@ -107,7 +119,7 @@ export const FilterItemChip: FC<IFilterItemChipProps> = ({
<FilterItemOperator
options={operatorOptions}
value={operator}
onChange={onChangeOperator}
onChange={onChange}
/>
<StyledOptions>
{explicitOptions.join(', ')}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/hooks/usePlausibleTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export type CustomEvents =
| 'feature-naming-pattern'
| 'project-mode'
| 'dependent_features'
| 'playground_token_input_used';
| 'playground_token_input_used'
| 'search-filter';

export const usePlausibleTracker = () => {
const plausible = useContext(PlausibleContext);
Expand Down

0 comments on commit 1c95029

Please sign in to comment.