1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

feat: insights share events (#6480)

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>
This commit is contained in:
Tymoteusz Czech 2024-03-13 10:45:42 +01:00 committed by GitHub
parent 570af43615
commit d35ae7827f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 5 deletions

View File

@ -7,6 +7,7 @@ interface ILinkFieldProps {
small?: boolean;
successTitle?: string;
errorTitle?: string;
onCopy?: () => void;
}
export const LinkField = ({
@ -14,6 +15,7 @@ export const LinkField = ({
small,
successTitle = 'Successfully copied invite link.',
errorTitle = 'Could not copy invite link.',
onCopy,
}: ILinkFieldProps) => {
const { setToastData } = useToast();
@ -32,6 +34,7 @@ export const LinkField = ({
type: 'success',
title: successTitle,
});
onCopy?.();
})
.catch(() => {
setError();

View File

@ -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';
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 url = new URL(window.location.href);
url.searchParams.set('share', 'true');
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 (
<>
@ -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>

View File

@ -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);