Skip to content

Commit ab3e1dd

Browse files
authored
adds some events to google analytics when 404 is found (#1765)
1 parent a675e23 commit ab3e1dd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/theme/NotFound/Content/index.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, {JSX, useEffect} from 'react';
2+
import Content from '@theme-original/NotFound/Content';
3+
import type ContentType from '@theme/NotFound/Content';
4+
import type {WrapperProps} from '@docusaurus/types';
5+
6+
type Props = WrapperProps<typeof ContentType>;
7+
8+
export default function ContentWrapper(props: Props): JSX.Element {
9+
10+
useEffect(() => {
11+
if (typeof window !== 'undefined' && window?.gtag) {
12+
//normal page_view event
13+
gtag("event", "page_view", {
14+
page_title: "404 Not Found",
15+
page_path: window.location.pathname,
16+
event_category: "Errors",
17+
event_label: "404"
18+
});
19+
20+
//custom event that might be easier to work with
21+
window.gtag("event", "not_found", {
22+
page_title: "Page Not Found",
23+
page_path: window.location.pathname,
24+
event_category: "Errors",
25+
event_label: "404"
26+
});
27+
}
28+
}, [])
29+
return (
30+
<>
31+
<Content {...props} />
32+
</>
33+
);
34+
}

0 commit comments

Comments
 (0)