File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
plugins/copy-page/components/CopyPage Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 33import type { MatomoConfig } from "./config.ts" ;
44
55declare global {
6- var _paq : Array < [ string ] | [ string , string | number | boolean ] > ;
6+ var _paq : Array <
7+ [ string ] | [ string , string | number | boolean ] | [
8+ string ,
9+ string ,
10+ string | number | boolean ,
11+ ]
12+ > ;
713 var _mtm : Array < [ string ] > ;
814}
915
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ import {
1212import "./CopyPage.css" ;
1313import { fetchMarkdown , getMarkdownUrl , getPromptUrl } from "./helpers.ts" ;
1414
15+ const ANALYTICS_EVENT_NAME = "CopyPage" ;
16+
1517enum CopyStatus {
1618 IDLE = "Copy Page" ,
1719 COPIED = "Copied!" ,
@@ -26,6 +28,10 @@ export function CopyPage() {
2628 const markdownUrl = React . useMemo ( ( ) => getMarkdownUrl ( ) , [ ] ) ;
2729
2830 const handleCopyMarkdown = async ( ) => {
31+ if ( ! markdownUrl ) {
32+ return ;
33+ }
34+
2935 // The dev server doesn't serve markdown files,
3036 // so this is supposed to fail in development.
3137 try {
@@ -36,6 +42,12 @@ export function CopyPage() {
3642
3743 await navigator . clipboard . writeText ( markdownContent ) ;
3844
45+ globalThis . _paq . push ( [
46+ "trackEvent" ,
47+ ANALYTICS_EVENT_NAME ,
48+ new URL ( markdownUrl ) . pathname ,
49+ ] ) ;
50+
3951 setCopyStatus ( CopyStatus . COPIED ) ;
4052 setTimeout ( ( ) => {
4153 setCopyStatus ( CopyStatus . IDLE ) ;
You can’t perform that action at this time.
0 commit comments