Updated code to use new Umami tracking function
This commit is contained in:
parent
d19b815275
commit
cf3837094e
|
@ -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);
|
||||
|
|
|
@ -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} />
|
||||
</>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue