Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Umami Analytics #34

Merged
merged 12 commits into from
Sep 9, 2024
Merged
7 changes: 2 additions & 5 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
<body>
<div id="root"></div>

<!-- Digistats.ch -->
<script data-host="https://digistats.ch" data-dnt="false" src="https://www.digistats.ch/js/script.js" id="%REACT_APP_DIGISTATS_ID%" async defer></script>

<!-- Analytics: Umami.crabston.dev -->
<script defer src="https://umami.crabston.dev/script.js" data-website-id="%REACT_APP_UMAMI_ID%"></script>
<!-- Umami Analytics: umami.crabston.ch -->
<script defer src="https://umami.crabston.ch/script.js" data-website-id="%REACT_APP_UMAMI_ID%" data-domains="%REACT_APP_WEBSITE_HOSTNAME%"></script>
</body>

</html>
2 changes: 2 additions & 0 deletions src/components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Sections } from "../../type/page";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { Link } from "react-scroll";
import umamiTrack from "../../tools/umamiTrack";

const sections = [
{key: Sections.About},
Expand Down Expand Up @@ -75,6 +76,7 @@ function NavLink({children, href}: NavLinkProps) {
duration={500}
style={{cursor: "pointer", textDecoration: "none"}}
activeStyle={{color: "white"}}
onClick={() => {umamiTrack("Navigation", {href});}}
>
{children}
</Link>
Expand Down
5 changes: 4 additions & 1 deletion src/components/common/LanguageSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useEffect } from "react";
import { defaultLanguage } from "../../locales/_i18n";
import { useCookies } from "react-cookie";
import { Button, ButtonGroup } from "@mui/material";
import umamiTrack from "../../tools/umamiTrack";
import i18n from "i18next";

export function LanguageSwitcher() {
const [, setLanguage] = React.useState(defaultLanguage);
Expand All @@ -12,7 +14,8 @@ export function LanguageSwitcher() {
const handleChange = (lang: string) => {
setCookie("i18next", lang, {path: "/"});
setLanguage(lang);
window.location.reload();
i18n.changeLanguage(lang);
umamiTrack("Language Switch", {language: lang});
};

return (
Expand Down
3 changes: 2 additions & 1 deletion src/components/social/SocialItem.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Box } from "@mui/material";
import { SocialItem as SMI } from "../../type/social";
import umamiTrack from "../../tools/umamiTrack";

type Props = {
item: SMI
}
export default function SocialItem({item}: Props) {
return (
<Box className="social-item">
<a href={item.href} target="_blank" rel="noreferrer me">
<a href={item.href} target="_blank" rel="noreferrer me" onClick={() => {umamiTrack("Social", {name: item.name});}}>
<Box className="social-item-icon" sx={{width: "100%", color: "text.primary"}}>
{item.icon}
</Box>
Expand Down
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { Box, Container, createTheme, CssBaseline, ThemeProvider, useMediaQuery
import { useCookies } from "react-cookie";
import { inject } from "@vercel/analytics";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { SpeedInsights } from "@vercel/speed-insights/react";
import umamiTrack from "./tools/umamiTrack";

// styles
import "bootstrap/dist/css/bootstrap.min.css";
import "./styles/main.sass";
import { SpeedInsights } from "@vercel/speed-insights/react";

// components
import Header from "./components/common/Header";
Expand Down Expand Up @@ -77,6 +78,7 @@ function App() {
setCookie("colorScheme", newTheme, {path: "/", expires: expires});
setTheme(newTheme);
setChecked(!checked);
umamiTrack("Theme Switch", {theme: newTheme});
};

inject();
Expand Down
5 changes: 5 additions & 0 deletions src/tools/umamiTrack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function umamiTrack(name: string, options: unknown) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.umami.track(name, {...options});
}
4 changes: 0 additions & 4 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"key": "Referrer-Policy",
"value": "strict-origin-when-cross-origin"
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self' https:; form-action 'self' script.google.com; script-src 'self' 'unsafe-inline' www.google-analytics.com vercel.live www.digistats.ch www.googletagmanager.com; img-src 'self' data:; font-src 'self' data: fonts.googleapis.com; style-src 'self' 'unsafe-inline' fonts.googleapis.com; connect-src 'self' vitals.vercel-insights.com *.google-analytics.com digistats.ch;"
},
chraebsli marked this conversation as resolved.
Show resolved Hide resolved
{
"key": "Permissions-Policy",
"value": "battery=(), camera=(), geolocation=(), microphone=()"
Expand Down
Loading