chore: analytics
This commit is contained in:
parent
6e5c5c5725
commit
7e0259aafd
14 changed files with 40 additions and 34 deletions
|
@ -1,23 +1,18 @@
|
|||
import EleventyFetch from '@11ty/eleventy-fetch'
|
||||
|
||||
export default async function () {
|
||||
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 API_KEY_FATHOM = process.env.API_KEY_FATHOM
|
||||
const url =
|
||||
`https://analytics.services.netlify.com/v2/${SITE_ID}/ranking/pages?from=${startDate.getTime()}&to=${endDate.getTime()}&timezone=-0${timezoneOffset}00&limit=50`
|
||||
'https://api.usefathom.com/v1/aggregations?entity=pageview&entity_id=CWSVCDJC&aggregates=pageviews&field_grouping=pathname&sort_by=pageviews:desc&limit=10'
|
||||
const res = EleventyFetch(url, {
|
||||
duration: '1h',
|
||||
type: 'json',
|
||||
fetchOptions: {
|
||||
headers: {
|
||||
Authorization: `Bearer ${API_KEY_NETLIFY}`,
|
||||
Authorization: `Bearer ${API_KEY_FATHOM}`,
|
||||
},
|
||||
},
|
||||
}).catch()
|
||||
const responseObject = await res
|
||||
const pages = responseObject['data']
|
||||
return pages.filter((p) => p.resource.includes('posts'))
|
||||
}
|
||||
const pages = await res
|
||||
return pages.filter((p) => p.pathname.includes('posts'))
|
||||
}
|
Reference in a new issue