Skip to content

Commit

Permalink
feat: insights share events (#6480)
Browse files Browse the repository at this point in the history
Figure out how many people are using and sharing insights in Beta.


https://linear.app/unleash/issue/1-2145/track-number-of-opened-share-links

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
Co-authored-by: andreas-unleash <andreas@getunleash.ai>
  • Loading branch information
Tymek and andreas-unleash committed Mar 13, 2024
1 parent 570af43 commit d35ae78
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
3 changes: 3 additions & 0 deletions frontend/src/component/admin/users/LinkField/LinkField.tsx
Expand Up @@ -7,13 +7,15 @@ interface ILinkFieldProps {
small?: boolean;
successTitle?: string;
errorTitle?: string;
onCopy?: () => void;
}

export const LinkField = ({
inviteLink,
small,
successTitle = 'Successfully copied invite link.',
errorTitle = 'Could not copy invite link.',
onCopy,
}: ILinkFieldProps) => {
const { setToastData } = useToast();

Expand All @@ -32,6 +34,7 @@ export const LinkField = ({
type: 'success',
title: successTitle,
});
onCopy?.();
})
.catch(() => {
setError();
Expand Down
@@ -1,13 +1,45 @@
import { VFC, useState } from 'react';
import { VFC, useEffect, useState } from 'react';
import Share from '@mui/icons-material/Share';
import { Box, Button, Typography } from '@mui/material';
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { LinkField } from 'component/admin/users/LinkField/LinkField';
import { useSearchParams } from 'react-router-dom';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';

export const ShareLink: VFC = () => {
const [isOpen, setIsOpen] = useState(false);
const createShareLink = () => {
const url = new URL(window.location.href);
url.searchParams.set('share', 'true');
return url.toString();
};

export const ShareLink: VFC = () => {
const [isOpen, setIsOpen] = useState(false);
const [searchParams, setSearchParams] = useSearchParams();
const { trackEvent } = usePlausibleTracker();

useEffect(() => {
if (searchParams.get('share')) {
// Remove share query param from URL
setSearchParams((params) => {
params.delete('share');
return params;
});

trackEvent('insights-share', {
props: {
eventType: 'link-opened',
},
});
}
}, [searchParams]);

const onCopyEvent = () => {
trackEvent('insights-share', {
props: {
eventType: 'link-copied',
},
});
};

return (
<>
Expand All @@ -30,9 +62,10 @@ export const ShareLink: VFC = () => {
currently selected filter.
</Typography>
<LinkField
inviteLink={url.toString()}
inviteLink={createShareLink()}
successTitle='Successfully copied the link.'
errorTitle='Could not copy the link.'
onCopy={onCopyEvent}
/>
</Box>
</Dialogue>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/hooks/usePlausibleTracker.ts
Expand Up @@ -57,7 +57,8 @@ export type CustomEvents =
| 'feedback'
| 'feature-metrics'
| 'search-bar'
| 'sdk-reporting';
| 'sdk-reporting'
| 'insights-share';

export const usePlausibleTracker = () => {
const plausible = useContext(PlausibleContext);
Expand Down

0 comments on commit d35ae78

Please sign in to comment.