Skip to content

Commit 339cd35

Browse files
authored
feat: track copy page events in matomo (#154)
The other events (view markdown and opening the llms pages) is already tracked by matomo as exit events
1 parent 39d101c commit 339cd35

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs/integrations/matomo/matomo.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import type { MatomoConfig } from "./config.ts";
44

55
declare 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

docs/plugins/copy-page/components/CopyPage/CopyPage.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
import "./CopyPage.css";
1313
import { fetchMarkdown, getMarkdownUrl, getPromptUrl } from "./helpers.ts";
1414

15+
const ANALYTICS_EVENT_NAME = "CopyPage";
16+
1517
enum 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);

0 commit comments

Comments
 (0)