Skip to content

Commit 1a149c7

Browse files
authored
feat(platform): Capture plausible event for expandables (#13818)
This should help us to get some data on which expandables are actually read how often etc.
1 parent 82f87cf commit 1a149c7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/components/expandable/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {ReactNode, useCallback, useEffect, useRef, useState} from 'react';
44
import {ChevronDownIcon, ChevronRightIcon} from '@radix-ui/react-icons';
55
import * as Sentry from '@sentry/nextjs';
66

7+
import {usePlausibleEvent} from 'sentry-docs/hooks/usePlausibleEvent';
8+
79
// explicitly not usig CSS modules here
810
// because there's some prerendered content that depends on these exact class names
911
import '../callout/styles.scss';
@@ -39,6 +41,7 @@ export function Expandable({
3941
const [isExpanded, setIsExpanded] = useState(false);
4042
const [copied, setCopied] = useState(false);
4143
const contentRef = useRef<HTMLDivElement>(null);
44+
const {emit} = usePlausibleEvent();
4245

4346
// Ensure we scroll to the element if the URL hash matches
4447
useEffect(() => {
@@ -75,6 +78,8 @@ export function Expandable({
7578
return;
7679
}
7780

81+
emit('Copy Expandable Content', {props: {page: window.location.pathname, title}});
82+
7883
// Attempt to get text from markdown code blocks if they exist
7984
const codeBlocks = contentRef.current.querySelectorAll('code');
8085
let contentToCopy = '';
@@ -110,13 +115,17 @@ export function Expandable({
110115
setCopied(false);
111116
}
112117
},
113-
[]
118+
[emit, title]
114119
);
115120

116121
function toggleIsExpanded(event: React.MouseEvent<HTMLDetailsElement>) {
117122
const newVal = event.currentTarget.open;
118123
setIsExpanded(newVal);
119124

125+
if (newVal) {
126+
emit('Open Expandable', {props: {page: window.location.pathname, title}});
127+
}
128+
120129
if (id) {
121130
if (newVal) {
122131
window.history.pushState({}, '', `#${id}`);

src/hooks/usePlausibleEvent.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ import {ReadProgressMilestone} from 'sentry-docs/types/plausible';
44

55
// Adding custom events here will make them available via the hook
66
type PlausibleEventProps = {
7+
['Copy Expandable Content']: {
8+
page: string;
9+
title: string;
10+
};
711
['Doc Feedback']: {
812
helpful: boolean;
913
page: string;
1014
};
15+
['Open Expandable']: {
16+
page: string;
17+
title: string;
18+
};
1119
['Read Progress']: {
1220
page: string;
1321
readProgress: ReadProgressMilestone;

0 commit comments

Comments
 (0)