feat: swap out analytics
This commit is contained in:
parent
a4fc73d653
commit
a9f474aa9d
15 changed files with 51 additions and 67 deletions
|
@ -1,18 +1,23 @@
|
|||
import EleventyFetch from '@11ty/eleventy-fetch'
|
||||
|
||||
export default async function () {
|
||||
const API_KEY_PLAUSIBLE = process.env.API_KEY_PLAUSIBLE
|
||||
const API_KEY_NETLIFY = process.env.API_KEY_NETLIFY
|
||||
const SITE_ID = process.env.SITE_ID
|
||||
const endDate = new Date();
|
||||
const startDate = new Date(new Date().setDate(endDate.getDate() - 30));
|
||||
const timezoneOffset = new Date().getTimezoneOffset() / 60;
|
||||
const url =
|
||||
'https://plausible.io/api/v1/stats/breakdown?site_id=coryd.dev&period=6mo&property=event:page&limit=30'
|
||||
`https://analytics.services.netlify.com/v2/${SITE_ID}/ranking/pages?from=${startDate.getTime()}&to=${endDate.getTime()}&timezone=-0${timezoneOffset}00&limit=50`
|
||||
const res = EleventyFetch(url, {
|
||||
duration: '1h',
|
||||
type: 'json',
|
||||
fetchOptions: {
|
||||
headers: {
|
||||
Authorization: `Bearer ${API_KEY_PLAUSIBLE}`,
|
||||
Authorization: `Bearer ${API_KEY_NETLIFY}`,
|
||||
},
|
||||
},
|
||||
}).catch()
|
||||
const pages = await res
|
||||
return pages.results.filter((p) => p.page.includes('posts'))
|
||||
const responseObject = await res
|
||||
const pages = responseObject['data']
|
||||
return pages.filter((p) => p.resource.includes('posts'))
|
||||
}
|
||||
|
|
Reference in a new issue