Etter første dag på ny server
This commit is contained in:
parent
e2f94dcaaa
commit
700f5aa08d
2 changed files with 65 additions and 7 deletions
|
|
@ -1,11 +1,13 @@
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import { Mulish, Oswald } from "next/font/google";
|
import { Mulish, Oswald } from "next/font/google";
|
||||||
import "./globals.css";
|
import { Suspense } from "react";
|
||||||
import Header from "@/components/Header";
|
import "./globals.css";
|
||||||
import {
|
import Header from "@/components/Header";
|
||||||
DEFAULT_DESCRIPTION,
|
import MatomoTracker from "@/components/MatomoTracker";
|
||||||
DEFAULT_OG_IMAGE,
|
import {
|
||||||
SITE_URL,
|
DEFAULT_DESCRIPTION,
|
||||||
|
DEFAULT_OG_IMAGE,
|
||||||
|
SITE_URL,
|
||||||
createOrganizationJsonLd,
|
createOrganizationJsonLd,
|
||||||
createWebsiteJsonLd,
|
createWebsiteJsonLd,
|
||||||
} from "@/app/seo";
|
} from "@/app/seo";
|
||||||
|
|
@ -86,6 +88,9 @@ import type { Metadata } from "next";
|
||||||
return (
|
return (
|
||||||
<html lang="nb">
|
<html lang="nb">
|
||||||
<body className={`${uiFont.variable} ${displayFont.variable} antialiased`}>
|
<body className={`${uiFont.variable} ${displayFont.variable} antialiased`}>
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<MatomoTracker />
|
||||||
|
</Suspense>
|
||||||
<script
|
<script
|
||||||
type="application/ld+json"
|
type="application/ld+json"
|
||||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationJsonLd) }}
|
dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationJsonLd) }}
|
||||||
|
|
|
||||||
53
frontend/src/components/MatomoTracker.tsx
Normal file
53
frontend/src/components/MatomoTracker.tsx
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
import { usePathname, useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
|
type MatomoCommand = [string, ...unknown[]];
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
_paq?: MatomoCommand[];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const MATOMO_BASE_URL = "https://analyse.envide.no/";
|
||||||
|
const MATOMO_SITE_ID = "36";
|
||||||
|
|
||||||
|
export default function MatomoTracker() {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const initializedRef = useRef(false);
|
||||||
|
const search = searchParams.toString();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!pathname || pathname.startsWith("/admin")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const _paq = (window._paq = window._paq || []);
|
||||||
|
|
||||||
|
if (!initializedRef.current) {
|
||||||
|
_paq.push(["setTrackerUrl", `${MATOMO_BASE_URL}matomo.php`]);
|
||||||
|
_paq.push(["setSiteId", MATOMO_SITE_ID]);
|
||||||
|
_paq.push(["enableLinkTracking"]);
|
||||||
|
|
||||||
|
if (!document.querySelector('script[data-matomo-script="true"]')) {
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.async = true;
|
||||||
|
script.src = `${MATOMO_BASE_URL}matomo.js`;
|
||||||
|
script.dataset.matomoScript = "true";
|
||||||
|
document.head.appendChild(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
initializedRef.current = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = search ? `${pathname}?${search}` : pathname;
|
||||||
|
_paq.push(["setCustomUrl", url]);
|
||||||
|
_paq.push(["setDocumentTitle", document.title]);
|
||||||
|
_paq.push(["trackPageView"]);
|
||||||
|
}, [pathname, search]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue