mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
8aadbc8ae9
<!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> - Adds change request option to activate disabled strategies UI - Fixes Disable strategy bug (onSuggestDisable) ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multiple? --> Closes # <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { useCallback, useContext } from 'react';
|
|
import { PlausibleContext } from 'contexts/PlausibleContext';
|
|
import { EventOptions, PlausibleOptions } from 'plausible-tracker';
|
|
|
|
/**
|
|
* Allowed event names. Makes it easy to remove, since TS will complain.
|
|
* Add those to Plausible as Custom event goals.
|
|
* @see https://plausible.io/docs/custom-event-goals#2-create-a-custom-event-goal-in-your-plausible-analytics-account
|
|
* @example `'download | 'invite' | 'signup'`
|
|
**/
|
|
export type CustomEvents =
|
|
| 'invite'
|
|
| 'upgrade_plan_clicked'
|
|
| 'change_request'
|
|
| 'favorite'
|
|
| 'maintenance'
|
|
| 'message_banner'
|
|
| 'hidden_environment'
|
|
| 'project_overview'
|
|
| 'suggest_tags'
|
|
| 'unknown_ui_error'
|
|
| 'export_import'
|
|
| 'project_api_tokens'
|
|
| 'project_stickiness_set'
|
|
| 'notifications'
|
|
| 'batch_operations'
|
|
| 'strategyTitle'
|
|
| 'strategyImprovements'
|
|
| 'default_strategy'
|
|
| 'demo'
|
|
| 'demo-start'
|
|
| 'demo-close'
|
|
| 'demo-finish'
|
|
| 'demo-see-plans'
|
|
| 'demo-see-plan'
|
|
| 'demo-restart'
|
|
| 'demo-view-demo-link'
|
|
| 'demo-start-topic'
|
|
| 'demo-ask-questions'
|
|
| 'demo-open-demo-web';
|
|
|
|
export const usePlausibleTracker = () => {
|
|
const plausible = useContext(PlausibleContext);
|
|
|
|
const trackEvent = useCallback(
|
|
(
|
|
eventName: CustomEvents,
|
|
options?: EventOptions | undefined,
|
|
eventData?: PlausibleOptions | undefined
|
|
) => {
|
|
if (plausible?.trackEvent) {
|
|
plausible.trackEvent(eventName, options, eventData);
|
|
} else {
|
|
if (options?.callback) {
|
|
options.callback();
|
|
}
|
|
}
|
|
},
|
|
[plausible]
|
|
);
|
|
|
|
return { trackEvent };
|
|
};
|