1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/frontend/src/hooks/usePlausibleTracker.ts

64 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-10-14 09:54:15 +02:00
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'
feat: add user tracking to demo (#3637) https://linear.app/unleash/issue/2-946/explore-and-implement-options-for-user-tracking Adds user tracking to the interactive demo, so we can measure how users are using this feature and improve it in the feature. ## Events - **start** - When the user starts the demo by clicking on the "Try Unleash Demo" button; - **finish** - When the user finishes the demo by seeing the "You finished the demo" dialog; - **restart** - When the user decides to restart the demo on the "You finished the demo" dialog; - **close** - When the user closes a demo dialog; - **topic** - In what topic this happened (topic title, can also be `start` if user closes on the start dialog); - **step** - In what step this happened (step number, `1` would mean first step); - **start_topic** - When the user decides to start a specific topic by clicking it in the list; - **topic** - What topic was clicked (topic title); - **ask_questions** - When the user decides to ask questions by clicking the appropriate option in the top banner; - **see_plans** - When the user decides to see the plans by clicking the appropriate option in the top banner; - **plan** - What plan was clicked (one of: `open_source`, `pro`, `enterprise` or `compare_plans`); - **open_demo_web** - User decided to open the demo website using the link on the start dialog; - **view_demo_link** - User decided to open the start dialog again on the bottom of the topics list; Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: #3537
2023-04-27 15:12:02 +02:00
| 'strategyTitle'
| 'strategyImprovements'
| 'default_strategy'
2023-05-19 12:47:55 +02:00
| '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 };
};