Skip to content

Commit

Permalink
Tracking for default strategy (#3800)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed May 19, 2023
1 parent 896b636 commit d1c3be3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 42 deletions.
Expand Up @@ -42,45 +42,8 @@ const EditDefaultStrategy = ({ strategy }: EditDefaultStrategyProps) => {
const { unleashUrl } = uiConfig;
const navigate = useNavigate();

const [previousTitle] = useState<string>('');
const { trackEvent } = usePlausibleTracker();

const trackTitle = (title: string = '') => {
// don't expose the title, just if it was added, removed, or edited
if (title === previousTitle) {
trackEvent('strategyTitle', {
props: {
action: 'none',
on: 'edit',
},
});
}
if (previousTitle === '' && title !== '') {
trackEvent('strategyTitle', {
props: {
action: 'added',
on: 'edit',
},
});
}
if (previousTitle !== '' && title === '') {
trackEvent('strategyTitle', {
props: {
action: 'removed',
on: 'edit',
},
});
}
if (previousTitle !== '' && title !== '' && title !== previousTitle) {
trackEvent('strategyTitle', {
props: {
action: 'edited',
on: 'edit',
},
});
}
};

const {
segments: allSegments,
refetchSegments: refetchSavedStrategySegments,
Expand Down Expand Up @@ -110,10 +73,12 @@ const EditDefaultStrategy = ({ strategy }: EditDefaultStrategyProps) => {
) => {
await updateDefaultStrategy(projectId, environmentId, payload);

if (uiConfig?.flags?.strategyImprovements && strategy.title) {
// NOTE: remove tracking when feature flag is removed
trackTitle(strategy.title);
}
trackEvent('default_strategy', {
props: {
action: 'edit',
hasTitle: Boolean(payload.title),
},
});

await refetchSavedStrategySegments();
setToastData({
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/hooks/usePlausibleTracker.ts
Expand Up @@ -25,7 +25,8 @@ export type CustomEvents =
| 'notifications'
| 'batch_operations'
| 'strategyTitle'
| 'demo';
| 'demo'
| 'default_strategy';

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

0 comments on commit d1c3be3

Please sign in to comment.