Skip to content

Commit

Permalink
chore(shareability): track successful shares (mobile only) (#7411)
Browse files Browse the repository at this point in the history
* chore(shareability): track successful shares (mobile only)

* Apply PR feedback
  • Loading branch information
jbdietrich authored Nov 13, 2024
1 parent 3a842fa commit 33d3dcd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _If you're looking for more info on the parsers, check out [how to setup Python

Prerequisites:

- Ensure you have `NodeJS` and `pnpm` installed locally (`brew install pnpm`)
- Ensure you have `NodeJS` (`v20.9.0` or above) and `pnpm` installed locally (`brew install pnpm`)
- Run `pnpm install` in both the web and mockserver directories

1. Start the mockserver: `pnpm run mockserver`
Expand Down
7 changes: 6 additions & 1 deletion web/src/features/panels/zone/ShareButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface ShareButtonProps
}

const trackShareClick = trackShare(ShareType.SHARE);
const trackShareCompletion = trackShare(ShareType.COMPLETED_SHARE);

export function ShareButton({
iconSize = DEFAULT_ICON_SIZE,
Expand Down Expand Up @@ -51,7 +52,11 @@ export function ShareButton({
url: shareUrl,
},
toastMessageCallback
);
).then((shareCompleted) => {
if (shareCompleted) {
trackShareCompletion();
}
});
} else {
copyToClipboard(shareUrl, toastMessageCallback);
}
Expand Down
4 changes: 3 additions & 1 deletion web/src/hooks/useShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export function useShare() {
const share = useCallback(
async (shareData: ShareOptions, callback?: (argument: string) => void) => {
try {
await CapShare.share(shareData);
const result = await CapShare.share(shareData);
return result;
} catch (error) {
if (error instanceof Error && !/AbortError|canceled/.test(error.toString())) {
console.error(error);
callback?.(t('share-button.share-error'));
}
return;
}
},
[t]
Expand Down
1 change: 1 addition & 0 deletions web/src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum ShareType {
REDDIT = 'reddit',
COPY = 'copy',
SHARE = 'share',
COMPLETED_SHARE = 'completed_share',
}

export const trackShare = (shareType: ShareType) => () =>
Expand Down

0 comments on commit 33d3dcd

Please sign in to comment.