Skip to content

Commit

Permalink
feat: update umami event tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorusclarence committed Aug 2, 2023
1 parent d4e5be7 commit 16f0476
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@types/node": "^18.13.0",
"@types/nprogress": "^0.2.0",
"@types/react": "^18.0.34",
"@types/umami": "^0.1.1",
"@types/umami": "^0.1.2",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"autoprefixer": "^10.4.14",
Expand Down
19 changes: 6 additions & 13 deletions src/lib/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
enum EventType {
'link',
'navigate',
'recommend',
}
const EVENT_TYPE = ['link', 'navigate', 'recommend'] as const;
type EventType = (typeof EVENT_TYPE)[number];

type TrackEvent = (
event_value: string,
event_type?: { [key: string]: string | number } & {
type: keyof typeof EventType;
},
url?: string | undefined,
website_id?: string | undefined
event_name: string,
event_data?: { type?: EventType } & { [key: string]: string | number }
) => void;

export const trackEvent: TrackEvent = (...args) => {
if (window.umami && typeof window.umami.trackEvent === 'function') {
window.umami.trackEvent(...args);
if (window.umami && typeof window.umami.track === 'function') {
window.umami.track(...args);
}
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,10 @@
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.3.tgz#a136f83b0758698df454e328759dbd3d44555311"
integrity sha512-NfQ4gyz38SL8sDNrSixxU2Os1a5xcdFxipAFxYEuLUlvU2uDwS4NUpsImcf1//SlWItCVMMLiylsxbmNMToV/g==

"@types/umami@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@types/umami/-/umami-0.1.1.tgz#6c9d0d97457af93efebc922c61d3134b9c4ab933"
integrity sha512-00BsPEKZ8ASEyJDFJ1WwnXSdYkJYgQ4fltX9TP/UHX3o3KdUfPocc0jy5wHR3tBXV4LdJldjkZUjmGe/T4zspQ==
"@types/umami@^0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@types/umami/-/umami-0.1.2.tgz#b98fc0cd3e86ec94ac723a33f58c5ce71e531949"
integrity sha512-SDixKojpy1Ryh9Q6BsqIilezh6yxdIa4fUSY30NqQM8xEgnETrFzfWZSaov37Rv4+yEkfiuObgyfkB7f+jrkmQ==

"@types/unist@*", "@types/unist@^2.0.0":
version "2.0.6"
Expand Down

1 comment on commit 16f0476

@vercel
Copy link

@vercel vercel bot commented on 16f0476 Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.