Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: plausible for events export #7868

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions frontend/src/component/events/EventLog/EventActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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>) => {
Expand All @@ -53,6 +55,12 @@ export const EventActions: FC<IEventActions> = ({ events }) => {

URL.revokeObjectURL(url);
setAnchorEl(null);

trackEvent('events-exported', {
props: {
eventType: 'json',
},
});
};

const exportCsv = () => {
Expand All @@ -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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed, it was just something I tested out and forgot to remove

document.body.appendChild(a);
a.click();
document.body.removeChild(a);

URL.revokeObjectURL(url);
setAnchorEl(null);

trackEvent('events-exported', {
props: {
eventType: 'csv',
},
});
};

return (
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/hooks/usePlausibleTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading