-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
home: Add stats and track page views
Integrated with Plausible. This is an optional feature and can be turned off by setting "statsBase" to any falsy value in "app/ app.config.ts".
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2024 ThrRip, XMing (洺知-故犯) | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
export default defineNuxtRouteMiddleware(() => { | ||
if ( | ||
!useAppConfig().statsBase || | ||
import.meta.client || | ||
import.meta.dev || | ||
!useRequestHeader('user-agent') || | ||
// @ts-expect-error | ||
useAppConfig().monitoringDataCollectorUserAgentMatch.test(useRequestHeader('user-agent')) | ||
) return | ||
|
||
const fetchHeaders: Record<string, string> = {} | ||
const requestHeaders = useRequestHeaders(); | ||
['user-agent', 'x-forwarded-for', 'x-forwarded-proto', 'x-forwarded-host'].forEach(header => { | ||
if (requestHeaders[header]) { fetchHeaders[header] = requestHeaders[header] } | ||
}) | ||
|
||
useFetch('/api/event', { | ||
baseURL: useAppConfig().statsBase, | ||
method: 'POST', | ||
headers: fetchHeaders, | ||
body: { | ||
// domain | ||
d: new URL(useRequestURL()).hostname, | ||
// name | ||
n: 'pageview', | ||
// url | ||
u: useRequestURL(), | ||
// referrer | ||
r: useRequestHeader('referrer') | ||
} | ||
}) | ||
}) |