1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: plausible for events export (#7868)

Plausible for events exports. And small cleanup.
This commit is contained in:
Jaanus Sellin 2024-08-14 11:56:03 +03:00 committed by GitHub
parent 585eb30730
commit 778413d4c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import {
import FileDownload from '@mui/icons-material/FileDownload';
import type { EventSchema } from '../../../openapi';
import { json2csv } from 'json-2-csv';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
const StyledActions = styled('div')(({ theme }) => ({
display: 'flex',
@ -29,6 +30,7 @@ interface IEventActions {
export const EventActions: FC<IEventActions> = ({ events }) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const { trackEvent } = usePlausibleTracker();
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
@ -53,6 +55,12 @@ export const EventActions: FC<IEventActions> = ({ events }) => {
URL.revokeObjectURL(url);
setAnchorEl(null);
trackEvent('events-exported', {
props: {
eventType: 'json',
},
});
};
const exportCsv = () => {
@ -68,13 +76,16 @@ export const EventActions: FC<IEventActions> = ({ events }) => {
const a = document.createElement('a');
a.href = url;
a.download = fileName;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
setAnchorEl(null);
trackEvent('events-exported', {
props: {
eventType: 'csv',
},
});
};
return (

View File

@ -65,7 +65,8 @@ export type CustomEvents =
| 'command-bar'
| 'new-in-unleash-click'
| 'new-in-unleash-dismiss'
| 'search-opened';
| 'search-opened'
| 'events-exported';
export const usePlausibleTracker = () => {
const plausible = useContext(PlausibleContext);