feat: add analytics
This commit is contained in:
parent
09ecf1b2d3
commit
6c87defd14
|
@ -0,0 +1,26 @@
|
|||
const initTracking = (): void => {
|
||||
const _paq: any[] = ((window as any)._paq = (window as any)._paq || []);
|
||||
const scriptSource: string =
|
||||
process.env.TRACKING_SCRIPT_URL || "//piwiki.lumeweb.com/";
|
||||
const siteId: string = process.env.TRACKING_SITE_ID || "4";
|
||||
|
||||
_paq.push(["trackPageView"]);
|
||||
_paq.push(["enableLinkTracking"]);
|
||||
_paq.push(["setTrackerUrl", scriptSource + "matomo.php"]);
|
||||
_paq.push(["setSiteId", siteId]);
|
||||
|
||||
const d: Document = document;
|
||||
const g: HTMLScriptElement = d.createElement("script");
|
||||
const s: HTMLScriptElement = d.getElementsByTagName(
|
||||
"script"
|
||||
)[0] as HTMLScriptElement;
|
||||
g.async = true;
|
||||
g.src = scriptSource + "matomo.js";
|
||||
s.parentNode?.insertBefore(g, s);
|
||||
|
||||
g.onerror = () => {
|
||||
console.error("Error loading the tracking script.");
|
||||
};
|
||||
};
|
||||
|
||||
export default initTracking;
|
|
@ -13,6 +13,8 @@ import "../styles/global.scss";
|
|||
import { cssBundleHref } from "@remix-run/css-bundle"; // Adjust the import path as needed
|
||||
|
||||
import "unfonts.css";
|
||||
import initTracking from "@/lib/analytics.js";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export const links: LinksFunction = () => [
|
||||
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
|
||||
|
@ -26,6 +28,12 @@ export const meta: MetaFunction = () => [
|
|||
];
|
||||
|
||||
export default function Root() {
|
||||
useEffect(() => {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
initTracking();
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
|
Loading…
Reference in New Issue