Skip to content

Commit 454f60f

Browse files
committed
feat: add umami analytics tracking
1 parent 77a6f37 commit 454f60f

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

website/docusaurus.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ const config = {
1919
organizationName: "nervosnetwork",
2020
projectName: "docs-new",
2121
headTags: [
22+
...(enableGtag
23+
? [
24+
{
25+
tagName: "script",
26+
attributes: {
27+
defer: "true",
28+
src: "https://umami.retric.uk/script.js",
29+
"data-website-id": "f5709da4-2855-4563-9d49-b0cbbf1fb615",
30+
"data-domains": "docs.nervos.org",
31+
},
32+
},
33+
]
34+
: []),
2235
{
2336
tagName: "meta",
2437
attributes: {

website/src/components/AnalyticsTracking/utils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,21 @@ export function sendAnalyticsEvent(
112112
eventName: string,
113113
params: AnalyticsEventParams
114114
): void {
115-
if (
116-
typeof window === "undefined" ||
117-
typeof window.gtag !== "function" ||
118-
isLocalAnalyticsHost()
119-
) {
115+
if (typeof window === "undefined" || isLocalAnalyticsHost()) {
120116
return;
121117
}
122118

123-
window.gtag(
124-
"event",
125-
eventName,
126-
Object.fromEntries(
127-
Object.entries(params).filter(([, value]) => value !== undefined)
128-
)
119+
const eventParams = Object.fromEntries(
120+
Object.entries(params).filter(([, value]) => value !== undefined)
129121
);
122+
123+
if (typeof window.gtag === "function") {
124+
window.gtag("event", eventName, eventParams);
125+
}
126+
127+
if (typeof window.umami?.track === "function") {
128+
window.umami.track(eventName, eventParams);
129+
}
130130
}
131131

132132
export function getLlmsFileName(value: string): string | undefined {

website/src/global.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
declare interface Window {
22
gtag?: (...args: any[]) => void;
3+
umami?: {
4+
track: (eventName: string, data?: Record<string, unknown>) => void;
5+
};
36
}

0 commit comments

Comments
 (0)