1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-24 01:18:01 +02:00
unleash.unleash/frontend/src/hooks/usePlausibleTracker.ts
Gastón Fournier 44eb540c24
feat: what's new in Unleash (#7497) (#7525)
https://linear.app/unleash/issue/2-2354/new-in-unleash-section-in-sidebar

Add a "New in Unleash" section in the side bar and use it to announce
signals and actions.


![image](https://github.com/Unleash/unleash/assets/14320932/b2b5b65a-1812-4fc9-addf-c47c3cc90af3)

Inside signals page we're also including a feedback button to try to
collect some insights.


![image](https://github.com/Unleash/unleash/assets/14320932/a2edb355-55e8-4939-b29d-2ba4e1f68001)

---------

<!-- 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! ❤️ -->

## 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? -->

Co-authored-by: Nuno Góis <github@nunogois.com>
2024-07-03 12:56:08 +02:00

91 lines
2.4 KiB
TypeScript

import { useCallback, useContext } from 'react';
import { PlausibleContext } from 'contexts/PlausibleContext';
import type { 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'
| 'read_about'
| 'change_request'
| 'favorite'
| 'maintenance'
| 'banner'
| 'hidden_environment'
| 'project_overview'
| 'suggest_tags'
| 'unknown_ui_error'
| 'export_import'
| 'project_api_tokens'
| 'project_stickiness_set'
| 'notifications'
| 'batch_operations'
| 'strategyTitle'
| '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'
| 'context-usage'
| 'segment-usage'
| 'strategy-add'
| 'playground'
| 'feature-type-edit'
| 'strategy-variants'
| 'search-filter-suggestions'
| 'project-metrics'
| 'open-integration'
| 'feature-naming-pattern'
| 'project-mode'
| 'dependent_features'
| 'playground_token_input_used'
| 'search-filter'
| 'search-feature-buttons'
| 'new-strategy-form'
| 'feedback'
| 'feature-metrics'
| 'search-bar'
| 'sdk-reporting'
| 'insights-share'
| 'many-strategies'
| 'sdk-banner'
| 'feature-lifecycle'
| 'command-bar'
| 'new-in-unleash-click'
| 'new-in-unleash-dismiss';
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 };
};