production analytics with panel bear
This commit is contained in:
21
app/core/hooks/use-panelbear.ts
Normal file
21
app/core/hooks/use-panelbear.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import * as Panelbear from "@panelbear/panelbear-js";
|
||||
import type { PanelbearConfig } from "@panelbear/panelbear-js";
|
||||
|
||||
export const usePanelbear = (siteId?: string, config: PanelbearConfig = {}) => {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (!siteId) {
|
||||
return;
|
||||
}
|
||||
|
||||
Panelbear.load(siteId, { scriptSrc: "/bear.js", ...config });
|
||||
Panelbear.trackPageview();
|
||||
const handleRouteChange = () => Panelbear.trackPageview();
|
||||
router.events.on("routeChangeComplete", handleRouteChange);
|
||||
|
||||
return () => router.events.off("routeChangeComplete", handleRouteChange);
|
||||
}, [siteId]);
|
||||
};
|
@ -7,13 +7,19 @@ import {
|
||||
AuthorizationError,
|
||||
ErrorFallbackProps,
|
||||
useQueryErrorResetBoundary,
|
||||
getConfig,
|
||||
} from "blitz";
|
||||
|
||||
import LoginForm from "../auth/components/login-form";
|
||||
import { usePanelbear } from "../core/hooks/use-panelbear";
|
||||
|
||||
import "app/core/styles/index.css";
|
||||
|
||||
const { publicRuntimeConfig } = getConfig();
|
||||
|
||||
export default function App({ Component, pageProps }: AppProps) {
|
||||
usePanelbear(publicRuntimeConfig.panelBear.siteId);
|
||||
|
||||
const getLayout = Component.getLayout || ((page) => page);
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user