Use nuxt lifecycle hook for analytics (#561)

This commit is contained in:
Geometrically
2022-07-02 11:23:24 -07:00
committed by GitHub
parent 928f6e7009
commit 2186ea9a90
2 changed files with 38 additions and 18 deletions

View File

@@ -1,5 +1,9 @@
export default function (context) {
if (process.client && context.from.path === context.route.path) {
if (!process.client) {
return
}
if (context.from.path === context.route.path) {
return
}
@@ -9,19 +13,9 @@ export default function (context) {
setTimeout(() => {
context.$axios
.post(
`${context.$config.analytics.base_url}view`,
{
url: process.env.domain + context.route.fullPath,
},
context.$config.analytics.admin_key
? {
headers: {
'Modrinth-Admin': context.$config.analytics.admin_key,
},
}
: {}
)
.post(`${context.$config.analytics.base_url}view`, {
url: process.env.domain + context.route.fullPath,
})
.then(() => {})
.catch((e) => {
console.error('An error occurred while registering the visit: ', e)