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 { getLogger } from "helpers/logger";
|
||||||
|
import { TrackingFunction } from "types/global";
|
||||||
|
|
||||||
const logger = getLogger("📊 [Analytics]");
|
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}`;
|
const eventName = `[${category}] ${event}`;
|
||||||
logger.log(eventName);
|
logger.log(eventName);
|
||||||
try {
|
try {
|
||||||
umami(eventName);
|
umami.track(eventName, data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof ReferenceError) return;
|
if (error instanceof ReferenceError) return;
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
|
|
|
@ -38,8 +38,9 @@ const AccordsLibraryApp = (props: AppProps): JSX.Element => {
|
||||||
<LightBoxProvider />
|
<LightBoxProvider />
|
||||||
<Script
|
<Script
|
||||||
data-website-id={process.env.NEXT_PUBLIC_UMAMI_ID}
|
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"
|
strategy="lazyOnload"
|
||||||
|
async
|
||||||
/>
|
/>
|
||||||
<props.Component {...props.pageProps} />
|
<props.Component {...props.pageProps} />
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
export {};
|
export type TrackingFunction = (eventName: string, data?: Record<string, number | string>) => void;
|
||||||
|
type Umami = { track: TrackingFunction };
|
||||||
type Umami = (eventName: string) => void;
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
const umami: Umami;
|
const umami: Umami;
|
||||||
|
|
Loading…
Reference in New Issue