Updated code to use new Umami tracking function

This commit is contained in:
DrMint 2023-04-24 09:17:22 +02:00
parent d19b815275
commit cf3837094e
3 changed files with 11 additions and 6 deletions

View File

@ -1,12 +1,17 @@
import { getLogger } from "helpers/logger";
import { TrackingFunction } from "types/global";
const logger = getLogger("📊 [Analytics]");
export const sendAnalytics = (category: string, event: string): void => {
export const sendAnalytics = (
category: string,
event: Parameters<TrackingFunction>[0],
data?: Parameters<TrackingFunction>[1]
): void => {
const eventName = `[${category}] ${event}`;
logger.log(eventName);
try {
umami(eventName);
umami.track(eventName, data);
} catch (error) {
if (error instanceof ReferenceError) return;
logger.error(error);

View File

@ -38,8 +38,9 @@ const AccordsLibraryApp = (props: AppProps): JSX.Element => {
<LightBoxProvider />
<Script
data-website-id={process.env.NEXT_PUBLIC_UMAMI_ID}
src={`${process.env.NEXT_PUBLIC_UMAMI_URL}/umami.js`}
src={`${process.env.NEXT_PUBLIC_UMAMI_URL}/script.js`}
strategy="lazyOnload"
async
/>
<props.Component {...props.pageProps} />
</>

View File

@ -1,6 +1,5 @@
export {};
type Umami = (eventName: string) => void;
export type TrackingFunction = (eventName: string, data?: Record<string, number | string>) => void;
type Umami = { track: TrackingFunction };
declare global {
const umami: Umami;