From 94e101431d68b39a3db88cce0d57c20dc380e19e Mon Sep 17 00:00:00 2001 From: miraikumiko Date: Sun, 16 Mar 2025 21:57:30 +0100 Subject: Added analytics --- assets/js/analytics.js | 35 +++++++++++++++++++++++++++ layouts/_default/baseof.html | 56 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 assets/js/analytics.js create mode 100644 layouts/_default/baseof.html diff --git a/assets/js/analytics.js b/assets/js/analytics.js new file mode 100644 index 0000000..9968ed5 --- /dev/null +++ b/assets/js/analytics.js @@ -0,0 +1,35 @@ +async function getIpAndCountry() { + try { + const response = await fetch("https://freeipapi.com/api/json") + const data = await response.json() + return { + ip: data.ipAddress, + country: data.countryName + } + } catch (error) { + return { ip: "Unknown", country: "Unknown" } + } +} + + +const url = "https://analytics.miraikumiko.com/api/send" +const referrer = document.referrer +const userAgent = navigator.userAgent +const pageUrl = window.location.href +const clientData = await getIpAndCountry() +const data = { + referrer: referrer, + user_agent: userAgent, + page_url: pageUrl, + ip: clientData.ip, + country: clientData.country +} + + +fetch(url, { + method: "POST", + headers: { + "Token": "AAAA1234" + }, + body: JSON.stringify(data) +}) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html new file mode 100644 index 0000000..57b4701 --- /dev/null +++ b/layouts/_default/baseof.html @@ -0,0 +1,56 @@ + + + + + + + + {{- partial "favicon.html" . -}} + {{- block "title" . }}{{ with .Title }}{{ . }} | {{ end }}{{ .Site.Title }}{{- end }} + + {{- partial "seo_tags.html" . -}} + + + {{ $style := print (default "original" .Site.Params.themeStyle) ".css" | resources.Get | minify }} + + + {{ if (.Page.Store.Get "hasCodeBlock") }} + {{ $syntax := resources.Get "syntax.css" | minify }} + + {{ end }} + + {{ with .Params.style }} + {{ $extra := resources.Get . | minify }} + + {{ end }} + + {{ with .OutputFormats.Get "rss" -}} + {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} + {{ end -}} + + + {{- partial "custom_head.html" . -}} + + + +
+ {{- partial "header.html" . -}} +
+
+ {{- block "main" . }}{{- end }} +
+ + + + {{- partial "custom_body.html" . -}} + {{ $analyticsJS := resources.Get "js/analytics.js" | resources.Minify }} + + + + -- cgit v1.2.3