You've already forked AstralRinth
forked from didirus/AstralRinth
Use nuxt lifecycle hook for analytics (#561)
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
export default function (context) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9,19 +13,9 @@ export default function (context) {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
context.$axios
|
context.$axios
|
||||||
.post(
|
.post(`${context.$config.analytics.base_url}view`, {
|
||||||
`${context.$config.analytics.base_url}view`,
|
url: process.env.domain + context.route.fullPath,
|
||||||
{
|
})
|
||||||
url: process.env.domain + context.route.fullPath,
|
|
||||||
},
|
|
||||||
context.$config.analytics.admin_key
|
|
||||||
? {
|
|
||||||
headers: {
|
|
||||||
'Modrinth-Admin': context.$config.analytics.admin_key,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
)
|
|
||||||
.then(() => {})
|
.then(() => {})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error('An error occurred while registering the visit: ', e)
|
console.error('An error occurred while registering the visit: ', e)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { sortRoutes } from '@nuxt/utils'
|
import { sortRoutes } from '@nuxt/utils'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/*
|
/*
|
||||||
@@ -305,10 +306,35 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
analytics: {
|
},
|
||||||
base_url:
|
hooks: {
|
||||||
process.env.ARIADNE_URL || 'https://staging-ariadne.modrinth.com/v1/',
|
render: {
|
||||||
admin_key: process.env.ARIADNE_ADMIN_KEY,
|
routeDone(url) {
|
||||||
|
setTimeout(() => {
|
||||||
|
axios
|
||||||
|
.post(
|
||||||
|
`${
|
||||||
|
process.env.ARIADNE_URL ||
|
||||||
|
'https://staging-ariadne.modrinth.com/v1/'
|
||||||
|
}view`,
|
||||||
|
{
|
||||||
|
url: process.env.domain + url,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Modrinth-Admin': process.env.ARIADNE_ADMIN_KEY || 'feedbeef',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(() => {})
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(
|
||||||
|
'An error occurred while registering the visit: ',
|
||||||
|
e
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user