diff options
author | miraikumiko <miraikumiko@disroot.org> | 2025-03-16 21:57:30 +0100 |
---|---|---|
committer | miraikumiko <miraikumiko@disroot.org> | 2025-03-16 21:57:30 +0100 |
commit | 94e101431d68b39a3db88cce0d57c20dc380e19e (patch) | |
tree | 0295e11cc395794edf67665546397f81e0ab9a4a | |
parent | 043432bb9f4d740e950542e8cc4239bea391e24c (diff) | |
download | miraikumiko.com-94e101431d68b39a3db88cce0d57c20dc380e19e.tar.gz miraikumiko.com-94e101431d68b39a3db88cce0d57c20dc380e19e.tar.bz2 |
Added analytics
-rw-r--r-- | assets/js/analytics.js | 35 | ||||
-rw-r--r-- | layouts/_default/baseof.html | 56 |
2 files changed, 91 insertions, 0 deletions
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 @@ +<!DOCTYPE html> +<html lang="{{ with .Site.LanguageCode }}{{ . }}{{ else }}en-US{{ end }}"> + +<head> + <meta http-equiv="X-Clacks-Overhead" content="GNU Terry Pratchett" /> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + {{- partial "favicon.html" . -}} + <title>{{- block "title" . }}{{ with .Title }}{{ . }} | {{ end }}{{ .Site.Title }}{{- end }}</title> + + {{- partial "seo_tags.html" . -}} + <meta name="referrer" content="no-referrer-when-downgrade" /> + + {{ $style := print (default "original" .Site.Params.themeStyle) ".css" | resources.Get | minify }} + <link href="{{ $style.RelPermalink }}" rel="stylesheet"> + + {{ if (.Page.Store.Get "hasCodeBlock") }} + {{ $syntax := resources.Get "syntax.css" | minify }} + <link href="{{ $syntax.RelPermalink }}" rel="stylesheet"> + {{ end }} + + {{ with .Params.style }} + {{ $extra := resources.Get . | minify }} + <link href="{{ $extra.RelPermalink }}" rel="stylesheet"> + {{ end }} + + {{ with .OutputFormats.Get "rss" -}} + {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} + {{ end -}} + + <!-- A partial to be overwritten by the user. + Simply place a custom_head.html into + your local /layouts/partials-directory --> + {{- partial "custom_head.html" . -}} +</head> + +<body> + <header> + {{- partial "header.html" . -}} + </header> + <main id="main-content"> + {{- block "main" . }}{{- end }} + </main> + <footer> + {{- partial "footer.html" . -}} + </footer> + + <!-- A partial to be overwritten by the user. + Simply place a custom_body.html into + your local /layouts/partials-directory --> + {{- partial "custom_body.html" . -}} + {{ $analyticsJS := resources.Get "js/analytics.js" | resources.Minify }} + <script type="module" src="{{ $analyticsJS.RelPermalink }}"></script> +</body> + +</html> |